going somewhere
This commit is contained in:
1 parent
6b3c99664c
commit
209af0d820
16 files changed
+549
-131
No files matched your search
@@ -1,6 +1,7 @@
|
||||
package helper
|
||||
|
||||
import (
|
||||
"crypto"
|
||||
"errors"
|
||||
"strings"
|
||||
)
|
||||
@@ -21,3 +22,29 @@ func JoinErrors(errs []error) error {
|
||||
}
|
||||
return JoinAsError(msgs)
|
||||
}
|
||||
|
||||
func GetHashFunctionByLowerCaseName(hashName string) (crypto.Hash, error) {
|
||||
switch hashName {
|
||||
case "md4":
|
||||
return crypto.MD4, nil
|
||||
case "md5":
|
||||
return crypto.MD5, nil
|
||||
case "sha1":
|
||||
return crypto.SHA1, nil
|
||||
case "sha224":
|
||||
return crypto.SHA224, nil
|
||||
case "sha256":
|
||||
return crypto.SHA256, nil
|
||||
case "sha384":
|
||||
return crypto.SHA384, nil
|
||||
case "sha512":
|
||||
return crypto.SHA512, nil
|
||||
case "md5sha1":
|
||||
return crypto.MD5SHA1, nil
|
||||
case "ripemd160":
|
||||
return crypto.RIPEMD160, nil
|
||||
default:
|
||||
return 0, errors.New("unknown lowercase hash " + hashName)
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package helper
|
||||
|
||||
import (
|
||||
"crypto"
|
||||
"errors"
|
||||
"testing"
|
||||
)
|
||||
@@ -36,3 +37,24 @@ func TestJoinErrors(t *testing.T) {
|
||||
t.Error("bad error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetHashFunctionByLowerCaseName(t *testing.T) {
|
||||
m := map[string]crypto.Hash{
|
||||
"md4": crypto.MD4,
|
||||
"md5": crypto.MD5,
|
||||
"sha1": crypto.SHA1,
|
||||
"sha224": crypto.SHA224,
|
||||
"sha256": crypto.SHA256,
|
||||
"sha384": crypto.SHA384,
|
||||
"sha512": crypto.SHA512,
|
||||
"md5sha1": crypto.MD5SHA1,
|
||||
"ripemd160": crypto.RIPEMD160,
|
||||
}
|
||||
for hashName, exptedHash := range m {
|
||||
if hash, err := GetHashFunctionByLowerCaseName(hashName); err != nil {
|
||||
t.Error(err)
|
||||
} else if hash != exptedHash {
|
||||
t.Error("bad hash found for ", hashName)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user