-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Description
Proposal Details
hpke.PrivateKey can work with opaque keys, which by definition are not exportable and can't implement a Bytes() []byte method.
For example, one can pass a hardware key implementing ecdh.KeyExchanger to hpke.NewDHKEMPrivateKey. In this case, the resulting KEM private key will error out when Bytes is called.
I propose to remove the Bytes method from hpke.PrivateKey interface to avoid projects unintentionally building logic around a function that can't be correctly implemented by all keys.
The standard library only uses PrivateKey.Bytes for testing, so removing it should be safe. If someone really needs that, then it should still be possible to type-assert that a given private key implements interface { Bytes() []byte }.
Also, the private structs in the hpke package implementing the hpke.PrivateKey interface should not implement a Bytes method unless it can be proven that the key is not opaque to avoid callers assuming type-casting interface { Bytes() []byte } will always succeed.
Note that this wouldn't be a breaking change, as the hpke package is still not released (see #75300).
Having said this, I'm aware that I'm a bit late here, this comment should have gone into #75300 before the proposal being accepted. But better late than never.