hash

package
v0.51.2 Latest Latest
Warning

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

Go to latest
Published: May 7, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

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 (
	HashType_name = map[int32]string{
		0: "HashType_UNKNOWN",
		1: "HashType_SHA256",
		2: "HashType_SHA1",
		3: "HashType_BLAKE3",
	}
	HashType_value = map[string]int32{
		"HashType_UNKNOWN": 0,
		"HashType_SHA256":  1,
		"HashType_SHA1":    2,
		"HashType_BLAKE3":  3,
	}
)

Enum value maps for HashType.

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

ErrHashMismatch is returned when hashes mismatch.

View Source
var ErrHashTypeUnknown = errors.New("unknown hash type")

ErrHashTypeUnknown is returned when the hash type is unknown.

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" json:"hashType,omitempty"`
	// Hash is the hash value.
	Hash []byte `protobuf:"bytes,2,opt,name=hash,proto3" json:"hash,omitempty"`
	// contains filtered or unexported fields
}

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 UnmarshalHashJSON

func UnmarshalHashJSON(data []byte) (*Hash, error)

UnmarshalHashJSON unmarshals a hash from json.

func (*Hash) Clone

func (h *Hash) Clone() *Hash

Clone clones the hash object.

func (*Hash) CloneMessageVT

func (m *Hash) CloneMessageVT() protobuf_go_lite.CloneMessage

func (*Hash) CloneVT

func (m *Hash) CloneVT() *Hash

func (*Hash) CompareHash

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

CompareHash compares two hashes.

func (*Hash) EqualMessageVT

func (this *Hash) EqualMessageVT(thatMsg any) bool

func (*Hash) EqualVT

func (this *Hash) EqualVT(that *Hash) bool

func (*Hash) GetHash

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

func (*Hash) GetHashType

func (x *Hash) GetHashType() HashType

func (*Hash) IsEmpty

func (h *Hash) IsEmpty() bool

IsEmpty checks if the hash is empty.

func (*Hash) IsNil

func (h *Hash) IsNil() bool

IsNil checks if the object is nil.

func (*Hash) MarshalDigest

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

MarshalDigest marshals the hash to a binary slice.

func (*Hash) MarshalJSON

func (x *Hash) MarshalJSON() ([]byte, error)

MarshalJSON marshals the Hash to JSON.

func (*Hash) MarshalProtoJSON

func (x *Hash) MarshalProtoJSON(s *json.MarshalState)

MarshalProtoJSON marshals the Hash message to JSON.

func (*Hash) MarshalProtoText

func (x *Hash) MarshalProtoText() string

func (*Hash) MarshalString

func (h *Hash) MarshalString() string

MarshalString marshals the hash to a string.

func (*Hash) MarshalToSizedBufferVT

func (m *Hash) MarshalToSizedBufferVT(dAtA []byte) (int, error)

func (*Hash) MarshalToVT

func (m *Hash) MarshalToVT(dAtA []byte) (int, error)

func (*Hash) MarshalVT

func (m *Hash) MarshalVT() (dAtA []byte, err error)

func (*Hash) ParseFromB58

func (h *Hash) ParseFromB58(ref string) error

ParseFromB58 parses the object ref from a base58 string.

func (*Hash) ProtoMessage

func (*Hash) ProtoMessage()

func (*Hash) Reset

func (x *Hash) Reset()

func (*Hash) SizeVT

func (m *Hash) SizeVT() (n int)

func (*Hash) String

func (x *Hash) String() string

func (*Hash) UnmarshalJSON

func (x *Hash) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals the Hash from JSON.

func (*Hash) UnmarshalProtoJSON

func (x *Hash) UnmarshalProtoJSON(s *json.UnmarshalState)

UnmarshalProtoJSON unmarshals the Hash message from JSON.

func (*Hash) UnmarshalVT

func (m *Hash) UnmarshalVT(dAtA []byte) error

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.

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: Do not use SHA1 unless you absolutely have to for backwards compat! (Git)
	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) Enum

func (x HashType) Enum() *HashType

func (HashType) GetHashLen

func (h HashType) GetHashLen() int

GetHashLen returns the hash length.

func (HashType) MarshalJSON

func (x HashType) MarshalJSON() ([]byte, error)

MarshalJSON marshals the HashType to JSON.

func (HashType) MarshalProtoJSON

func (x HashType) MarshalProtoJSON(s *json.MarshalState)

MarshalProtoJSON marshals the HashType to JSON.

func (HashType) MarshalProtoText

func (x HashType) MarshalProtoText() string

func (HashType) MarshalText

func (x HashType) MarshalText() ([]byte, error)

MarshalText marshals the HashType to text.

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) UnmarshalJSON

func (x *HashType) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals the HashType from JSON.

func (*HashType) UnmarshalProtoJSON

func (x *HashType) UnmarshalProtoJSON(s *json.UnmarshalState)

UnmarshalProtoJSON unmarshals the HashType from JSON.

func (*HashType) UnmarshalText

func (x *HashType) UnmarshalText(b []byte) error

UnmarshalText unmarshals the HashType from text.

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