-
Notifications
You must be signed in to change notification settings - Fork 76
Add new Certificate.PrivateKey
init from PKCS8 DER bytes
#248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@available(macOS 11.0, iOS 14, tvOS 14, watchOS 7, macCatalyst 14, visionOS 1.0, *) | ||
extension Certificate.PrivateKey { | ||
/// Initialize a new certificate private key from PKCS8-format DER bytes. | ||
public init(pkcs8DERBytes: [UInt8]) throws { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sort-of thinking that this should be public init(derBytes:)
. We'd be willing to detect what the right answer was if we had to, but I think we mostly don't have to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I flip-flopped a bit on this since being unspecific about the format lets us evolve the API better. However it is a reality that right now we only understand PKCS8 in DER. Should I still mention this in the docs but change the argument label?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we detect different representation just based on the DER representation reliably?
I don't recall the details but I thought there was a good reason why we switch over the pem discriminator instead of just looking at the bytes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, we can't detect it reliably, but that's ok: it's what PKCS#8 is for. I suspect we'll only ever support the PKCS#8 format here, and that's fine.
@available(macOS 11.0, iOS 14, tvOS 14, watchOS 7, macCatalyst 14, visionOS 1.0, *) | ||
extension Certificate.PrivateKey { | ||
/// Initialize a new certificate private key from PKCS8-format DER bytes. | ||
public init(pkcs8DERBytes: [UInt8]) throws { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's also add at least one unit test that uses this constructor directly, ideally one per algorithm.
415098e
to
7a8b9d4
Compare
7a8b9d4
to
24b1878
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lovely, thanks @gjcairo!
This PR adds a new
init(derBytes:)
to initialise a private key in PKCS8 format from an array of DER bytes.