hash

package
v1.51.0-mod-v1.6 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrUnsupported = errors.New("hash type not supported")

ErrUnsupported should be returned by filesystem, if it is requested to deliver an unsupported hash type.

Functions

func Equals

func Equals(src, dst string) bool

Equals checks to see if src == dst, but ignores empty strings and returns true if either is empty.

func Stream

func Stream(r io.Reader) (map[Type]string, error)

Stream will calculate hashes of all supported hash types.

func StreamTypes

func StreamTypes(r io.Reader, set Set) (map[Type]string, error)

StreamTypes will calculate hashes of the requested hash types.

func Width

func Width(hashType Type) int

Width returns the width in characters for any HashType

Types

type MultiHasher

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

A MultiHasher will construct various hashes on all incoming writes.

func NewMultiHasher

func NewMultiHasher() *MultiHasher

NewMultiHasher will return a hash writer that will write all supported hash types.

func NewMultiHasherTypes

func NewMultiHasherTypes(set Set) (*MultiHasher, error)

NewMultiHasherTypes will return a hash writer that will write the requested hash types.

func (*MultiHasher) Size

func (m *MultiHasher) Size() int64

Size returns the number of bytes written

func (*MultiHasher) Sums

func (m *MultiHasher) Sums() map[Type]string

Sums returns the sums of all accumulated hashes as hex encoded strings.

func (*MultiHasher) Write

func (m *MultiHasher) Write(p []byte) (n int, err error)

type Set

type Set int

A Set Indicates one or more hash types.

func NewHashSet

func NewHashSet(t ...Type) Set

NewHashSet will create a new hash set with the hash types supplied

func Supported

func Supported() Set

Supported returns a set of all the supported hashes by HashStream and MultiHasher.

func (*Set) Add

func (h *Set) Add(t ...Type) Set

Add one or more hash types to the set. Returns the modified hash set.

func (Set) Array

func (h Set) Array() (ht []Type)

Array returns an array of all hash types in the set

func (Set) Contains

func (h Set) Contains(t Type) bool

Contains returns true if the

func (Set) Count

func (h Set) Count() int

Count returns the number of hash types in the set

func (Set) GetOne

func (h Set) GetOne() Type

GetOne will return a hash type. Currently the first is returned, but it could be improved to return the strongest.

func (Set) Overlap

func (h Set) Overlap(t Set) Set

Overlap returns the overlapping hash types

func (Set) String

func (h Set) String() string

String returns a string representation of the hash set. The function will panic if it contains an unknown type.

func (Set) SubsetOf

func (h Set) SubsetOf(c Set) bool

SubsetOf will return true if all types of h is present in the set c

type Type

type Type int

Type indicates a standard hashing algorithm

var (
	// None indicates no hashes are supported
	None Type

	// MD5 indicates MD5 support
	MD5 Type

	// SHA1 indicates SHA-1 support
	SHA1 Type

	// Whirlpool indicates Whirlpool support
	Whirlpool Type

	// CRC32 indicates CRC-32 support
	CRC32 Type
)

func RegisterHash

func RegisterHash(name string, width int, newFunc func() hash.Hash) Type

RegisterHash adds a new Hash to the list and returns it Type

func (*Type) Set

func (h *Type) Set(s string) error

Set a Type from a flag

func (Type) String

func (h Type) String() string

String returns a string representation of the hash type. The function will panic if the hash type is unknown.

func (Type) Type

func (h Type) Type() string

Type of the value

Jump to

Keyboard shortcuts

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