Skip to content

Commit

Permalink
Codable Config
Browse files Browse the repository at this point in the history
  • Loading branch information
consuelita committed Dec 13, 2018
1 parent 9fbbc9f commit dccd274
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Sources/ReplicantSwift/Models/SequenceModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct SequenceModel
public struct SequenceModel: Codable
{
/// Byte Sequence.
var sequence: Data
Expand Down
8 changes: 6 additions & 2 deletions Sources/ReplicantSwift/Polish.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -33,7 +38,6 @@ public class Polish: NSObject

self.privateKey = newKeyPair.privateKey
self.publicKey = newKeyPair.publicKey
self.recipientPublicKey = recipientPublicKey
}

deinit
Expand Down
6 changes: 3 additions & 3 deletions Sources/ReplicantSwift/ReplicantConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Sources/ReplicantSwift/ReplicantServerConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct ReplicantServerConfig
public struct ReplicantServerConfig: Codable
{
public var chunkSize: Int
public var chunkTimeout: Int
Expand Down
4 changes: 2 additions & 2 deletions Sources/ReplicantSwift/ReplicantSwift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit dccd274

Please sign in to comment.