Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type DigestVerifier ¶
type DigestVerifier interface { Hash // SumAndVerify calls [hash.Hash.Sum] passing b and matches the resulting slice against the original set of // candidates. // // SumAndVerify returns true if and only if the hash matches at least one match candidate. SumAndVerify(b []byte) bool }
DigestVerifier extends Hash with SumAndVerify to verify the hash against a set of precomputed digests.
Using Subresource Integrity allow for multiple digests to be given as match candidates. As a result, NewVerifier supports being given several precomputed digests to match against. If the precomputed digests use different hash functions, the function of the first digest will be the one that is used as the primary Hash function.
func NewVerifier ¶
func NewVerifier(primary string, additional ...string) (DigestVerifier, []string)
NewVerifier returns a new DigestVerifier that will match against the given set of digest candidates.
The hash function of the first (primary) digest will be used as the primary hash function. Digests with unknown hash function are returned as the second value. If all digests are unrecognised, a nil DigestVerifier is returned. Call Register if you are expecting custom hash functions.
type Hash ¶
type Hash interface { hash.Hash // Name returns the name of the hash function. Name() string // SumToString calls [hash.Hash.Sum] passing b and encodes the returned slice as a string prefixed with the hash // name. // // See [Subresource Integrity] for example usages of such strings in <script> and <link> tags such as // <script // src="https://example.com/example-framework.js" // integrity="sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC" // crossorigin="anonymous"></script> // // [Subresource Integrity]: https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity SumToString(b []byte) string }
Hash extends hash.Hash with SumToString to generate the base64-encoded cryptographic hash that can be used to verify Subresource Integrity.
func NewSha224 ¶
func NewSha224() Hash
NewSha224 returns a new Hash using sha224 as the hash function.
func NewSha256 ¶
func NewSha256() Hash
NewSha256 returns a new Hash using sha256 as the hash function.