From dccd274ccd0a90fc707794b101bf05a2b8040aff Mon Sep 17 00:00:00 2001 From: Lita Date: Wed, 12 Dec 2018 18:36:26 -0600 Subject: [PATCH] Codable Config --- Sources/ReplicantSwift/Models/SequenceModel.swift | 2 +- Sources/ReplicantSwift/Polish.swift | 8 ++++++-- Sources/ReplicantSwift/ReplicantConfig.swift | 6 +++--- Sources/ReplicantSwift/ReplicantServerConfig.swift | 2 +- Sources/ReplicantSwift/ReplicantSwift.swift | 4 ++-- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/Sources/ReplicantSwift/Models/SequenceModel.swift b/Sources/ReplicantSwift/Models/SequenceModel.swift index 411f762..6c31c22 100644 --- a/Sources/ReplicantSwift/Models/SequenceModel.swift +++ b/Sources/ReplicantSwift/Models/SequenceModel.swift @@ -7,7 +7,7 @@ import Foundation -public struct SequenceModel +public struct SequenceModel: Codable { /// Byte Sequence. var sequence: Data diff --git a/Sources/ReplicantSwift/Polish.swift b/Sources/ReplicantSwift/Polish.swift index 20ee9b5..cb44590 100644 --- a/Sources/ReplicantSwift/Polish.swift +++ b/Sources/ReplicantSwift/Polish.swift @@ -21,10 +21,15 @@ public class Polish: NSObject public var publicKey: SecKey public var privateKey: SecKey - public init?(recipientPublicKey: SecKey?) + public init?(recipientPublicKeyData: Data?) { Polish.deleteKeys() + if let rPublicKeyData = recipientPublicKeyData + { + recipientPublicKey = Polish.decodeKey(fromData: rPublicKeyData) + } + guard let newKeyPair = Polish.generateKeyPair() else { @@ -33,7 +38,6 @@ public class Polish: NSObject self.privateKey = newKeyPair.privateKey self.publicKey = newKeyPair.publicKey - self.recipientPublicKey = recipientPublicKey } deinit diff --git a/Sources/ReplicantSwift/ReplicantConfig.swift b/Sources/ReplicantSwift/ReplicantConfig.swift index e1c4ed9..64a722f 100644 --- a/Sources/ReplicantSwift/ReplicantConfig.swift +++ b/Sources/ReplicantSwift/ReplicantConfig.swift @@ -7,16 +7,16 @@ import Foundation -public struct ReplicantConfig +public struct ReplicantConfig: Codable { - public var serverPublicKey: SecKey + public var serverPublicKey: Data public var chunkSize: Int public var chunkTimeout: Int public var addSequences: [SequenceModel]? public var removeSequences: [SequenceModel]? - public init?(serverPublicKey: SecKey, chunkSize: Int, chunkTimeout: Int, addSequences: [SequenceModel]?, removeSequences: [SequenceModel]?) + public init?(serverPublicKey: Data, chunkSize: Int, chunkTimeout: Int, addSequences: [SequenceModel]?, removeSequences: [SequenceModel]?) { guard chunkSize >= keySize + aesOverheadSize else diff --git a/Sources/ReplicantSwift/ReplicantServerConfig.swift b/Sources/ReplicantSwift/ReplicantServerConfig.swift index e070fb3..2230fe8 100644 --- a/Sources/ReplicantSwift/ReplicantServerConfig.swift +++ b/Sources/ReplicantSwift/ReplicantServerConfig.swift @@ -7,7 +7,7 @@ import Foundation -public struct ReplicantServerConfig +public struct ReplicantServerConfig: Codable { public var chunkSize: Int public var chunkTimeout: Int diff --git a/Sources/ReplicantSwift/ReplicantSwift.swift b/Sources/ReplicantSwift/ReplicantSwift.swift index 76b0d73..e794f91 100644 --- a/Sources/ReplicantSwift/ReplicantSwift.swift +++ b/Sources/ReplicantSwift/ReplicantSwift.swift @@ -10,7 +10,7 @@ public struct Replicant public init?(withConfig config: ReplicantConfig) { - guard let polish = Polish(recipientPublicKey: config.serverPublicKey) + guard let polish = Polish(recipientPublicKeyData: config.serverPublicKey) else { return nil @@ -34,7 +34,7 @@ public struct ReplicantServer public init?(withConfig config: ReplicantServerConfig) { - guard let polish = Polish(recipientPublicKey: nil) + guard let polish = Polish(recipientPublicKeyData: nil) else { return nil