integrity

package
v0.0.0-...-dbe7a22 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 29, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

An implementation of the Subresource Integrity W3C recommendation (http://www.w3.org/TR/SRI/)

Index

Constants

This section is empty.

Variables

View Source
var ErrBadIntegrity = errors.New("bad integrity metadata")

Functions

func Check

func Check(r io.Reader, integrity string) (bool, error)

Checks whether the contents of the reader matches the given integrity. This is simply a convenience wrapper around NewChecker and its methods.

func Generate

func Generate(algorithm string, bytes []byte) string

Generate generates a Subresource Integrity metadata from the given algorithm and byte array. Unrecognized or deprecated algorithms yield an empty string.

func MustGenerate

func MustGenerate(algorithm string, bytes []byte) string

MustGenerate behaves like Generate, except that an unrecognized or deprecated algortihm causes a panic.

Types

type Checker

type Checker []subChecker

func NewChecker

func NewChecker(integrity string) (Checker, error)

NewChecker creates a Checker from the given integrity specification, following the format of "integrity metadata" as specified by https://www.w3.org/TR/SRI/#the-integrity-attribute

func (Checker) Check

func (c Checker) Check() bool

Check returns whether the data written so far (with Write) matches the original integrity metadata.

func (Checker) Reset

func (c Checker) Reset()

Reset resets the Checker to its initial state, so that previously written data no longer counts.

func (Checker) Write

func (c Checker) Write(p []byte) (n int, err error)

Write adds more data to the underlying running hash(es).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL