Skip to content
Snippets Groups Projects
Commit 8d56fcfe authored by Dariusz Rybicki's avatar Dariusz Rybicki
Browse files

Add ClientCreator

parent 08b5e5c1
No related branches found
No related tags found
1 merge request!1Client management
import Bindings
public struct ClientCreator {
public var create: (URL, Data, Data) throws -> Void
public func callAsFunction(directoryURL: URL, ndf: Data, password: Data) throws {
try create(directoryURL, ndf, password)
}
}
extension ClientCreator {
public static let live = ClientCreator { directoryURL, ndf, password in
var error: NSError?
let network = String(data: ndf, encoding: .utf8)!
let created = BindingsNewClient(network, directoryURL.path, password, nil, &error)
if let error = error {
throw error
}
if !created {
throw BindingsNewClientUnknownError()
}
}
}
#if DEBUG
extension ClientCreator {
public static let failing = ClientCreator { _, _, _ in
struct NotImplemented: Error {}
throw NotImplemented()
}
}
#endif
......@@ -9,3 +9,7 @@ public struct BindingsGenerateSecretUnknownError: Error, Equatable {
public struct PasswordStorageMissingPasswordError: Error, Equatable {
public init() {}
}
public struct BindingsNewClientUnknownError: Error, Equatable {
public init() {}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment