1
0
Fork 0
mirror of https://github.com/vbatts/dedupe-linker.git synced 2024-12-27 09:06:31 +00:00
dedupe-linker/cryptomap/crypto.go
Vincent Batts e9488b60ff cryptomap: discoverable mapping and defaults
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2016-09-13 11:10:24 -04:00

38 lines
925 B
Go

package cryptomap
import (
"crypto"
"log"
"strings"
// Importing all the currently supported hashes
_ "crypto/md5"
_ "crypto/sha1"
_ "crypto/sha256"
_ "crypto/sha512"
)
// DefaultCipher is the crypto cipher default used if none is specified or
// specified is unknown.
var DefaultCipher = "sha1"
// Ciphers is the known set of mappings for string to crypto.Hash
// use an init() to add custom hash ciphers
var Ciphers = map[string]crypto.Hash{
"md5": crypto.MD5,
"sha1": crypto.SHA1,
"sha224": crypto.SHA224,
"sha256": crypto.SHA256,
"sha384": crypto.SHA384,
"sha512": crypto.SHA512,
}
// DetermineHash takes a generic string, like "sha1" and returns the
// corresponding crypto.Hash
func DetermineHash(str string) (h crypto.Hash) {
if h, ok := Ciphers[strings.ToLower(str)]; ok {
return h
}
log.Printf("WARNING: unknown cipher %q. using %q", str, DefaultCipher)
return Ciphers[DefaultCipher]
}