-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2e89a48
commit 620fd88
Showing
9 changed files
with
238 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import Foundation | ||
import Security | ||
import CommonCrypto | ||
|
||
public struct ReplicantClientModel | ||
{ | ||
public let polish: PolishClientModel | ||
public var config: ReplicantConfig | ||
public var toneBurst: ToneBurst? | ||
|
||
public init?(withConfig config: ReplicantConfig) | ||
{ | ||
guard let polish = PolishClientModel(serverPublicKeyData: config.serverPublicKey) | ||
else | ||
{ | ||
return nil | ||
} | ||
|
||
if let addSequences = config.addSequences, let removeSequences = config.removeSequences | ||
{ | ||
self.toneBurst = ToneBurst(addSequences: addSequences, removeSequences: removeSequences) | ||
} | ||
|
||
self.config = config | ||
self.polish = polish | ||
} | ||
} | ||
|
||
extension Data | ||
{ | ||
public var bytes: Array<UInt8> | ||
{ | ||
return Array(self) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// | ||
// ReplicantServerModel.swift | ||
// ReplicantSwift | ||
// | ||
// Created by Adelita Schule on 12/18/18. | ||
// | ||
|
||
import Foundation | ||
|
||
public struct ReplicantServerModel | ||
{ | ||
public var polish: PolishServerModel | ||
public var config: ReplicantServerConfig | ||
public var toneBurst: ToneBurst? | ||
|
||
public init?(withConfig config: ReplicantServerConfig) | ||
{ | ||
guard let polish = PolishServerModel() | ||
else | ||
{ | ||
return nil | ||
} | ||
|
||
if let addSequences = config.addSequences, let removeSequences = config.removeSequences | ||
{ | ||
self.toneBurst = ToneBurst(addSequences: addSequences, removeSequences: removeSequences) | ||
} | ||
|
||
self.config = config | ||
self.polish = polish | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// | ||
// PolishClientModel.swift | ||
// ReplicantSwift | ||
// | ||
// Created by Adelita Schule on 12/18/18. | ||
// | ||
|
||
import Foundation | ||
|
||
public class PolishClientModel | ||
{ | ||
let controller = PolishController() | ||
|
||
public var serverPublicKey: SecKey | ||
public var publicKey: SecKey | ||
public var privateKey: SecKey | ||
|
||
public init?(serverPublicKeyData: Data) | ||
{ | ||
controller.deleteKeys() | ||
|
||
guard let sPublicKey = controller.decodeKey(fromData: serverPublicKeyData) | ||
else | ||
{ | ||
return nil | ||
} | ||
|
||
guard let newKeyPair = controller.generateKeyPair() | ||
else | ||
{ | ||
return nil | ||
} | ||
|
||
self.serverPublicKey = sPublicKey | ||
self.privateKey = newKeyPair.privateKey | ||
self.publicKey = newKeyPair.publicKey | ||
} | ||
|
||
deinit | ||
{ | ||
controller.deleteKeys() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// | ||
// PolishServerModel.swift | ||
// ReplicantSwift | ||
// | ||
// Created by Adelita Schule on 12/18/18. | ||
// | ||
|
||
import Foundation | ||
|
||
public class PolishServerModel | ||
{ | ||
let controller = PolishController() | ||
|
||
public var publicKey: SecKey | ||
public var privateKey: SecKey | ||
|
||
|
||
public init?() | ||
{ | ||
controller.deleteKeys() | ||
|
||
guard let newKeyPair = controller.generateKeyPair() | ||
else | ||
{ | ||
return nil | ||
} | ||
|
||
self.privateKey = newKeyPair.privateKey | ||
self.publicKey = newKeyPair.publicKey | ||
} | ||
|
||
deinit | ||
{ | ||
controller.deleteKeys() | ||
} | ||
} |
Oops, something went wrong.