diff --git a/Controller/CryptoSettingViewModel.swift b/Controller/CryptoSettingViewModel.swift index 0297d0c..d0197e7 100644 --- a/Controller/CryptoSettingViewModel.swift +++ b/Controller/CryptoSettingViewModel.swift @@ -135,7 +135,7 @@ class CryptoSettingViewModel: ViewModel, ViewModelType { return Output( initial: Driver.just(( algorithmList: [Algorithm.aes128, Algorithm.aes192, Algorithm.aes256], - modeList: ["CBC", "ECB", "GCM"], + modeList: ["CBC", "ECB", /* "GCM" */], // GCM 还没准备好示例代码,暂时禁用 paddingList: ["pkcs7"], initialFields: dependencies.settingFieldRelay.value )), diff --git a/Model/Algorithm.swift b/Model/Algorithm.swift index 585ef31..1a3cde0 100644 --- a/Model/Algorithm.swift +++ b/Model/Algorithm.swift @@ -67,13 +67,10 @@ struct AESCryptoModel { var iv = "" if ["CBC", "GCM"].contains(cryptoFields.mode) { - var expectIVLength = 0 - if cryptoFields.mode == "CBC" { - expectIVLength = 16 - } - else if cryptoFields.mode == "GCM" { - expectIVLength = 12 - } + let expectIVLength = [ + "CBC": 16, + "GCM": 12 + ][cryptoFields.mode] ?? 0 if let ivField = cryptoFields.iv, ivField.count == expectIVLength { iv = ivField