Add capabilities.

This commit is contained in:
Max Goedjen 2025-08-23 19:35:21 -07:00
parent 8c2f9c14cd
commit bfa7a3cd51
No known key found for this signature in database
2 changed files with 14 additions and 1 deletions

View File

@ -12,6 +12,12 @@ extension SmartCard {
public let keySize: Int public let keySize: Int
public let requiresAuthentication: Bool = false public let requiresAuthentication: Bool = false
public let publicKey: Data public let publicKey: Data
public let capabilities: Set<KeyCapabilities>
public enum KeyCapabilities: Sendable {
case signature
case encryption
}
} }

View File

@ -170,7 +170,14 @@ extension SmartCard.Store {
let publicKeySecRef = SecKeyCopyPublicKey(publicKeyRef)! let publicKeySecRef = SecKeyCopyPublicKey(publicKeyRef)!
let publicKeyAttributes = SecKeyCopyAttributes(publicKeySecRef) as! [CFString: Any] let publicKeyAttributes = SecKeyCopyAttributes(publicKeySecRef) as! [CFString: Any]
let publicKey = publicKeyAttributes[kSecValueData] as! Data let publicKey = publicKeyAttributes[kSecValueData] as! Data
return SmartCard.Secret(id: tokenID, name: name, algorithm: algorithm, keySize: keySize, publicKey: publicKey) var capabilities: Set<SmartCard.Secret.KeyCapabilities> = []
if ($0[kSecAttrCanSign] as? Bool) == true {
capabilities.insert(.signature)
}
if ($0[kSecAttrCanEncrypt] as? Bool) == true && ($0[kSecAttrCanDecrypt] as? Bool) == true {
capabilities.insert(.encryption)
}
return SmartCard.Secret(id: tokenID, name: name, algorithm: algorithm, keySize: keySize, publicKey: publicKey, capabilities: capabilities)
} }
state.secrets.append(contentsOf: wrapped) state.secrets.append(contentsOf: wrapped)
} }