Skip to content

Commit

Permalink
Add enumeration of encryption method.
Browse files Browse the repository at this point in the history
  • Loading branch information
yangziy committed Sep 27, 2018
1 parent 47c0216 commit c15d81f
Showing 1 changed file with 23 additions and 22 deletions.
45 changes: 23 additions & 22 deletions ShadowsocksX-NG/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,27 @@ extension Data {
}

enum ProxyType:String {case pac="auto", global="global", manual="manual"};
enum EncryptionMethod:String {
case AES_128_GCM = "aes-128-gcm"
case AES_192_GCM = "aes-192-gcm"
case AES_256_GCM = "aes-256-gcm"
case AES_128_CFB = "aes-128-cfb"
case AES_192_CFB = "aes-192-cfb"
case AES_256_CFB = "aes-256-cfb"
case AES_128_CTR = "aes-128-ctr"
case AES_192_CTR = "aes-192-ctr"
case AES_256_CTR = "aes-256-ctr"
case CAMELLIA_128_CFB = "camellia-128-cfb"
case CAMELLIA_192_CFB = "camellia-192-cfb"
case CAMELLIA_256_CFB = "camellia-256-cfb"
case BF_CFB = "bf-cfb"
case CHACHA20_IETF_POLY1305 = "chacha20-ietf-poly1305"
case XCHACHA20_IETF_POLY1305 = "xchacha20-ietf-poly1305"
case SALSA20 = "salsa20"
case CHACHA20 = "chacha20"
case CHACHA20_IETF = "chacha20-ietf"
case RC4_MD5 = "rc4-md5"
}

struct Globals {
static var proxyType = ProxyType.pac
Expand Down Expand Up @@ -79,31 +100,11 @@ class Validator {
static func method(_ str:String) -> Bool {
// Copy from PreferencesWindowController.swift
// Better to make valid methods enumeration type.
return [
"aes-128-gcm",
"aes-192-gcm",
"aes-256-gcm",
"aes-128-cfb",
"aes-192-cfb",
"aes-256-cfb",
"aes-128-ctr",
"aes-192-ctr",
"aes-256-ctr",
"camellia-128-cfb",
"camellia-192-cfb",
"camellia-256-cfb",
"bf-cfb",
"chacha20-ietf-poly1305",
"xchacha20-ietf-poly1305",
"salsa20",
"chacha20",
"chacha20-ietf",
"rc4-md5",
].contains(str);
return EncryptionMethod.init(rawValue: str) != nil
}

static func password(_ str:String) -> Bool {
return str != "";
return !str.isEmpty;
}

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

0 comments on commit c15d81f

Please sign in to comment.