Skip to content

proposal: crypto/hpke: remove Bytes method from PrivateKey #76674

@qmuntal

Description

@qmuntal

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.

@FiloSottile

Metadata

Metadata

Assignees

No one assigned

    Labels

    LibraryProposalIssues describing a requested change to the Go standard library or x/ libraries, but not to a toolProposalProposal-CryptoProposal related to crypto packages or other security issuesokay-after-rc1Used by release team to mark a release-blocker issue as okay to resolve either before or after rc1release-blocker

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions