hash

package
v1.57.2 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2022 License: MIT Imports: 15 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 HelpString added in v1.56.0

func HelpString(indent int) string

HelpString returns help message with supported hashes

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, base64Encoded bool) 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) Sum added in v1.55.0

func (m *MultiHasher) Sum(hashType Type) ([]byte, error)

Sum returns the specified hash from the multihasher

func (*MultiHasher) SumString added in v1.57.1

func (m *MultiHasher) SumString(hashType Type, base64Encoded bool) (string, error)

SumString returns the specified hash from the multihasher as a hex or base64 encoded string

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

	// SHA256 indicates SHA-256 support
	SHA256 Type
)

func RegisterHash added in v1.6.1

func RegisterHash(name, alias 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. Both name and alias are accepted.

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