-
Notifications
You must be signed in to change notification settings - Fork 0
/
obfs.ts
67 lines (55 loc) · 1.58 KB
/
obfs.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import Connection from '../helper/connection'
/**
* The ObfsMethod class is an abstract class that all other,
* extended classes should implement its methods and properties
* every obfuscation method should extend this class
*/
abstract class ObfsMethod {
public static readonly CLIENT = 'CLIENT'
public static readonly SERVER = 'SERVER'
/**
* The type of obfuscation
*/
public type: typeof ObfsMethod.CLIENT | typeof ObfsMethod.SERVER
/**
* Connection object
*/
protected connection: Connection
/**
* The Obfuscation method name
*/
public abstract name: string
constructor(
connection: Connection,
type: typeof ObfsMethod.CLIENT | typeof ObfsMethod.SERVER
) {
this.connection = connection
this.type = type
}
/**
* Checks if the message format is Appropriate with
* this obfuscation method
* @param message - The incoming message
*/
public abstract check(message: Buffer): boolean
/**
* Begins the handshake process for the encryption
* @param callback - Emitted after the handshake process
*/
public abstract handshake(callback: () => void): void
/**
* DeObfuscates the obfuscated message
* @param message - The obfuscated message
*/
public abstract deObfuscate(message: Buffer): Buffer
/**
* Obfuscates the non-obfuscated message
* @param message - The non-obfuscated message
*/
public abstract obfuscate(message: Buffer): Buffer
}
export type ObfsBuilder = (
connection: Connection,
type?: typeof ObfsMethod.CLIENT | typeof ObfsMethod.SERVER
) => ObfsMethod
export default ObfsMethod