Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
GitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
crypto: Equal(PublicKey) bool methods leak to PrivateKey implementations #38190
Since golang.org/cl/225460 (#21704), the following code compiles but prints an unexpected result:
This is due to PrivateKey embedding
This causes difficult to debug issues with tools like go-cmp, as it looks for an
Nice bug. If a particular PrivateKey embeds PublicKey, then any time you implement PublicKey.M you should also implement PrivateKey.M to do the private key-specific behavior, whatever that is. Probably there should be a (non-doc) comment in the sources anywhere we do this, alerting people to the gotcha.
Embedding the PublicKey instead of calling the field Public was probably a mistake, but too late now.
Yeah, using embedding was probably a mistake in hindsight, even if I see how it made sense since the PublicKey fields are arguably PrivateKey fields as well.
Question about Equal semantics: would you expect two equivalent PrivateKeys to return true or false if one has Precomputed set and the other doesn't? I think false?
(I was hoping to avoid the question by not implementing Equal on the private keys, but yes, too late.)
Naively I'd assume
(It could be somewhat confusing to consider it given ECDSA and EdDSA have no analog.)