hashlib

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2019 License: AGPL-3.0 Imports: 8 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Hash

type Hash []byte

Hash is like multihash.Multihash but also supports serializing to json. It's methods are nil-value safe.

var (
	// EmptyBackendHash is a hash containing only zeros, using IPFS's default hash.
	EmptyBackendHash Hash

	// EmptyInternalHash is a hash containing only zeros, using brig's default hash.
	EmptyInternalHash Hash
)

func Cast

func Cast(data []byte) (Hash, error)

Cast checks if `data` is a suitable hash and converts it.

func FromB58String

func FromB58String(b58 string) (Hash, error)

FromB58String creates a new Hash from a base58 string. (This is shorthand for importing/using &Hash{multihash.FromB58String("xxx")}

func Sum

func Sum(data []byte) Hash

Sum hashes `data` with the internal hashing algorithm.

func SumWithBackendHash added in v0.2.0

func SumWithBackendHash(data []byte) Hash

SumWithBackendHash creates a hash with the same algorithm the backend uses.

func TestDummy

func TestDummy(t *testing.T, seed byte) Hash

TestDummy returns a blake2b hash based on `seed`. The same `seed` will always generate the same hash.

func (Hash) B58String

func (h Hash) B58String() string

B58String formats the hash as base58 string.

func (Hash) Bytes

func (h Hash) Bytes() []byte

Bytes returns the underlying bytes in the hash.

func (Hash) Clone

func (h Hash) Clone() Hash

Clone returns the same hash as `h`, but with a different underlying array.

func (Hash) Equal

func (h Hash) Equal(other Hash) bool

Equal returns true if both hashes are equal. Nil hashes are considered equal.

func (Hash) Mix added in v0.2.0

func (h Hash) Mix(o Hash) Hash

Mix produces a hash of both passed hashes.

func (Hash) ShortB58

func (h Hash) ShortB58() string

ShortB58 produces a shorter version (12 bytes long) of B58String()

func (Hash) String

func (h Hash) String() string

func (Hash) UnmarshalJSON

func (h Hash) UnmarshalJSON(data []byte) error

UnmarshalJSON loads a base58 string representation of a hash and converts it to raw bytes.

func (Hash) Valid

func (h Hash) Valid() bool

Valid returns true if the hash contains a defined value.

type HashWriter

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

HashWriter is a io.Writer that supports being written to.

func NewHashWriter

func NewHashWriter() *HashWriter

NewHashWriter returns a new HashWriter. Currently it is always sha3-256.

func (*HashWriter) Finalize

func (hw *HashWriter) Finalize() Hash

Finalize returns the final hash of the written data.

func (*HashWriter) Write

func (hw *HashWriter) Write(buf []byte) (int, error)

Jump to

Keyboard shortcuts

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