Skip to content

Commit 9dcd6b3

Browse files
committed
crypto: implement Hash.String
Fixes #33430 Change-Id: I323323b3136dd7b408005c3bb5ea05e3b566bd38 Reviewed-on: https://go-review.googlesource.com/c/go/+/224937 Run-TryBot: Katie Hockman <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Filippo Valsorda <[email protected]>
1 parent ade9886 commit 9dcd6b3

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

Diff for: src/crypto/crypto.go

+45
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,51 @@ func (h Hash) HashFunc() Hash {
2020
return h
2121
}
2222

23+
func (h Hash) String() string {
24+
switch h {
25+
case MD4:
26+
return "MD4"
27+
case MD5:
28+
return "MD5"
29+
case SHA1:
30+
return "SHA-1"
31+
case SHA224:
32+
return "SHA-224"
33+
case SHA256:
34+
return "SHA-256"
35+
case SHA384:
36+
return "SHA-384"
37+
case SHA512:
38+
return "SHA-512"
39+
case MD5SHA1:
40+
return "MD5+SHA1"
41+
case RIPEMD160:
42+
return "RIPEMD-160"
43+
case SHA3_224:
44+
return "SHA3-224"
45+
case SHA3_256:
46+
return "SHA3-256"
47+
case SHA3_384:
48+
return "SHA3-384"
49+
case SHA3_512:
50+
return "SHA3-512"
51+
case SHA512_224:
52+
return "SHA-512/224"
53+
case SHA512_256:
54+
return "SHA-512/256"
55+
case BLAKE2s_256:
56+
return "BLAKE2s-256"
57+
case BLAKE2b_256:
58+
return "BLAKE2b-256"
59+
case BLAKE2b_384:
60+
return "BLAKE2b-384"
61+
case BLAKE2b_512:
62+
return "BLAKE2b-512"
63+
default:
64+
return "unknown hash value " + strconv.Itoa(int(h))
65+
}
66+
}
67+
2368
const (
2469
MD4 Hash = 1 + iota // import golang.org/x/crypto/md4
2570
MD5 // import crypto/md5

0 commit comments

Comments
 (0)