Documentation
¶
Overview ¶
Package integrity parses Subresource Integrity metadata and verifies streams against cryptographic digests.
It supports SHA-256, SHA-384, and SHA-512 without depending on HTTP, storage, or package-manager types.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Digest ¶
type Digest struct {
// contains filtered or unexported fields
}
Digest is an immutable algorithm and digest-byte pair.
Use ParseHex or ParseSRI to construct a Digest. Bytes returns a copy of the stored bytes.
func (Digest) Equal ¶
Equal reports whether two digests use the same algorithm and contain the same raw bytes. The byte comparison takes constant time for equal-length values.
type ErrIncomplete ¶
type ErrIncomplete struct{}
ErrIncomplete reports that verification was requested before the reader observed EOF.
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader calculates requested digests as bytes pass through it. Bytes remain unverified until a completed Result passes Verify.
Example ¶
package main
import (
"fmt"
"io"
"strings"
"github.com/git-pkgs/integrity"
)
func main() {
expected, err := integrity.ParseSRI("sha256-LPJNul+wow4m6DsqxbninhsWHlwfp0JecwQzYpOLmCQ=")
if err != nil {
panic(err)
}
reader, err := integrity.NewReader(strings.NewReader("hello"), integrity.SHA256)
if err != nil {
panic(err)
}
if _, err := io.Copy(io.Discard, reader); err != nil {
panic(err)
}
result := reader.Result()
fmt.Println(result.Bytes, result.Complete)
fmt.Println(result.Verify(expected) == nil)
}
Output: 5 true true
type SRI ¶
type SRI []Digest
SRI is a Subresource Integrity metadata list.
func ParseSRI ¶
ParseSRI parses a whitespace-separated Subresource Integrity metadata list. It accepts standard and URL-safe base64 with optional padding and ignores options, which SRI currently leaves undefined.
Example ¶
package main
import (
"fmt"
"github.com/git-pkgs/integrity"
)
func main() {
metadata, err := integrity.ParseSRI("sha256-LPJNul+wow4m6DsqxbninhsWHlwfp0JecwQzYpOLmCQ=")
if err != nil {
panic(err)
}
fmt.Println(metadata[0].Algorithm())
fmt.Println(metadata[0].Hex())
}
Output: sha256 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824