2020-03-07 23:09:18 +00:00
|
|
|
public protocol Secret: Identifiable, Hashable {
|
2020-03-04 07:14:38 +00:00
|
|
|
|
|
|
|
var name: String { get }
|
|
|
|
var publicKey: Data { get }
|
|
|
|
|
2020-02-19 04:52:00 +00:00
|
|
|
}
|
2020-03-07 23:04:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public struct AnySecret: Secret {
|
|
|
|
|
2020-03-07 23:09:18 +00:00
|
|
|
fileprivate let hashable: AnyHashable
|
2020-03-07 23:04:36 +00:00
|
|
|
fileprivate let _id: () -> AnyHashable
|
|
|
|
fileprivate let _name: () -> String
|
|
|
|
fileprivate let _publicKey: () -> Data
|
|
|
|
|
|
|
|
public init<T>(_ secret: T) where T: Secret {
|
2020-03-07 23:09:18 +00:00
|
|
|
self.hashable = secret
|
2020-03-07 23:04:36 +00:00
|
|
|
_id = { secret.id as AnyHashable }
|
|
|
|
_name = { secret.name }
|
|
|
|
_publicKey = { secret.publicKey }
|
|
|
|
}
|
|
|
|
|
|
|
|
public var id: AnyHashable {
|
|
|
|
return _id()
|
|
|
|
}
|
|
|
|
|
|
|
|
public var name: String {
|
|
|
|
return _name()
|
|
|
|
}
|
|
|
|
|
|
|
|
public var publicKey: Data {
|
|
|
|
return _publicKey()
|
|
|
|
}
|
|
|
|
|
2020-03-07 23:09:18 +00:00
|
|
|
public static func == (lhs: AnySecret, rhs: AnySecret) -> Bool {
|
|
|
|
lhs.hashable == rhs.hashable
|
|
|
|
}
|
|
|
|
|
|
|
|
public func hash(into hasher: inout Hasher) {
|
|
|
|
hashable.hash(into: &hasher)
|
|
|
|
}
|
|
|
|
|
2020-03-07 23:04:36 +00:00
|
|
|
}
|
|
|
|
|