secretive/Sources/Packages/Sources/SecretKit/Types/Secret.swift

36 lines
1.1 KiB
Swift
Raw Normal View History

import Foundation
/// 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
/// A user-facing string identifying the Secret.
2020-03-04 07:14:38 +00:00
var name: String { get }
/// The algorithm this secret uses.
var algorithm: Algorithm { get }
/// The key size for the secret.
var keySize: Int { get }
/// Whether the secret requires authentication before use.
var requiresAuthentication: Bool { get }
/// 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
}
/// 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 {
2020-03-10 05:06:51 +00:00
case ellipticCurve
/// Initializes the Algorithm with a secAttr representation of an algorithm.
/// - Parameter secAttr: the secAttr, represented as an NSNumber.
public init(secAttr: NSNumber) {
let secAttrString = secAttr.stringValue as CFString
switch secAttrString {
case kSecAttrKeyTypeEC:
self = .ellipticCurve
default:
fatalError()
}
}
}