hash

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2022 License: Apache-2.0 Imports: 10 Imported by: 1

Documentation

Index

Constants

View Source
const RecommendedHashType = HashType_HashType_BLAKE3

RecommendedHashType is the hash type recommended to use. Note: not guaranteed to stay the same between Bifrost versions.

Variables

View Source
var ErrHashMismatch = errors.New("hash mismatch")

ErrHashMismatch is returned when hashes mismatch.

View Source
var HashType_name = map[int32]string{
	0: "HashType_UNKNOWN",
	1: "HashType_SHA256",
	2: "HashType_SHA1",
	3: "HashType_BLAKE3",
}
View Source
var HashType_value = map[string]int32{
	"HashType_UNKNOWN": 0,
	"HashType_SHA256":  1,
	"HashType_SHA1":    2,
	"HashType_BLAKE3":  3,
}

SupportedHashTypes is the list of built-in hash types.

Functions

This section is empty.

Types

type Hash

type Hash struct {
	// HashType is the hash type in use.
	HashType HashType `protobuf:"varint,1,opt,name=hash_type,json=hashType,proto3,enum=hash.HashType" json:"hash_type,omitempty"`
	// Hash is the hash value.
	Hash                 []byte   `protobuf:"bytes,2,opt,name=hash,proto3" json:"hash,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

Hash is a hash of a binary blob.

func NewHash

func NewHash(ht HashType, h []byte) *Hash

NewHash constructs a new hash object.

func Sum

func Sum(ht HashType, data []byte) (*Hash, error)

Sum constructs a hash type by summing an object.

func (*Hash) Clone

func (h *Hash) Clone() *Hash

Clone clones the hash object.

func (*Hash) CompareHash

func (h *Hash) CompareHash(other *Hash) bool

CompareHash compares two hashes.

func (*Hash) Descriptor

func (*Hash) Descriptor() ([]byte, []int)

func (*Hash) GetHash

func (m *Hash) GetHash() []byte

func (*Hash) GetHashType

func (m *Hash) GetHashType() HashType

func (*Hash) IsEmpty

func (h *Hash) IsEmpty() bool

IsEmpty checks if the hash is empty.

func (*Hash) MarshalDigest

func (h *Hash) MarshalDigest() []byte

MarshalDigest marshals the hash to a binary slice.

func (*Hash) MarshalString

func (h *Hash) MarshalString() string

MarshalString marshals the hash to a string.

func (*Hash) ProtoMessage

func (*Hash) ProtoMessage()

func (*Hash) Reset

func (m *Hash) Reset()

func (*Hash) String

func (m *Hash) String() string

func (*Hash) Validate

func (h *Hash) Validate() error

Validate validates the hash.

func (*Hash) VerifyData

func (h *Hash) VerifyData(data []byte) ([]byte, error)

VerifyData verifies data against the sum. Returns the hash of the data, hash type, and error Returns an error if failed to validate.

func (*Hash) XXX_DiscardUnknown

func (m *Hash) XXX_DiscardUnknown()

func (*Hash) XXX_Marshal

func (m *Hash) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Hash) XXX_Merge

func (m *Hash) XXX_Merge(src proto.Message)

func (*Hash) XXX_Size

func (m *Hash) XXX_Size() int

func (*Hash) XXX_Unmarshal

func (m *Hash) XXX_Unmarshal(b []byte) error

type HashType

type HashType int32

HashType identifies the hash type in use.

const (
	// HashType_UNKNOWN is an unknown hash type.
	HashType_HashType_UNKNOWN HashType = 0
	// HashType_SHA256 is the sha256 hash type.
	HashType_HashType_SHA256 HashType = 1
	// HashType_SHA1 is the sha1 hash type.
	// Note: this is not recommended for use outside of backwards-compat.
	HashType_HashType_SHA1 HashType = 2
	// HashType_BLAKE3 is the blake3 hash type.
	// Uses a 32-byte digest size.
	HashType_HashType_BLAKE3 HashType = 3
)

func (HashType) BuildHasher

func (h HashType) BuildHasher() (hash.Hash, error)

BuildHasher builds the hasher for the hash type.

func (HashType) EnumDescriptor

func (HashType) EnumDescriptor() ([]byte, []int)

func (HashType) GetHashLen

func (h HashType) GetHashLen() int

GetHashLen returns the hash length.

func (HashType) String

func (x HashType) String() string

func (HashType) Sum

func (h HashType) Sum(data []byte) ([]byte, error)

Sum takes the sum with the hash type.

func (HashType) Validate

func (h HashType) Validate() error

Validate validates the hash type.

Jump to

Keyboard shortcuts

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