Add descriptions for unavailable keys (#708)

* Describe unavailable key types

* Cleanup
This commit is contained in:
Max Goedjen
2025-09-14 14:42:41 -07:00
committed by GitHub
parent 3f247d628f
commit d7f8d5e56b
6 changed files with 82 additions and 25 deletions

View File

@@ -60,16 +60,17 @@ extension Preview {
let id = UUID()
var name: String { "Modifiable Preview Store" }
let secrets: [Secret]
var supportedKeyTypes: [KeyType] {
if #available(macOS 26, *) {
[
var supportedKeyTypes: KeyAvailability {
return KeyAvailability(
available: [
.ecdsa256,
.mldsa65,
.mldsa87,
.mldsa87
],
unavailable: [
.init(keyType: .ecdsa384, reason: .macOSUpdateRequired)
]
} else {
[.ecdsa256]
}
)
}
init(secrets: [Secret]) {

View File

@@ -75,10 +75,23 @@ struct CreateSecretView<StoreType: SecretStoreModifiable>: View {
Section {
VStack {
Picker(.createSecretKeyTypeLabel, selection: $keyType) {
ForEach(store.supportedKeyTypes, id: \.self) { option in
ForEach(store.supportedKeyTypes.available, id: \.self) { option in
Text(String(describing: option))
.tag(option)
.font(.caption)
}
Divider()
ForEach(store.supportedKeyTypes.unavailable, id: \.keyType) { option in
VStack {
Button {
} label: {
Text(String(describing: option.keyType))
switch option.reason {
case .macOSUpdateRequired:
Text(.createSecretKeyTypeMacOSUpdateRequiredLabel)
}
}
}
.selectionDisabled()
}
}
if keyType?.algorithm == .mldsa {
@@ -119,7 +132,7 @@ struct CreateSecretView<StoreType: SecretStoreModifiable>: View {
.padding()
}
.onAppear {
keyType = store.supportedKeyTypes.first
keyType = store.supportedKeyTypes.available.first
}
.formStyle(.grouped)
}
@@ -146,6 +159,6 @@ struct CreateSecretView<StoreType: SecretStoreModifiable>: View {
}
//#Preview {
// CreateSecretView(store: Preview.StoreModifiable()) { _ in }
//}
#Preview {
CreateSecretView(store: Preview.StoreModifiable()) { _ in }
}