ProtonMail / go-crypto

Fork of go/x/crypto, providing an up-to-date OpenPGP implementation
https://pkg.go.dev/github.com/ProtonMail/go-crypto
BSD 3-Clause "New" or "Revised" License
328 stars 99 forks source link

Feature request: Support to wrap pre-created RSA, ECDSA or Ed25519 keys #202

Open balena opened 5 months ago

balena commented 5 months ago

Context

There are use cases where keys are pre-created. For example, on environments where key derivations are required.

The function NewEntity can only be used to create keys from scratch based on parameters passed on the config, and does not allow passing pre-created keys.

Solution

In the PR https://github.com/ProtonMail/go-crypto/pull/201, I've created a new function NewEntityFromKey so that users can pass pre-created keys of types *rsa.PrivateKey, *ecdsa.PrivateKey and ed25519.PrivateKey (not a pointer).

I copied the latter assumptions from the package x509 (for instance function MarshalPKCS8PrivateKey), looks like it is being a convention in the Go standard libraries to pass around ed25519.PrivateKey and ed25519.PublicKey keys without pointers.

This is a proof the entity created from passed keys works with gpg: https://gist.github.com/balena/27ef6b7ca319cd43f0d2d9ff2af49248 (run with go test -v -count=1 .)