From c15d81f78fa9494c37092d69d9942e7d381371e0 Mon Sep 17 00:00:00 2001 From: yangziy Date: Thu, 27 Sep 2018 18:40:17 +0800 Subject: [PATCH] Add enumeration of encryption method. --- ShadowsocksX-NG/Utils.swift | 45 +++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/ShadowsocksX-NG/Utils.swift b/ShadowsocksX-NG/Utils.swift index 09713db9..47883d25 100644 --- a/ShadowsocksX-NG/Utils.swift +++ b/ShadowsocksX-NG/Utils.swift @@ -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 @@ -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 {