relab / hotstuff

MIT License
166 stars 52 forks source link

Move Parse{Public|Private}Key and MarshalToPEM functions to their respective crypto package #122

Open meling opened 4 months ago

meling commented 4 months ago

We have functions for parsing from []byte to key and marshaling key to PEM in the keygen package.

// ParsePrivateKey parses a PEM encoded private key.
func ParsePrivateKey(buf []byte) (key hotstuff.PrivateKey, err error)
// ParsePublicKey parses a PEM encoded public key
func ParsePublicKey(buf []byte) (key hotstuff.PublicKey, err error) 

// PrivateKeyToPEM encodes the private key in PEM format.
func PrivateKeyToPEM(key hotstuff.PrivateKey) ([]byte, error)
// PublicKeyToPEM encodes the public key in PEM format.
func PublicKeyToPEM(key hotstuff.PublicKey) ([]byte, error)

However, these belong in their respective packages {ecdsa, eddsa, bls12}, since we must add code to these methods whenever we add a new crypto scheme and expose parsing details outside the package, which could be kept internal to the specific package.

That is, we should add these to the different crypto packages:

Have I've overlooked something that makes this approach less desirable?

meling commented 4 months ago

This rewrite should add tests to check that the marshaled keys and be unmarshaled with the corresponding Parse funcs.