Skip to content

Commit ef10b81

Browse files
authored
Add Certificate.PrivateKey description (#132)
* Add `Certificate.PrivateKey` description and update `Certificate.PublicKey` description to disambiguate from private keys. * secure enclave is only a thing on darwin * update tests
1 parent 708eb05 commit ef10b81

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

Sources/X509/CertificatePrivateKey.swift

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,20 @@ extension Certificate.PrivateKey: Sendable {}
152152

153153
extension Certificate.PrivateKey: CustomStringConvertible {
154154
public var description: String {
155-
return "TODO"
155+
switch self.backing {
156+
case .p256:
157+
return "P256.PrivateKey"
158+
case .p384:
159+
return "P384.PrivateKey"
160+
case .p521:
161+
return "P521.PrivateKey"
162+
case .rsa(let publicKey):
163+
return "RSA\(publicKey.keySizeInBits).PrivateKey"
164+
#if canImport(Darwin)
165+
case .secureEnclaveP256:
166+
return "SecureEnclave.P256.PrivateKey"
167+
#endif
168+
}
156169
}
157170
}
158171

Sources/X509/CertificatePublicKey.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,13 @@ extension Certificate.PublicKey: CustomStringConvertible {
163163
public var description: String {
164164
switch self.backing {
165165
case .p256:
166-
return "P256"
166+
return "P256.PublicKey"
167167
case .p384:
168-
return "P384"
168+
return "P384.PublicKey"
169169
case .p521:
170-
return "P521"
170+
return "P521.PublicKey"
171171
case .rsa(let publicKey):
172-
return "RSA\(publicKey.keySizeInBits)"
172+
return "RSA\(publicKey.keySizeInBits).PublicKey"
173173
}
174174
}
175175
}

Tests/X509Tests/CertificateTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ final class CertificateTests: XCTestCase {
513513
subject: "CN=Swift Certificate Test CA 1,O=Apple,C=US", \
514514
notValidBefore: 2022-08-08 14:26:14 +0000, \
515515
notValidAfter: 2033-08-05 14:26:14 +0000, \
516-
publicKey: P384, \
516+
publicKey: P384.PublicKey, \
517517
signature: ECDSA, \
518518
extensions: [\
519519
BasicConstraints(CA=TRUE), \
@@ -576,7 +576,7 @@ final class CertificateTests: XCTestCase {
576576
subject: "CN=Swift Certificate Test Intermediate CA 1,O=Apple,C=US", \
577577
notValidBefore: 2022-08-08 14:26:14 +0000, \
578578
notValidAfter: 2028-08-06 14:26:14 +0000, \
579-
publicKey: P256, \
579+
publicKey: P256.PublicKey, \
580580
signature: ECDSA, \
581581
extensions: [\
582582
BasicConstraints(CA=TRUE, maxPathLength=1), \
@@ -626,7 +626,7 @@ final class CertificateTests: XCTestCase {
626626
subject: "STREET=Infinite Loop,CN=localhost,O=Apple,C=US", \
627627
notValidBefore: 2022-08-08 14:26:14 +0000, \
628628
notValidAfter: 2024-08-07 14:26:14 +0000, \
629-
publicKey: P256, \
629+
publicKey: P256.PublicKey, \
630630
signature: ECDSA, \
631631
extensions: [\
632632
BasicConstraints(CA=FALSE), \

0 commit comments

Comments
 (0)