// Integrity string has the pattern of: hashAlgorithms-digest.
// Return the hashAlgorithm and transform the diegest to the actual sha.
Integrity string has the pattern of: hashAlgorithms-digest.
Return the hashAlgorithm and transform the diegest to the actual sha.
// Integrity string has the pattern of : hashAlgorithms - digest . // Return the hashAlgorithm and transform the diegest to the actual sha .
func integrityToSha(integrity string) (hashAlgorithm string, sha string, err error) {
	data := strings.SplitN(integrity, "-", 2)
	if len(data) != 2 {
		return "", "", errors.New("the integrity '" + integrity + "' has bad format (valid format is HashAlgorithms-Hash)")
	}
	var integrityDigest string
	hashAlgorithm, integrityDigest = data[0], data[1]
	decoded, err := base64.StdEncoding.DecodeString(integrityDigest)
	if err != nil {
		err = errors.New("failed to decode integrity hash. Error: " + err.Error())
		return
	}
	sha = hex.EncodeToString(decoded)
	return
}
func integrityToSha ( integrity string ) ( hashAlgorithm string , sha string , err error ) { data := strings . SplitN ( integrity , " " , 2 ) if len ( data ) != 2 { return " " , " " , errors . New ( " " + integrity + " " ) } var integrityDigest string hashAlgorithm , integrityDigest = data [ 0 ] , data [ 1 ] decoded , err := base64 . StdEncoding . DecodeString ( integrityDigest ) if err != nil { err = errors . New ( " " + err . Error ( ) ) return } sha = hex . EncodeToString ( decoded ) return }
Integrity string has the pattern of: hashAlgorithms-digest.
Integrity string has the pattern of : hashAlgorithms - digest .