-
Notifications
You must be signed in to change notification settings - Fork 18k
proposal: concrete interfaces for crypto.PublicKey and crypto.PrivateKey #30140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Interfaces can't be changed in Go 1 due to the Go 1 compatibility promise. |
Thanks for the quick reply. Before you tag this as Go2 only: First PointAdding It makes them Second PointAlthough you could technically say that changing the interface breaks compatibility, it's actually just moving run time errors to compile time errors. However, I'm willing to concede that some weirdo, somewhere, has used That being said, the bigger issue is the first point. It's trivial to add an interface. |
Technicalities matter. We can't make this change in Go 1. |
Forget the second point entirely. How about the 1st point? |
@FiloSottile What do you think of the idea of adding a standard method to every |
Ping @FiloSottile |
I'm ok with making I had never heard of a thumbprint, and I don't want to touch JWT specs if at all possible. I'm not opposed to adding a common method to all public keys, but I can't think of a good one. |
How about Fingerprint then? That's also well standardized, a la ssh. |
From that it doesn't look like That proposal allows for an better workaround for types that optionally support it, but it doesn't solve the problem that I'd like this to be re-opened as a non-duplicate. |
My understanding is that by having the go version in Including |
We haven't yet used the module language version to change the standard library, so we don't know yet what the process would be, but changing an interface like this would not have a clean upgrade path because of third-party implementations of PrivateKey and PublicKey that would break.
|
I don't understand. How could anything in the There's nothing to implement. The interface is empty and not usable. Unless there's some sort of private type casting in the standard library code (which I haven't dug around for), there is no way to use a 3rd party implementation with the standard library. At the very least there is no documented way to do that. |
bump ^^ I'm open to that there's a use case that I'm unfamiliar with or don't properly understand and I'd like to know how it would be possible for 3rd party implementations to exist (and to break). |
One example that would break if you just added a method to I'm not saying it's the most elegant or correct way to handle a use-case like this. But there is historical precedent. |
Currently
crypto.PublicKey
andcrypto.PrivateKey
are empty interfaces.This has bitten me a number of times because errors that could easily be caught by tooling or at compile time become runtime errors (sometimes very confusing ones).
It appears that all Private Keys in the crypto package include
PublicKey
orPublic() crypto.PublicKey
. I assume that, by their very nature, any future invention of asymmetric keys will include the Public Key as part of the definition of the Private Key.There's also a well-known and intuitive standard way to compute a key Thumbprint that would work on any existing asymmetric keys and any future asymmetric keys. I believe there are also one or more well-known ways to compute a Fingerprint (SSH, among others), but perhaps Thumbprint is more distinct in that there is only one such specification (as far as I know).
I propose that
crypto.PrivateKey
be changed as follows:And that
crypto.PublicKey
likewise change to something like this:The text was updated successfully, but these errors were encountered: