ProtonMail/go-crypto

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

balena opened this issue · 0 comments

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 #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 .)