sri

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2020 License: Apache-2.0 Imports: 9 Imported by: 2

README

Subresource Integrity checking for Go

Go Report Card GoDoc

go-sri implements Subresource Integrity checking for Go. It can parse SRI strings and validate content against them; this is done efficiently, calculating only the set of hashes that are useful for an input.

See godoc for more information & usage.

Documentation

Overview

Package sri implements a Subresource Integrity checker for Go. See https://www.w3.org/TR/SRI/ for more information.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Checker

type Checker struct {
	// contains filtered or unexported fields
}

A Checker implements checking of a resource against a given subresource integrity string.

It is not safe for concurrent use; each Checker corresponds to a single resource to be checked.

After creation you would typically use it as a Writer to add data to it, then call Check to verify that the content matches the original expression.

func NewChecker

func NewChecker(sri string) (*Checker, error)

NewChecker creates a new Checker from the given string. It supports SHA256, SHA384 and SHA512 (although will only calculate those needed for the input). Use NewCheckerForHashes if you need support for additional hash types.

func NewCheckerForHashes

func NewCheckerForHashes(sri string, hashes map[string]HashFunc) (*Checker, error)

NewCheckerForHashes creates a new Checker from the given string and set of hashes. It does not add any hashes by default, although will still only calculate those required by the SRI string given.

func NewCheckerWithSHA1

func NewCheckerWithSHA1(sri string) (*Checker, error)

NewCheckerWithSHA1 is like NewChecker but adds SHA1 as an optional hash type. This is generally useful only for compatibility and is *not* recommended by the standard, so use at your own risk.

func (*Checker) Check

func (c *Checker) Check() error

Check checks the data read so far against the expected hashes. It returns an error if it does not match or nil on success.

func (*Checker) Expected added in v1.1.0

func (c *Checker) Expected(name string) []string

Expected returns the expected hashes for the given hash name.

func (*Checker) Write

func (c *Checker) Write(b []byte) (int, error)

Write implements the io.Writer interface. It never returns an error.

type HashFunc

type HashFunc func() hash.Hash

A HashFunc is simply a function that returns a new Hash instance.

Jump to

Keyboard shortcuts

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