check.go 487 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
package sign

import (
	"bytes"
	"crypto/sha512"
	"encoding/hex"
	"io/ioutil"
)

// CheckContractHash computes the hash of the provided file and compares it to the expected one.
func CheckContractHash(filename string, expectedHash string) (ok bool, err error) {
	data, err := ioutil.ReadFile(filename)
	if err != nil {
		return
	}

	expected, err := hex.DecodeString(expectedHash)
	if err != nil {
		return
	}

	hash := sha512.Sum512(data)
	ok = bytes.Equal(expected, hash[:])
	return
}