From bfa7a3cd51f15ba449b77f5a1320a43aa491d05a Mon Sep 17 00:00:00 2001 From: Max Goedjen Date: Sat, 23 Aug 2025 19:35:21 -0700 Subject: [PATCH] Add capabilities. --- .../Sources/SmartCardSecretKit/SmartCardSecret.swift | 6 ++++++ .../Sources/SmartCardSecretKit/SmartCardStore.swift | 9 ++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Sources/Packages/Sources/SmartCardSecretKit/SmartCardSecret.swift b/Sources/Packages/Sources/SmartCardSecretKit/SmartCardSecret.swift index 348926f..bfa7420 100644 --- a/Sources/Packages/Sources/SmartCardSecretKit/SmartCardSecret.swift +++ b/Sources/Packages/Sources/SmartCardSecretKit/SmartCardSecret.swift @@ -12,6 +12,12 @@ extension SmartCard { public let keySize: Int public let requiresAuthentication: Bool = false public let publicKey: Data + public let capabilities: Set + + public enum KeyCapabilities: Sendable { + case signature + case encryption + } } diff --git a/Sources/Packages/Sources/SmartCardSecretKit/SmartCardStore.swift b/Sources/Packages/Sources/SmartCardSecretKit/SmartCardStore.swift index d52c1c8..4d8f42c 100644 --- a/Sources/Packages/Sources/SmartCardSecretKit/SmartCardStore.swift +++ b/Sources/Packages/Sources/SmartCardSecretKit/SmartCardStore.swift @@ -170,7 +170,14 @@ extension SmartCard.Store { let publicKeySecRef = SecKeyCopyPublicKey(publicKeyRef)! let publicKeyAttributes = SecKeyCopyAttributes(publicKeySecRef) as! [CFString: Any] let publicKey = publicKeyAttributes[kSecValueData] as! Data - return SmartCard.Secret(id: tokenID, name: name, algorithm: algorithm, keySize: keySize, publicKey: publicKey) + var capabilities: Set = [] + 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) }