2022-01-02 00:43:29 +00:00
|
|
|
import Foundation
|
|
|
|
|
2022-01-02 02:10:44 +00:00
|
|
|
/// The base protocol for describing a Secret
|
2020-02-19 04:52:00 +00:00
|
|
|
public protocol Secret: Identifiable, Hashable {
|
2020-03-04 07:14:38 +00:00
|
|
|
|
2022-01-02 02:10:44 +00:00
|
|
|
/// A user-facing string identifying the Secret.
|
2020-03-04 07:14:38 +00:00
|
|
|
var name: String { get }
|
2022-01-02 02:10:44 +00:00
|
|
|
/// The algorithm this secret uses.
|
2020-03-09 05:17:59 +00:00
|
|
|
var algorithm: Algorithm { get }
|
2022-01-02 02:10:44 +00:00
|
|
|
/// The key size for the secret.
|
2020-03-09 05:17:59 +00:00
|
|
|
var keySize: Int { get }
|
2022-02-25 06:59:35 +00:00
|
|
|
/// Whether the secret requires authentication before use.
|
|
|
|
var requiresAuthentication: Bool { get }
|
2022-01-02 02:10:44 +00:00
|
|
|
/// The public key data for the secret.
|
2020-03-04 07:14:38 +00:00
|
|
|
var publicKey: Data { get }
|
|
|
|
|
2020-02-19 04:52:00 +00:00
|
|
|
}
|
2020-03-09 05:17:59 +00:00
|
|
|
|
2022-01-02 02:10:44 +00:00
|
|
|
/// The type of algorithm the Secret uses. Currently, only elliptic curve algorithms are supported.
|
2020-03-24 06:22:22 +00:00
|
|
|
public enum Algorithm: Hashable {
|
2022-01-02 02:10:44 +00:00
|
|
|
|
2020-03-10 05:06:51 +00:00
|
|
|
case ellipticCurve
|
2022-01-02 02:10:44 +00:00
|
|
|
|
|
|
|
/// Initializes the Algorithm with a secAttr representation of an algorithm.
|
|
|
|
/// - Parameter secAttr: the secAttr, represented as an NSNumber.
|
2020-03-09 05:17:59 +00:00
|
|
|
public init(secAttr: NSNumber) {
|
|
|
|
let secAttrString = secAttr.stringValue as CFString
|
|
|
|
switch secAttrString {
|
|
|
|
case kSecAttrKeyTypeEC:
|
|
|
|
self = .ellipticCurve
|
|
|
|
default:
|
|
|
|
fatalError()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|