packwiz/core/hash.go
TheEpicBlock b5b9fd6810
Modrinth Support (#11)
Co-authored-by: comp500 <comp500@users.noreply.github.com>
2021-02-16 16:34:52 +00:00

28 lines
543 B
Go

package core
import (
"crypto/md5"
"crypto/sha1"
"crypto/sha256"
"crypto/sha512"
"errors"
"hash"
"strings"
)
// GetHashImpl gets an implementation of hash.Hash for the given hash type string
func GetHashImpl(hashType string) (hash.Hash, error) {
switch strings.ToLower(hashType) {
case "sha1":
return sha1.New(), nil
case "sha256":
return sha256.New(), nil
case "sha512":
return sha512.New(), nil
case "md5":
return md5.New(), nil
}
// TODO: implement murmur2
return nil, errors.New("hash implementation not found")
}