You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
658 B
Go
31 lines
658 B
Go
package in_toto
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
"crypto/sha512"
|
|
"hash"
|
|
)
|
|
|
|
/*
|
|
getHashMapping returns a mapping from hash algorithm to supported hash
|
|
interface.
|
|
*/
|
|
func getHashMapping() map[string]func() hash.Hash {
|
|
return map[string]func() hash.Hash{
|
|
"sha256": sha256.New,
|
|
"sha512": sha512.New,
|
|
"sha384": sha512.New384,
|
|
}
|
|
}
|
|
|
|
/*
|
|
hashToHex calculates the hash over data based on hash algorithm h.
|
|
*/
|
|
func hashToHex(h hash.Hash, data []byte) []byte {
|
|
h.Write(data)
|
|
// We need to use h.Sum(nil) here, because otherwise hash.Sum() appends
|
|
// the hash to the passed data. So instead of having only the hash
|
|
// we would get: "dataHASH"
|
|
return h.Sum(nil)
|
|
}
|