hash

package
v1.49.5 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2019 License: MIT Imports: 12 Imported by: 243

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.

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

View Source
var Width = map[Type]int{
	MD5:          32,
	SHA1:         40,
	Dropbox:      64,
	QuickXorHash: 40,
	Whirlpool:    128,
	CRC32:        8,
}

Width returns the width in characters for any HashType

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.

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 (*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

const (
	// MD5 indicates MD5 support
	MD5 Type = 1 << iota

	// SHA1 indicates SHA-1 support
	SHA1

	// Dropbox indicates Dropbox special hash
	// https://www.dropbox.com/developers/reference/content-hash
	Dropbox

	// QuickXorHash indicates Microsoft onedrive hash
	// https://docs.microsoft.com/en-us/onedrive/developer/code-snippets/quickxorhash
	QuickXorHash

	// Whirlpool indicates Whirlpool support
	Whirlpool

	// CRC32 indicates CRC-32 support
	CRC32

	// None indicates no hashes are supported
	None Type = 0
)

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