Ejemplo n.º 1
0
// SHA256Equal checks if sha256 checksum of the file is the same as the one passed in as paramter
// It returns error if the provided file can't be opened
func SHA256Equal(f Filer, sum string) error {
	return withFileReader(f, func(r io.Reader) error {
		sha256sum, err := utils.HashSum("sha256", r)
		if err != nil {
			return err
		}
		if sha256sum == sum {
			return nil
		}
		return fmt.Errorf("Expected sha256 sum: %s Calculated sum: %s", sum, sha256sum)
	})
}
Ejemplo n.º 2
0
// MD5Equal checks if md5 checksum of the file is the same as the one passed in as paramter
// It returns error if the provided file can't be opened
func MD5Equal(f Filer, sum string) error {
	return withFileReader(f, func(r io.Reader) error {
		md5sum, err := utils.HashSum("md5", r)
		if err != nil {
			return err
		}
		if md5sum == sum {
			return nil
		}
		return fmt.Errorf("Expected md5 sum: %s Calculated sum: %s", sum, md5sum)
	})
}