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

Add GetPublicKeyFromContact functor

parent 6a540463
No related branches found
No related tags found
2 merge requests!102Release 1.0.0,!18Update Bindings
import Bindings import Bindings
import XCTestDynamicOverlay
public struct ContactPubkeyProvider { public struct GetPublicKeyFromContact {
public var get: (Data) throws -> Data public var run: (Data) throws -> Data
public func callAsFunction(contact: Data) throws -> Data { public func callAsFunction(contact: Data) throws -> Data {
try get(contact) try run(contact)
} }
} }
extension ContactPubkeyProvider { extension GetPublicKeyFromContact {
public static let live = ContactPubkeyProvider { contact in public static let live = GetPublicKeyFromContact { contact in
var error: NSError? var error: NSError?
let pubkey = BindingsGetPubkeyFromContact(contact, &error) let key = BindingsGetPubkeyFromContact(contact, &error)
if let error = error { if let error = error {
throw error throw error
} }
guard let pubkey = pubkey else { guard let key = key else {
fatalError("BindingsGetPubkeyFromContact returned `nil` without providing error") fatalError("BindingsGetPubkeyFromContact returned `nil` without providing error")
} }
return pubkey return key
} }
} }
#if DEBUG extension GetPublicKeyFromContact {
extension ContactPubkeyProvider { public static let unimplemented = GetPublicKeyFromContact(
public static let failing = ContactPubkeyProvider { _ in run: XCTUnimplemented("\(Self.self)")
struct NotImplemented: Error {} )
throw NotImplemented()
}
} }
#endif
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