Skip to content

Commit c15d81f

Browse files
committed
Add enumeration of encryption method.
1 parent 47c0216 commit c15d81f

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

ShadowsocksX-NG/Utils.swift

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,27 @@ extension Data {
2525
}
2626

2727
enum ProxyType:String {case pac="auto", global="global", manual="manual"};
28+
enum EncryptionMethod:String {
29+
case AES_128_GCM = "aes-128-gcm"
30+
case AES_192_GCM = "aes-192-gcm"
31+
case AES_256_GCM = "aes-256-gcm"
32+
case AES_128_CFB = "aes-128-cfb"
33+
case AES_192_CFB = "aes-192-cfb"
34+
case AES_256_CFB = "aes-256-cfb"
35+
case AES_128_CTR = "aes-128-ctr"
36+
case AES_192_CTR = "aes-192-ctr"
37+
case AES_256_CTR = "aes-256-ctr"
38+
case CAMELLIA_128_CFB = "camellia-128-cfb"
39+
case CAMELLIA_192_CFB = "camellia-192-cfb"
40+
case CAMELLIA_256_CFB = "camellia-256-cfb"
41+
case BF_CFB = "bf-cfb"
42+
case CHACHA20_IETF_POLY1305 = "chacha20-ietf-poly1305"
43+
case XCHACHA20_IETF_POLY1305 = "xchacha20-ietf-poly1305"
44+
case SALSA20 = "salsa20"
45+
case CHACHA20 = "chacha20"
46+
case CHACHA20_IETF = "chacha20-ietf"
47+
case RC4_MD5 = "rc4-md5"
48+
}
2849

2950
struct Globals {
3051
static var proxyType = ProxyType.pac
@@ -79,31 +100,11 @@ class Validator {
79100
static func method(_ str:String) -> Bool {
80101
// Copy from PreferencesWindowController.swift
81102
// Better to make valid methods enumeration type.
82-
return [
83-
"aes-128-gcm",
84-
"aes-192-gcm",
85-
"aes-256-gcm",
86-
"aes-128-cfb",
87-
"aes-192-cfb",
88-
"aes-256-cfb",
89-
"aes-128-ctr",
90-
"aes-192-ctr",
91-
"aes-256-ctr",
92-
"camellia-128-cfb",
93-
"camellia-192-cfb",
94-
"camellia-256-cfb",
95-
"bf-cfb",
96-
"chacha20-ietf-poly1305",
97-
"xchacha20-ietf-poly1305",
98-
"salsa20",
99-
"chacha20",
100-
"chacha20-ietf",
101-
"rc4-md5",
102-
].contains(str);
103+
return EncryptionMethod.init(rawValue: str) != nil
103104
}
104105

105106
static func password(_ str:String) -> Bool {
106-
return str != "";
107+
return !str.isEmpty;
107108
}
108109

109110
static func remark(_ str:String) -> Bool {

0 commit comments

Comments
 (0)