hashutil

package
v0.0.0-...-c39e8e5 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2022 License: AGPL-3.0 Imports: 8 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Hash

func Hash(bs []byte) string

Hash hashes a blob into a hex hash that is assumed to be unique in the entire universe.

func HashFile

func HashFile(p string) (string, error)

HashFile computes the hash of the given file.

func HashReader

func HashReader(r io.Reader) (string, error)

HashReader hashes all the bytes read from a reader.

func HashStr

func HashStr(s string) string

HashStr hashes a string into a hash in hex.

Types

type CheckReader

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

CheckReader is a reader that checks the content of a reader, and returns an InvalidArg error if the hash mismatches, instead of io.EOF.

func NewCheckReader

func NewCheckReader(r io.Reader, h string, n int64) (*CheckReader, error)

NewCheckReader creates a new checking reader. the hash is sha256

func NewSHA256CheckReader

func NewSHA256CheckReader(r io.Reader, h []byte, n int64) *CheckReader

NewSHA256CheckReader creates a new checking reader that checks sha256 hash.

func (*CheckReader) Read

func (r *CheckReader) Read(buf []byte) (int, error)

Read reads into buf, and checks the hash. If it reaches the end of the stream but the hash mismatches, it returns an InvalidArg error.

Jump to

Keyboard shortcuts

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