From 116d8cf970c20caf2912d0fe1bd410a5a43dc373 Mon Sep 17 00:00:00 2001 From: Fin Date: Tue, 12 Mar 2024 15:08:29 +0800 Subject: [PATCH] =?UTF-8?q?GCM=20=E8=BF=98=E6=B2=A1=E5=87=86=E5=A4=87?= =?UTF-8?q?=E5=A5=BD=E7=A4=BA=E4=BE=8B=E4=BB=A3=E7=A0=81=EF=BC=8C=E6=9A=82?= =?UTF-8?q?=E6=97=B6=E7=A6=81=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Controller/CryptoSettingViewModel.swift | 2 +- Model/Algorithm.swift | 11 ++++------- 2 files changed, 5 insertions(+), 8 deletions(-) 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