1 package in_toto 2 3 import ( 4 "crypto/sha256" 5 "crypto/sha512" 6 "hash" 7 ) 8 9 /* 10 getHashMapping returns a mapping from hash algorithm to supported hash 11 interface. 12 */ 13 func getHashMapping() map[string]func() hash.Hash { 14 return map[string]func() hash.Hash{ 15 "sha256": sha256.New, 16 "sha512": sha512.New, 17 "sha384": sha512.New384, 18 } 19 } 20 21 /* 22 hashToHex calculates the hash over data based on hash algorithm h. 23 */ 24 func hashToHex(h hash.Hash, data []byte) []byte { 25 h.Write(data) 26 // We need to use h.Sum(nil) here, because otherwise hash.Sum() appends 27 // the hash to the passed data. So instead of having only the hash 28 // we would get: "dataHASH" 29 return h.Sum(nil) 30 } 31