Skip to content

Conversation

@Juice805
Copy link

@Juice805 Juice805 commented Nov 10, 2025

Motivation:

In some cases a developer may want to sign a certificate using a method other than a private key. For example: if a private key is protected by hardware which signs asynchronously.

Modifications:

  • Create CustomPrivateKey protocol
  • Create async initializers for Certificate and CertificateSigningRequest.
  • CustomPrivateKey can now back aCertificate.PrivateKey
  • Make Certificate.Signature initializer public

Result:

Developers can now sign a certificate with greater flexibility.

Alternatives Considered:

Implementations

Pass the CustomPrivateKey into Certificate and CertificateSigningRequest initializers directly.

There is concern this could add too much duplication of api.

Various names for the protocol:

  • Certificate.PrivateKeyProtocol and Certificate.AsyncPrivateKeyProtocol
  • Certificate.Signer/Certificate.AsyncSigner
  • Certificate.SignatureProvider/Certificate.AsyncSignatureProvider

@Lukasa Lukasa added the 🆕 semver/minor Adds new public API. label Dec 12, 2025
Motivation:

The new tests should be run

Modifications:

The new tests are missing the `@Test` macros

Result:

The new tests will have the `@Test` macros
Motivation:

Code should be clean

Modifications:

Removed `@inlinable` from protocol definition

Result:

protocol will not have `@inlinable`
Motivation:

Default implementation of signAsynchronously should be inlinable

Modifications:

adds `@inlinable` to default signAsynchronously implementation.

Result:

default signAsynchronously implementation will be `@inlinable`
Motivation:

`signAsynchronously` should not it is not mandatory to implement

Modifications:

Updated documentation

Result:

`signAsynchronously` has better docs
/// preference or security of the contained algorithms.
var supportedSignatureAlgorithms: [Certificate.SignatureAlgorithm] { get }

/// Use the private key to sign the provided bytes with a given signature algorithm.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is an async only private key supposed to implement this function? Should it throw or block instead?
Should this be separate protocols for async and sync keys?

some documentation/guidance for conforming types and callers of this function would be good.

Copy link
Author

@Juice805 Juice805 Dec 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was my original implementation. I believe the concern was it could lead to too much api duplication.

I will add documentation to guide the developer to throw an error in the case of unsupported synchronous signing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🆕 semver/minor Adds new public API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants