mirror of
https://github.com/Finb/Bark.git
synced 2025-12-08 21:36:01 +00:00
add Algorithm type
This commit is contained in:
parent
e91e9f5e9e
commit
6d4acccf28
@ -19,6 +19,7 @@
|
|||||||
06172FDA27F6DAEF002333A4 /* ServerListTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06172FD927F6DAEF002333A4 /* ServerListTableViewCell.swift */; };
|
06172FDA27F6DAEF002333A4 /* ServerListTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06172FD927F6DAEF002333A4 /* ServerListTableViewCell.swift */; };
|
||||||
06172FDC27F6DB06002333A4 /* ServerListTableViewCellViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06172FDB27F6DB06002333A4 /* ServerListTableViewCellViewModel.swift */; };
|
06172FDC27F6DB06002333A4 /* ServerListTableViewCellViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06172FDB27F6DB06002333A4 /* ServerListTableViewCellViewModel.swift */; };
|
||||||
061894C529962EB900E001C2 /* GradientButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 061894C429962EB900E001C2 /* GradientButton.swift */; };
|
061894C529962EB900E001C2 /* GradientButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 061894C429962EB900E001C2 /* GradientButton.swift */; };
|
||||||
|
061894C729A75BEA00E001C2 /* Algorithm.swift in Sources */ = {isa = PBXBuildFile; fileRef = 061894C629A75BEA00E001C2 /* Algorithm.swift */; };
|
||||||
0627DABB298B6EA2002F3F69 /* DropBoxView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0627DABA298B6EA2002F3F69 /* DropBoxView.swift */; };
|
0627DABB298B6EA2002F3F69 /* DropBoxView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0627DABA298B6EA2002F3F69 /* DropBoxView.swift */; };
|
||||||
0627DABD2990D615002F3F69 /* BorderTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0627DABC2990D615002F3F69 /* BorderTextField.swift */; };
|
0627DABD2990D615002F3F69 /* BorderTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0627DABC2990D615002F3F69 /* BorderTextField.swift */; };
|
||||||
062B98C3251B2762004562E7 /* BKButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 062B98C2251B2762004562E7 /* BKButton.swift */; };
|
062B98C3251B2762004562E7 /* BKButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 062B98C2251B2762004562E7 /* BKButton.swift */; };
|
||||||
@ -192,6 +193,7 @@
|
|||||||
06172FD927F6DAEF002333A4 /* ServerListTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServerListTableViewCell.swift; sourceTree = "<group>"; };
|
06172FD927F6DAEF002333A4 /* ServerListTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServerListTableViewCell.swift; sourceTree = "<group>"; };
|
||||||
06172FDB27F6DB06002333A4 /* ServerListTableViewCellViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServerListTableViewCellViewModel.swift; sourceTree = "<group>"; };
|
06172FDB27F6DB06002333A4 /* ServerListTableViewCellViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServerListTableViewCellViewModel.swift; sourceTree = "<group>"; };
|
||||||
061894C429962EB900E001C2 /* GradientButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GradientButton.swift; sourceTree = "<group>"; };
|
061894C429962EB900E001C2 /* GradientButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GradientButton.swift; sourceTree = "<group>"; };
|
||||||
|
061894C629A75BEA00E001C2 /* Algorithm.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Algorithm.swift; sourceTree = "<group>"; };
|
||||||
0627DABA298B6EA2002F3F69 /* DropBoxView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DropBoxView.swift; sourceTree = "<group>"; };
|
0627DABA298B6EA2002F3F69 /* DropBoxView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DropBoxView.swift; sourceTree = "<group>"; };
|
||||||
0627DABC2990D615002F3F69 /* BorderTextField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BorderTextField.swift; sourceTree = "<group>"; };
|
0627DABC2990D615002F3F69 /* BorderTextField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BorderTextField.swift; sourceTree = "<group>"; };
|
||||||
062B98C2251B2762004562E7 /* BKButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BKButton.swift; sourceTree = "<group>"; };
|
062B98C2251B2762004562E7 /* BKButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BKButton.swift; sourceTree = "<group>"; };
|
||||||
@ -430,6 +432,7 @@
|
|||||||
06B1158E247BB1FB006D91FB /* Message.swift */,
|
06B1158E247BB1FB006D91FB /* Message.swift */,
|
||||||
064CABA5256BE9510018155C /* PreviewModel.swift */,
|
064CABA5256BE9510018155C /* PreviewModel.swift */,
|
||||||
06BD4DA92901352E003364DB /* Object+Dictionary.swift */,
|
06BD4DA92901352E003364DB /* Object+Dictionary.swift */,
|
||||||
|
061894C629A75BEA00E001C2 /* Algorithm.swift */,
|
||||||
);
|
);
|
||||||
path = Model;
|
path = Model;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
@ -989,6 +992,7 @@
|
|||||||
06C5953124811392006B98F3 /* ArchiveSettingCell.swift in Sources */,
|
06C5953124811392006B98F3 /* ArchiveSettingCell.swift in Sources */,
|
||||||
068EC15A27ED99E700D5D11E /* ServerListViewModel.swift in Sources */,
|
068EC15A27ED99E700D5D11E /* ServerListViewModel.swift in Sources */,
|
||||||
06172FDC27F6DB06002333A4 /* ServerListTableViewCellViewModel.swift in Sources */,
|
06172FDC27F6DB06002333A4 /* ServerListTableViewCellViewModel.swift in Sources */,
|
||||||
|
061894C729A75BEA00E001C2 /* Algorithm.swift in Sources */,
|
||||||
065BE4502563D939002A8CA4 /* SoundCellViewModel.swift in Sources */,
|
065BE4502563D939002A8CA4 /* SoundCellViewModel.swift in Sources */,
|
||||||
06B1158F247BB1FB006D91FB /* Message.swift in Sources */,
|
06B1158F247BB1FB006D91FB /* Message.swift in Sources */,
|
||||||
06172FDA27F6DAEF002333A4 /* ServerListTableViewCell.swift in Sources */,
|
06172FDA27F6DAEF002333A4 /* ServerListTableViewCell.swift in Sources */,
|
||||||
|
|||||||
@ -124,8 +124,8 @@ import = "Import";
|
|||||||
exportOrImport = "Export and import messages";
|
exportOrImport = "Export and import messages";
|
||||||
items = "messages";
|
items = "messages";
|
||||||
|
|
||||||
enterKey = "Please enter %s-bit Key";
|
enterKey = "Please enter %d-bit Key";
|
||||||
enterIv = "Please enter %s-bit Iv";
|
enterIv = "Please enter 16-bit Iv";
|
||||||
encryptionSettings = "Encryption Settings";
|
encryptionSettings = "Encryption Settings";
|
||||||
algorithm = "Algorithm";
|
algorithm = "Algorithm";
|
||||||
mode = "Mode";
|
mode = "Mode";
|
||||||
|
|||||||
@ -127,7 +127,7 @@ import = "导入";
|
|||||||
exportOrImport = "导出或导入消息列表";
|
exportOrImport = "导出或导入消息列表";
|
||||||
items = "条消息";
|
items = "条消息";
|
||||||
|
|
||||||
enterKey = "请输入%s位Key";
|
enterKey = "请输入%d位Key";
|
||||||
enterIv = "请输入16位Iv";
|
enterIv = "请输入16位Iv";
|
||||||
encryptionSettings = "加密设置";
|
encryptionSettings = "加密设置";
|
||||||
algorithm = "算法";
|
algorithm = "算法";
|
||||||
|
|||||||
@ -7,6 +7,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import UIKit
|
import UIKit
|
||||||
|
import RxSwift
|
||||||
|
|
||||||
class CryptoSettingController: BaseViewController<CryptoSettingModel> {
|
class CryptoSettingController: BaseViewController<CryptoSettingModel> {
|
||||||
let algorithmFeild = DropBoxView(values: ["AES128", "AES192", "AES256"])
|
let algorithmFeild = DropBoxView(values: ["AES128", "AES192", "AES256"])
|
||||||
@ -180,4 +181,32 @@ class CryptoSettingController: BaseViewController<CryptoSettingModel> {
|
|||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
self.view.backgroundColor = BKColor.white
|
self.view.backgroundColor = BKColor.white
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override func bindViewModel() {
|
||||||
|
|
||||||
|
let output = viewModel.transform(input: CryptoSettingModel.Input(
|
||||||
|
algorithmChanged: self.algorithmFeild
|
||||||
|
.rx
|
||||||
|
.currentValueChanged
|
||||||
|
.compactMap{$0}
|
||||||
|
.asDriver(onErrorDriveWith: .empty())
|
||||||
|
))
|
||||||
|
|
||||||
|
output.algorithmList
|
||||||
|
.map{$0.map {$0.rawValue}}
|
||||||
|
.drive(self.algorithmFeild.rx.values)
|
||||||
|
.disposed(by: rx.disposeBag)
|
||||||
|
|
||||||
|
output.modeList
|
||||||
|
.drive(self.modeFeild.rx.values)
|
||||||
|
.disposed(by: rx.disposeBag)
|
||||||
|
|
||||||
|
output.paddingList
|
||||||
|
.drive(self.paddingField.rx.values)
|
||||||
|
.disposed(by: rx.disposeBag)
|
||||||
|
|
||||||
|
output.keyLenght.drive(onNext: {[weak self] keyLenght in
|
||||||
|
self?.keyTextField.placeholder = String(format: NSLocalizedString("enterKey"), keyLenght)
|
||||||
|
}).disposed(by: rx.disposeBag)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,13 +8,38 @@
|
|||||||
|
|
||||||
import CryptoSwift
|
import CryptoSwift
|
||||||
import Foundation
|
import Foundation
|
||||||
class CryptoSettingModel: ViewModel, ViewModelType {
|
import RxCocoa
|
||||||
struct Input {}
|
import RxSwift
|
||||||
|
|
||||||
struct Output {}
|
class CryptoSettingModel: ViewModel, ViewModelType {
|
||||||
|
struct Input {
|
||||||
|
let algorithmChanged: Driver<String>
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Output {
|
||||||
|
let algorithmList: Driver<[Algorithm]>
|
||||||
|
let modeList: Driver<[String]>
|
||||||
|
let paddingList: Driver<[String]>
|
||||||
|
let keyLenght: Driver<Int>
|
||||||
|
}
|
||||||
|
|
||||||
func transform(input: Input) -> Output {
|
func transform(input: Input) -> Output {
|
||||||
return Output()
|
let modeList = input
|
||||||
|
.algorithmChanged
|
||||||
|
.compactMap { Algorithm(rawValue: $0) }
|
||||||
|
.map { $0.modes }
|
||||||
|
|
||||||
|
let keyLenght = input
|
||||||
|
.algorithmChanged
|
||||||
|
.compactMap { Algorithm(rawValue: $0) }
|
||||||
|
.map { $0.keyLenght }
|
||||||
|
|
||||||
|
return Output(
|
||||||
|
algorithmList: Driver.just([Algorithm.aes128, Algorithm.aes192, Algorithm.aes256]),
|
||||||
|
modeList: Driver.merge(Driver.just(["CBC", "ECB", "GCM"]), modeList),
|
||||||
|
paddingList: Driver.just(["pkcs7"]),
|
||||||
|
keyLenght: Driver.merge(Driver.just(16), keyLenght)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override init() {
|
override init() {
|
||||||
|
|||||||
40
Model/Algorithm.swift
Normal file
40
Model/Algorithm.swift
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
//
|
||||||
|
// Algorithm.swift
|
||||||
|
// Bark
|
||||||
|
//
|
||||||
|
// Created by huangfeng on 2023/2/23.
|
||||||
|
// Copyright © 2023 Fin. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
enum Algorithm: String {
|
||||||
|
case aes128 = "AES128"
|
||||||
|
case aes192 = "AES192"
|
||||||
|
case aes256 = "AES256"
|
||||||
|
|
||||||
|
var modes: [String] {
|
||||||
|
switch self {
|
||||||
|
case .aes128, .aes192, .aes256:
|
||||||
|
return ["CBC", "ECB", "GCM"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var paddings: [String] {
|
||||||
|
switch self {
|
||||||
|
case .aes128, .aes192, .aes256:
|
||||||
|
return ["pkcs7"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var keyLenght: Int {
|
||||||
|
switch self {
|
||||||
|
case .aes128:
|
||||||
|
return 16
|
||||||
|
case .aes192:
|
||||||
|
return 24
|
||||||
|
case .aes256:
|
||||||
|
return 32
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -8,6 +8,8 @@
|
|||||||
|
|
||||||
import DropDown
|
import DropDown
|
||||||
import UIKit
|
import UIKit
|
||||||
|
import RxCocoa
|
||||||
|
import RxSwift
|
||||||
|
|
||||||
class DropBoxView: UIView {
|
class DropBoxView: UIView {
|
||||||
|
|
||||||
@ -42,13 +44,21 @@ class DropBoxView: UIView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let values: [String]
|
var values: [String] {
|
||||||
|
didSet {
|
||||||
|
self.currentValue = values.first
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var currentValue: String? {
|
var currentValue: String? {
|
||||||
didSet {
|
didSet {
|
||||||
self.valueLabel.text = currentValue
|
self.valueLabel.text = currentValue
|
||||||
|
self.currentValueChanged?(self.currentValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var currentValueChanged: ((String?) -> Void)?
|
||||||
|
|
||||||
init(values: [String]) {
|
init(values: [String]) {
|
||||||
self.values = values
|
self.values = values
|
||||||
super.init(frame: CGRect.zero)
|
super.init(frame: CGRect.zero)
|
||||||
@ -107,3 +117,21 @@ class DropBoxView: UIView {
|
|||||||
dropDown.show()
|
dropDown.show()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension Reactive where Base: DropBoxView {
|
||||||
|
|
||||||
|
var currentValueChanged: ControlEvent<String?> {
|
||||||
|
let source = Observable<String?>.create { [weak control = self.base] observer -> Disposable in
|
||||||
|
MainScheduler.ensureExecutingOnScheduler()
|
||||||
|
guard let control = control else {
|
||||||
|
observer.onCompleted()
|
||||||
|
return Disposables.create()
|
||||||
|
}
|
||||||
|
control.currentValueChanged = { value in
|
||||||
|
observer.onNext(value)
|
||||||
|
}
|
||||||
|
return Disposables.create()
|
||||||
|
}
|
||||||
|
return ControlEvent(events: source)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user