Skip to content
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

proposal: crypto: crypto.Hash implement fmt.Stringer and export crypto.maxHash #33430

Open
Ma124 opened this issue Aug 2, 2019 · 3 comments

Comments

@Ma124
Copy link

commented Aug 2, 2019

What version of Go are you using (go version)?

$ go version
go version go1.12.1 linux/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/ma_124/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/ma_124/.go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build821474858=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I wanted to iterate all builtin hash functions by doing something like the following:

var algs map[string]crypto.Hash

var h crypto.Hash
for ; h < crypto.maxHash; h++ {
    if h.Available() {
        algs[h.String()] = h
    }
}

What did you expect to see?

An exported crypto.maxHash and crypto.Hash implementing the fmt.Stringer interface.

@odeke-em odeke-em changed the title crypto: crypto.Hash implement fmt.Stringer and export crypto.maxHash proposal: crypto: crypto.Hash implement fmt.Stringer and export crypto.maxHash Aug 3, 2019

@gopherbot gopherbot added this to the Proposal milestone Aug 3, 2019

@gopherbot gopherbot added the Proposal label Aug 3, 2019

@andybons

This comment has been minimized.

Copy link
Member

commented Aug 6, 2019

@andybons

This comment has been minimized.

Copy link
Member

commented Aug 6, 2019

@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?

@Ma124

This comment has been minimized.

Copy link
Author

commented Aug 9, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.