Move Parse{Public|Private}Key and MarshalToPEM functions to their respective crypto package
Opened this issue · 1 comments
meling commented
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:
hotstuff.{Private|Public}Key
should require key types to provide aMarshalToPEM() ([]byte, error)
method.ParsePublicKey(buf []byte) (key hotstuff.PublicKey, err error)
ParsePrivateKey(buf []byte) (key hotstuff.PrivateKey, err error)
Have I've overlooked something that makes this approach less desirable?
meling commented
This rewrite should add tests to check that the marshaled keys and be unmarshaled with the corresponding Parse funcs.