hash

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Sha1           = "SHA1"
	AdditionalSha1 = "ADDITIONAL_SHA1"
)

Variables

View Source
var (
	ErrTooLargeForSuperHash   = fmt.Errorf("reader is too large for super hash calculation")
	ErrTooSmallForSuperHash   = fmt.Errorf("reader is too small for super hash calculation")
	ErrTooSmallForSigByteHash = fmt.Errorf("reader is too small for msb and lsb super hash calculations")
)

Functions

func BytesHash

func BytesHash(bs []byte, algo crypto.Hash) string

func BytesSha1

func BytesSha1(bs []byte) string

func FileHash

func FileHash(path string, algo crypto.Hash) (string, error)

func FileSha1

func FileSha1(path string) (string, error)

func Hash

func Hash(reader io.Reader, algo crypto.Hash) (string, error)

func OtherPlatformHash

func OtherPlatformHash(reader io.Reader, algo crypto.Hash) (string, error)

OtherPlatformHash calculates the hash of the provided io.Reader contents, after replacing the line endings to the other platform type. if the line endings are CRLF, they will be switched to LF if the line endings are LF, they will be switched to CRLF

func OtherPlatformSha1

func OtherPlatformSha1(reader io.Reader) (string, error)

func StringHash

func StringHash(str string, algo crypto.Hash) string

func StringSha1

func StringSha1(str string) string

Types

type SuperHash

type SuperHash struct {
	// FullHash contains a hash of the whole file
	FullHash string

	// MosSigBitsHash contains a hash of the first bits of the file. Amount of bits determined by bucket size.
	MostSigBitsHash string

	// LeastSigBitsHash contains a hash of the last bits of the file. Amount of bits determined by bucket size.
	LeastSigBitsHash string
	// contains filtered or unexported fields
}

SuperHash contains various hashes of a source file. All hashes are performed after stripping away all whitespace from the file

func CalculateSuperHash

func CalculateSuperHash(rs io.ReadSeeker, algo crypto.Hash) (h *SuperHash, err error)

CalculateSuperHash calculates the super hash of the provided reader, with the provided hash algorithm

func CalculateSuperSha1

func CalculateSuperSha1(rs io.ReadSeeker) (*SuperHash, error)

Jump to

Keyboard shortcuts

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