// GetHmacSha256 returns the HMAC-Sha256 hash of the header
482414
func (h *DBHeader) GetHmacSha256(hmacKey []byte) (ret [32]byte) {
	hash := hmac.New(sha256.New, hmacKey)
	hash.Write(h.RawData)
	copy(ret[:32], hash.Sum(nil)[:32])
	return
}
1088373
func DefaultHMAC(key, buf []byte) (HMAC, error) {
	mac := hmac.New(DefaultHashNew, key)
	mac.Write(buf)
	h, err := HashFromRaw(DefaultHashType, mac.Sum(nil))
	if err != nil {
		return HMAC{}, err
	}
	return HMAC{h}, nil
}
720161
func (u *UniterAPI) CharmArchiveSha256(args params.CharmURLs) (params.StringResults, error) {
	result := params.StringResults{
		Results: make([]params.StringResult, len(args.URLs)),
	}
	for i, arg := range args.URLs {
		curl, err := charm.ParseURL(arg.URL)
		if err != nil {
			err = common.ErrPerm
		} else {
			var sch *state.Charm
			sch, err = u.st.Charm(curl)
			if errors.IsNotFound(err) {
				err = common.ErrPerm
			}
			if err == nil {
				result.Results[i].Result = sch.BundleSha256()
			}
		}
		result.Results[i].Error = common.ServerError(err)
	}
	return result, nil
}
976999
func GetHeader(bytes []byte) (*common.Header, error) {
	hdr := &common.Header{}
	err := proto.Unmarshal(bytes, hdr)
	return hdr, errors.Wrap(err, "error unmarshaling Header")
}
460474
func (hc *HeaderChain) GetHeaderByHash(hash common.Hash) *types.Header {
	number := hc.GetBlockNumber(hash)
	if number == nil {
		return nil
	}
	return hc.GetHeader(hash, *number)
}
190459
func (s *StatusEvent) GetSHA() string {
	if s == nil || s.SHA == nil {
		return ""
	}
	return *s.SHA
}
1188809
func DoubleHashB(b []byte) []byte {
	first := sha256.Sum256(b)
	second := sha256.Sum256(first[:])
	return second[:]
}
1241997
func getContentSha256Cksum(r *http.Request, stype serviceType) string {
	if stype == serviceSTS {
		payload, err := ioutil.ReadAll(r.Body)
		if err != nil {
			logger.CriticalIf(context.Background(), err)
		}
		sum256 := sha256.New()
		sum256.Write(payload)
		r.Body = ioutil.NopCloser(bytes.NewReader(payload))
		return hex.EncodeToString(sum256.Sum(nil))
	}

	var (
		defaultSha256Cksum string
		v                  []string
		ok                 bool
	)

	// For a presigned request we look at the query param for sha256.
	if isRequestPresignedSignatureV4(r) {
		// X-Amz-Content-Sha256, if not set in presigned requests, checksum
		// will default to 'UNSIGNED-PAYLOAD'.
		defaultSha256Cksum = unsignedPayload
		v, ok = r.URL.Query()["X-Amz-Content-Sha256"]
		if !ok {
			v, ok = r.Header["X-Amz-Content-Sha256"]
		}
	} else {
		// X-Amz-Content-Sha256, if not set in signed requests, checksum
		// will default to sha256([]byte("")).
		defaultSha256Cksum = emptySHA256
		v, ok = r.Header["X-Amz-Content-Sha256"]
	}

	// We found 'X-Amz-Content-Sha256' return the captured value.
	if ok {
		return v[0]
	}

	// We couldn't find 'X-Amz-Content-Sha256'.
	return defaultSha256Cksum
}
829814
func NewSha256(r io.Reader) *Sha256Reader {
	s := new(Sha256Reader)
	s.hashReader = newHashReader(sha256.New(), r)
	return s
}
56428
func getSubjectInfoHash(cert *x509.Certificate, issuer bool) []byte {
	if cert == nil {
		return nil
	}

	var subject []byte
	if issuer {
		subject = cert.RawIssuer
	} else {
		subject = cert.RawSubject
	}

	digest := sha256.Sum256(subject)
	return digest[:]
}
190806
func Sha256(str cty.Value) (cty.Value, error) {
	return Sha256Func.Call([]cty.Value{str})
}
279117
func Keccak256(data ...[]byte) []byte {
	d := sha3.NewLegacyKeccak256()
	for _, b := range data {
		d.Write(b)
	}
	return d.Sum(nil)
}
345780
func NewHmacAuth(hash crypto.Hash, key []byte, header string,
	headers []string) HmacAuth {
	if hash.Available() == false {
		var name string
		var supported bool
		if name, supported = algorithmName[hash]; !supported {
			name = "#" + strconv.Itoa(int(hash))
		}
		panic("hmacauth: hash algorithm " + name + " is unavailable")
	}
	canonicalHeaders := make([]string, len(headers))
	for i, h := range headers {
		canonicalHeaders[i] = http.CanonicalHeaderKey(h)
	}
	return &hmacAuth{hash, key, header, canonicalHeaders}
}
893071
func (r *RepositoryCommit) GetSHA() string {
	if r == nil || r.SHA == nil {
		return ""
	}
	return *r.SHA
}
698212
func (p *PullRequestMergeResult) GetSHA() string {
	if p == nil || p.SHA == nil {
		return ""
	}
	return *p.SHA
}
1120903
func GetHash(namespace string) crypto.Hash {
	if strings.HasPrefix(namespace, "sha256-") {
		return crypto.SHA256
	}
	if strings.HasPrefix(namespace, "sha512-") {
		return crypto.SHA512
	}
	return crypto.SHA1
}
191113
func (s *Sha256Reader) Sha256() string {
	return hex.EncodeToString(s.hash.Sum(nil))
}