-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
crypto: implement Hash.String #33430
Comments
@Ma124 you mention what you want to do, but don’t explain why you or others would need this functionality. Could you elaborate a bit more on that in your proposal? What problem does this solve? |
The Stringer would be useful for all kinds of logging purposes and I personally see no drawback. The maxHash would be useful every time you need to show something non-go the options there are for hashing. So for example every time a user can choose a hashing algorithm in a CLI or GUI or maybe you list available hashing options to a program written in another language. And your duplicating code every time when you use the alternative: importing the package and putting it into a map. So if for example one of the choices becomes insecure you need to remove the import and the map entry and if you forget one of them you've got either an unused import which cannot be detected by the compiler or you've got a panic. So I think there are no reasons against Stringer and very few drawbacks of a renamed maxHash. |
I'm not against implementing crypto.Hash.String for logging and the like. Since hash functions need to be imported anyway to be available, I don't see the advantage of maxHash, and it's leaking an internal detail. Also, I don't want to encourage "pick your own hash" designs. The set of available hashes in a design should be ideally of size 1, and anyway clearly specified, not "whatever Go supports". |
Added to proposal minutes, seems headed for likely accept. |
Based on the discussion above, this seems like a likely accept. |
No change in consensus, so accepted. |
Change https://golang.org/cl/224937 mentions this issue: |
@katiehockman Hello! It looks like the documentation is missing for this new API: https://tip.golang.org/pkg/crypto/#Hash.String |
@toothrot Is it common to document trivial |
I just did a quick look through several crypto and x/crypto packages, and it differs (sometimes even within the same package). From what I'm seeing, It isn't documented if its self explanatory, e.g. https://pkg.go.dev/crypto/x509?tab=doc#PublicKeyAlgorithm.String and https://pkg.go.dev/golang.org/x/crypto/ssh?tab=doc#RejectionReason.String. In this case, I think |
Right, sorry for the false alarm. I was merely auditing all new APIs for #39489, and following up on ones that did not have documentation. |
No problem! Thanks for your diligence. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I wanted to iterate all builtin hash functions by doing something like the following:
What did you expect to see?
An exported
crypto.maxHash
andcrypto.Hash
implementing thefmt.Stringer
interface.The text was updated successfully, but these errors were encountered: