Documentation
¶
Overview ¶
Package lhash provides integrated labeled hashes.
Index ¶
- type Algorithm
- type LabeledHash
- func Digest(alg Algorithm, data []byte) *LabeledHash
- func DigestFile(alg Algorithm, pathToFile string) (*LabeledHash, error)
- func DigestFromReader(alg Algorithm, reader io.Reader) (*LabeledHash, error)
- func FromBase58(base58Encoded string) (*LabeledHash, error)
- func FromBase64(base64Encoded string) (*LabeledHash, error)
- func FromHex(hexEncoded string) (*LabeledHash, error)
- func Load(labeledHash []byte) (*LabeledHash, error)
- func (lh *LabeledHash) Algorithm() Algorithm
- func (lh *LabeledHash) Base58() string
- func (lh *LabeledHash) Base64() string
- func (lh *LabeledHash) Bytes() []byte
- func (lh *LabeledHash) Equal(other *LabeledHash) bool
- func (lh *LabeledHash) EqualRaw(otherDigest []byte) bool
- func (lh *LabeledHash) Hex() string
- func (lh *LabeledHash) Matches(data []byte) bool
- func (lh *LabeledHash) MatchesData(data []byte) bool
- func (lh *LabeledHash) MatchesFile(pathToFile string) (bool, error)
- func (lh *LabeledHash) MatchesReader(reader io.Reader) (bool, error)
- func (lh *LabeledHash) MatchesString(s string) bool
- func (lh *LabeledHash) Sum() []byte
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Algorithm ¶
type Algorithm uint
Algorithm is an identifier for a hash function.
const ( SHA2_224 Algorithm = 8 SHA2_256 Algorithm = 9 SHA2_384 Algorithm = 10 SHA2_512 Algorithm = 11 SHA2_512_224 Algorithm = 12 SHA2_512_256 Algorithm = 13 SHA3_224 Algorithm = 16 SHA3_256 Algorithm = 17 SHA3_384 Algorithm = 18 SHA3_512 Algorithm = 19 BLAKE2s_256 Algorithm = 24 BLAKE2b_256 Algorithm = 25 BLAKE2b_384 Algorithm = 26 BLAKE2b_512 Algorithm = 27 BLAKE3 Algorithm = 32 )
func (Algorithm) Digest ¶ added in v0.3.0
func (a Algorithm) Digest(data []byte) *LabeledHash
Digest creates a new labeled hash and digests the given data.
func (Algorithm) DigestFile ¶ added in v0.3.0
func (a Algorithm) DigestFile(pathToFile string) (*LabeledHash, error)
DigestFile creates a new labeled hash and digests the given file.
func (Algorithm) DigestFromReader ¶ added in v0.3.0
func (a Algorithm) DigestFromReader(reader io.Reader) (*LabeledHash, error)
DigestFromReader creates a new labeled hash and digests from the given reader.
type LabeledHash ¶
type LabeledHash struct {
// contains filtered or unexported fields
}
LabeledHash represents a typed hash value.
func Digest ¶
func Digest(alg Algorithm, data []byte) *LabeledHash
Digest creates a new labeled hash and digests the given data.
func DigestFile ¶ added in v0.3.0
func DigestFile(alg Algorithm, pathToFile string) (*LabeledHash, error)
DigestFile creates a new labeled hash and digests the given file.
func DigestFromReader ¶ added in v0.3.0
func DigestFromReader(alg Algorithm, reader io.Reader) (*LabeledHash, error)
DigestFromReader creates a new labeled hash and digests from the given reader.
func FromBase58 ¶ added in v0.2.2
func FromBase58(base58Encoded string) (*LabeledHash, error)
FromBase58 loads a labeled hash from the given Base58 string using the BTC alphabet.
func FromBase64 ¶ added in v0.2.2
func FromBase64(base64Encoded string) (*LabeledHash, error)
FromBase64 loads a labeled hash from the given Base64 string using raw url encoding.
func FromHex ¶ added in v0.2.2
func FromHex(hexEncoded string) (*LabeledHash, error)
FromHex loads a labeled hash from the given hexadecimal string.
func Load ¶
func Load(labeledHash []byte) (*LabeledHash, error)
Load loads a labeled hash from the given []byte slice.
func (*LabeledHash) Algorithm ¶ added in v0.3.0
func (lh *LabeledHash) Algorithm() Algorithm
Algorithm returns the algorithm of the labeled hash.
func (*LabeledHash) Base58 ¶ added in v0.2.2
func (lh *LabeledHash) Base58() string
Base58 returns the Base58 string representation of the labeled hash using the BTC alphabet.
func (*LabeledHash) Base64 ¶ added in v0.2.2
func (lh *LabeledHash) Base64() string
Base64 returns the Base64 string representation of the labeled hash using raw url encoding.
func (*LabeledHash) Bytes ¶
func (lh *LabeledHash) Bytes() []byte
Bytes return the []byte representation of the labeled hash.
func (*LabeledHash) Equal ¶ added in v0.2.2
func (lh *LabeledHash) Equal(other *LabeledHash) bool
Equal returns true if the given labeled hash is equal. Equality is checked by comparing both the algorithm and the digest value.
func (*LabeledHash) EqualRaw ¶ added in v0.3.0
func (lh *LabeledHash) EqualRaw(otherDigest []byte) bool
EqualRaw returns true if the given raw hash digest is equal. Equality is checked by comparing both the digest value only. The caller must make sure the same algorithm is used.
func (*LabeledHash) Hex ¶ added in v0.2.2
func (lh *LabeledHash) Hex() string
Hex returns the hexadecimal string representation of the labeled hash.
func (*LabeledHash) Matches ¶
func (lh *LabeledHash) Matches(data []byte) bool
Matches returns true if the digest of the given data matches the hash.
func (*LabeledHash) MatchesData ¶ added in v0.2.2
func (lh *LabeledHash) MatchesData(data []byte) bool
MatchesData returns true if the digest of the given data matches the hash. Deprecated: Use Matches instead.
func (*LabeledHash) MatchesFile ¶ added in v0.3.0
func (lh *LabeledHash) MatchesFile(pathToFile string) (bool, error)
MatchesFile returns true if the digest of the given file matches the hash.
func (*LabeledHash) MatchesReader ¶ added in v0.3.0
func (lh *LabeledHash) MatchesReader(reader io.Reader) (bool, error)
MatchesReader returns true if the digest of the given reader matches the hash.
func (*LabeledHash) MatchesString ¶ added in v0.2.2
func (lh *LabeledHash) MatchesString(s string) bool
MatchesString returns true if the digest of the given string matches the hash.
func (*LabeledHash) Sum ¶ added in v0.3.0
func (lh *LabeledHash) Sum() []byte
Sum returns the raw calculated hash digest.