mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 13:21:00 +02:00
Use hex.EncodeToString to encode to hex
This commit is contained in:
parent
833668e8f2
commit
f9f32a4b0e
2 changed files with 9 additions and 1 deletions
|
@ -6,6 +6,7 @@ import (
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
@ -89,7 +90,7 @@ func XXHashFile(fname string) (hash256 []byte, err error) {
|
||||||
func SHA256(s string) string {
|
func SHA256(s string) string {
|
||||||
sha := sha256.New()
|
sha := sha256.New()
|
||||||
sha.Write([]byte(s))
|
sha.Write([]byte(s))
|
||||||
return fmt.Sprintf("%x", sha.Sum(nil))
|
return hex.EncodeToString(sha.Sum(nil))
|
||||||
}
|
}
|
||||||
|
|
||||||
// PublicIP returns public ip address
|
// PublicIP returns public ip address
|
||||||
|
|
|
@ -40,6 +40,13 @@ func BenchmarkImoHash(b *testing.B) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func BenchmarkSha256(b *testing.B) {
|
||||||
|
b.ResetTimer()
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
SHA256("hello,world")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestExists(t *testing.T) {
|
func TestExists(t *testing.T) {
|
||||||
bigFile()
|
bigFile()
|
||||||
defer os.Remove("bigfile.test")
|
defer os.Remove("bigfile.test")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue