File tree 4 files changed +26
-0
lines changed
4 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ import (
14
14
"crypto/rsa"
15
15
"crypto/sha1"
16
16
"crypto/sha256"
17
+ "crypto/sha512"
17
18
"crypto/x509"
18
19
"crypto/x509/pkix"
19
20
"encoding/asn1"
@@ -36,6 +37,11 @@ import (
36
37
"golang.org/x/crypto/scrypt"
37
38
)
38
39
40
+ func sha512sum (input string ) string {
41
+ hash := sha512 .Sum512 ([]byte (input ))
42
+ return hex .EncodeToString (hash [:])
43
+ }
44
+
39
45
func sha256sum (input string ) string {
40
46
hash := sha256 .Sum256 ([]byte (input ))
41
47
return hex .EncodeToString (hash [:])
Original file line number Diff line number Diff line change @@ -26,12 +26,20 @@ var (
26
26
}
27
27
)
28
28
29
+ func TestSha512Sum (t * testing.T ) {
30
+ tpl := `{{"abc" | sha512sum}}`
31
+ if err := runt (tpl , "ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f" ); err != nil {
32
+ t .Error (err )
33
+ }
34
+ }
35
+
29
36
func TestSha256Sum (t * testing.T ) {
30
37
tpl := `{{"abc" | sha256sum}}`
31
38
if err := runt (tpl , "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad" ); err != nil {
32
39
t .Error (err )
33
40
}
34
41
}
42
+
35
43
func TestSha1Sum (t * testing.T ) {
36
44
tpl := `{{"abc" | sha1sum}}`
37
45
if err := runt (tpl , "a9993e364706816aba3e25717850c26c9cd0d89d" ); err != nil {
Original file line number Diff line number Diff line change @@ -21,6 +21,17 @@ sha256sum "Hello world!"
21
21
The above will compute the SHA 256 sum in an "ASCII armored" format that is
22
22
safe to print.
23
23
24
+ ## sha512sum
25
+
26
+ The ` sha512sum ` function receives a string, and computes it's SHA512 digest.
27
+
28
+ ```
29
+ sha512sum "Hello world!"
30
+ ```
31
+
32
+ The above will compute the SHA 512 sum in an "ASCII armored" format that is
33
+ safe to print.
34
+
24
35
## adler32sum
25
36
26
37
The ` adler32sum ` function receives a string, and computes its Adler-32 checksum.
Original file line number Diff line number Diff line change @@ -161,6 +161,7 @@ var genericMap = map[string]interface{}{
161
161
"plural" : plural ,
162
162
"sha1sum" : sha1sum ,
163
163
"sha256sum" : sha256sum ,
164
+ "sha512sum" : sha512sum ,
164
165
"adler32sum" : adler32sum ,
165
166
"toString" : strval ,
166
167
You can’t perform that action at this time.
0 commit comments