File tree Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -14,8 +14,14 @@ public protocol SecKeyConvertible: SecKeyRepresentable {
14
14
/// Creates a key from an X9.63 representation.
15
15
init < Bytes> ( x963Representation: Bytes ) throws where Bytes: ContiguousBytes
16
16
17
+ /// Creates a key from a Distinguished Encoding Rules (DER) encoded representation.
18
+ init < Bytes> ( derRepresentation: Bytes ) throws where Bytes : RandomAccessCollection , Bytes. Element == UInt8
19
+
17
20
/// An X9.63 representation of the key.
18
21
var x963Representation : Data { get }
22
+
23
+ /// A Distinguished Encoding Rules (DER) encoded representation of the private key.
24
+ var derRepresentation : Data { get }
19
25
}
20
26
21
27
// MARK: - CryptoKit
@@ -86,10 +92,11 @@ extension SecKeyConvertible {
86
92
let keyData : Data
87
93
switch secKeyDescriptor. keyType {
88
94
case . ecsecPrimeRandom:
95
+ // X9.63
89
96
keyData = x963Representation
90
97
case . rsa:
91
- // override and use data in PKCS #1 format
92
- throw SwiftSecurityError . unimplemented
98
+ // PCKS #1, DER-Encoded
99
+ keyData = derRepresentation
93
100
}
94
101
95
102
var error : Unmanaged < CFError > ?
Original file line number Diff line number Diff line change @@ -349,8 +349,14 @@ extension Keychain: SecKeyStore {
349
349
}
350
350
throw SwiftSecurityError . invalidParameter
351
351
}
352
-
353
- return try T ( x963Representation: data)
352
+
353
+ if let ecKey = try ? T ( x963Representation: data) {
354
+ return ecKey
355
+ } else if let rsaKey = try ? T ( derRepresentation: data) {
356
+ return rsaKey
357
+ } else {
358
+ throw SwiftSecurityError . invalidParameter
359
+ }
354
360
}
355
361
}
356
362
You can’t perform that action at this time.
0 commit comments