func (m PackageMeta) HashV1() (Hash, error) {
	return PackageHashV1(m.Location)
}
HashV1 computes a hash of the contents of the package at the location
associated with the receiver using hash algorithm 1.

The hash covers the paths to files in the directory and the contents of
those files. It does not cover other metadata about the files, such as
permissions.

HashV1 can be used only with the two local package location types
PackageLocalDir and PackageLocalArchive, because it needs to access the
contents of the indicated package in order to compute the hash. If given
a non-local location this function will always return an error.
package getproviders
import (
	"crypto/sha256"
	"fmt"
	"io"
	"os"
	"path/filepath"
	"strings"
	"golang.org/x/mod/sumdb/dirhash"
)
type Hash string
const NilHash = Hash("")
func ParseHash(s string) (Hash, error) {
	colon := strings.Index(s, ":")
	if colon < 1 {  
		return NilHash, fmt.Errorf("hash string must start with a scheme keyword followed by a colon")
	}
	return Hash(s), nil
}
func MustParseHash(s string) Hash {
	hash, err := ParseHash(s)
	if err != nil {
		panic(err.Error())
	}
	return hash
}
func (h Hash) Scheme() HashScheme {
	colon := strings.Index(string(h), ":")
	if colon < 0 {
		panic(fmt.Sprintf("invalid hash string %q", h))
	}
	return HashScheme(h[:colon+1])
}
func (h Hash) HasScheme(want HashScheme) bool {
	return h.Scheme() == want
}
func (h Hash) Value() string {
	colon := strings.Index(string(h), ":")
	if colon < 0 {
		panic(fmt.Sprintf("invalid hash string %q", h))
	}
	return string(h[colon+1:])
}
func (h Hash) String() string {
	return string(h)
}
func (h Hash) GoString() string {
	if h == NilHash {
		return "getproviders.NilHash"
	}
	switch scheme := h.Scheme(); scheme {
	case HashScheme1:
		return fmt.Sprintf("getproviders.HashScheme1.New(%q)", h.Value())
	case HashSchemeZip:
		return fmt.Sprintf("getproviders.HashSchemeZip.New(%q)", h.Value())
	default:
		return fmt.Sprintf("getproviders.HashScheme(%q).New(%q)", scheme, h.Value())
	}
}
type HashScheme string
const (
	HashScheme1 HashScheme = HashScheme("h1:")
	HashSchemeZip HashScheme = HashScheme("zh:")
)
func (hs HashScheme) New(value string) Hash {
	return Hash(string(hs) + value)
}
func PackageHash(loc PackageLocation) (Hash, error) {
	return PackageHashV1(loc)
}
func PackageMatchesHash(loc PackageLocation, want Hash) (bool, error) {
	switch want.Scheme() {
	case HashScheme1:
		got, err := PackageHashV1(loc)
		if err != nil {
			return false, err
		}
		return got == want, nil
	case HashSchemeZip:
		archiveLoc, ok := loc.(PackageLocalArchive)
		if !ok {
			return false, fmt.Errorf(`ziphash scheme ("zh:" prefix) is not supported for unpacked provider packages`)
		}
		got, err := PackageHashLegacyZipSHA(archiveLoc)
		if err != nil {
			return false, err
		}
		return got == want, nil
	default:
		return false, fmt.Errorf("unsupported hash format (this may require a newer version of Terraform)")
	}
}
func PackageMatchesAnyHash(loc PackageLocation, allowed []Hash) (bool, error) {
	var v1Hash, zipHash Hash
	for _, want := range allowed {
		switch want.Scheme() {
		case HashScheme1:
			if v1Hash == NilHash {
				got, err := PackageHashV1(loc)
				if err != nil {
					return false, err
				}
				v1Hash = got
			}
			if v1Hash == want {
				return true, nil
			}
		case HashSchemeZip:
			archiveLoc, ok := loc.(PackageLocalArchive)
			if !ok {
				continue
			}
			if zipHash == NilHash {
				got, err := PackageHashLegacyZipSHA(archiveLoc)
				if err != nil {
					return false, err
				}
				zipHash = got
			}
			if zipHash == want {
				return true, nil
			}
		default:
			continue
		}
	}
	return false, nil
}
func PreferredHashes(given []Hash) []Hash {
	var ret []Hash
	for _, hash := range given {
		switch hash.Scheme() {
		case HashScheme1, HashSchemeZip:
			ret = append(ret, hash)
		}
	}
	return ret
}
func PackageHashLegacyZipSHA(loc PackageLocalArchive) (Hash, error) {
	archivePath, err := filepath.EvalSymlinks(string(loc))
	if err != nil {
		return "", err
	}
	f, err := os.Open(archivePath)
	if err != nil {
		return "", err
	}
	defer f.Close()
	h := sha256.New()
	_, err = io.Copy(h, f)
	if err != nil {
		return "", err
	}
	gotHash := h.Sum(nil)
	return HashSchemeZip.New(fmt.Sprintf("%x", gotHash)), nil
}
func HashLegacyZipSHAFromSHA(sum [sha256.Size]byte) Hash {
	return HashSchemeZip.New(fmt.Sprintf("%x", sum[:]))
}
func PackageHashV1(loc PackageLocation) (Hash, error) {
	switch loc := loc.(type) {
	case PackageLocalDir:
		packageDir, err := filepath.EvalSymlinks(string(loc))
		if err != nil {
			return "", err
		}
		s, err := dirhash.HashDir(packageDir, "", dirhash.Hash1)
		return Hash(s), err
	case PackageLocalArchive:
		archivePath, err := filepath.EvalSymlinks(string(loc))
		if err != nil {
			return "", err
		}
		s, err := dirhash.HashZip(archivePath, dirhash.Hash1)
		return Hash(s), err
	default:
		return "", fmt.Errorf("cannot hash package at %s", loc.String())
	}
}
func (m PackageMeta) Hash() (Hash, error) {
	return PackageHash(m.Location)
}
func (m PackageMeta) MatchesHash(want Hash) (bool, error) {
	return PackageMatchesHash(m.Location, want)
}
func (m PackageMeta) MatchesAnyHash(acceptable []Hash) (bool, error) {
	return PackageMatchesAnyHash(m.Location, acceptable)
}