mirror of
https://github.com/vbatts/dedupe-linker.git
synced 2025-01-13 17:20:07 +00:00
cryptomap: discoverable mapping and defaults
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
parent
18ae791748
commit
e9488b60ff
2 changed files with 18 additions and 22 deletions
|
@ -12,31 +12,27 @@ import (
|
|||
_ "crypto/sha512"
|
||||
)
|
||||
|
||||
var knownCiphers = map[string]crypto.Hash{
|
||||
"md5": crypto.MD5,
|
||||
// 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) {
|
||||
// TODO make these strings discoverable, like a public variable
|
||||
switch strings.ToLower(str) {
|
||||
case "md5":
|
||||
h = crypto.MD5
|
||||
case "sha1":
|
||||
h = crypto.SHA1
|
||||
case "sha224":
|
||||
h = crypto.SHA224
|
||||
case "sha256":
|
||||
h = crypto.SHA256
|
||||
case "sha384":
|
||||
h = crypto.SHA384
|
||||
case "sha512":
|
||||
h = crypto.SHA512
|
||||
default:
|
||||
log.Printf("WARNING: unknown cipher %q. using 'sha1'", str)
|
||||
h = crypto.SHA1
|
||||
if h, ok := Ciphers[strings.ToLower(str)]; ok {
|
||||
return h
|
||||
}
|
||||
|
||||
return h
|
||||
log.Printf("WARNING: unknown cipher %q. using %q", str, DefaultCipher)
|
||||
return Ciphers[DefaultCipher]
|
||||
}
|
||||
|
|
2
main.go
2
main.go
|
@ -17,7 +17,7 @@ var (
|
|||
varBaseDir = filepath.Join(os.Getenv("HOME"), ".dedupe-linker/")
|
||||
|
||||
flVarBase = flag.String("b", varBaseDir, "base directory where files are duplicated")
|
||||
flCipher = flag.String("c", "sha1", "block cipher to use (sha1, or sha256)")
|
||||
flCipher = flag.String("c", cryptomap.DefaultCipher, "block cipher to use (sha1, or sha256)")
|
||||
flWorkers = flag.Int("w", 2, "workers to do summing")
|
||||
flNoop = flag.Bool("noop", false, "don't do any moving or linking")
|
||||
flDebug = flag.Bool("debug", false, "enable debug output")
|
||||
|
|
Loading…
Reference in a new issue