hashing

package module
v1.173.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: Apache-2.0 Imports: 18 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package hashing provides utilities for calculating hashes.

Index

Constants

View Source
const (
	HashMd5       = "MD5"
	HashSha256    = "SHA256"
	HashSha1      = "SHA1"
	HashMurmur    = "Murmur"
	HashXXHash    = "xxhash"     // https://github.com/OneOfOne/xxhash
	HashBlake2256 = "blake2b256" // https://www.blake2.net/
)

Variables

View Source
var (
	SupportedHashingAlgorithms = []string{HashMd5, HashXXHash, HashSha1, HashSha256, HashMurmur, HashBlake2256}
)

Functions

func CalculateBytesHash

func CalculateBytesHash(ctx context.Context, htype string, array []byte) (string, error)

CalculateBytesHash returns the hash of a byte array

func CalculateHash

func CalculateHash(text, htype string) string

CalculateHash calculates the hash of some text using the requested htype hashing algorithm.

func CalculateHashFromReader

func CalculateHashFromReader(ctx context.Context, htype string, reader io.Reader) (hash string, err error)

CalculateHashFromReader returns the hash of element coming from a reader.

func CalculateHashOfListOfStrings

func CalculateHashOfListOfStrings(ctx context.Context, htype string, text ...string) string

CalculateHashOfListOfStrings calculates the hash of some text using the requested htype hashing algorithm.

func CalculateHashWithContext

func CalculateHashWithContext(ctx context.Context, text, htype string) string

CalculateHashWithContext calculates the hash of some text using the requested htype hashing algorithm.

func CalculateMD5Hash

func CalculateMD5Hash(text string) string

func CalculateStringHash

func CalculateStringHash(hashingAlgo IHash, text string) string

CalculateStringHash returns the hash of some text using a particular hashing algorithm

func CalculateStringHashList

func CalculateStringHashList(ctx context.Context, hashingAlgo IHash, text ...string) string

CalculateStringHashList returns the hash of a list of strings using a particular hashing algorithm

func CalculateStringHashWithContext

func CalculateStringHashWithContext(ctx context.Context, hashingAlgo IHash, text string) string

CalculateStringHashWithContext returns the hash of some text using a particular hashing algorithm

func DetermineHashingAlgorithmCanonicalReference

func DetermineHashingAlgorithmCanonicalReference(name string) (ref string, err error)

DetermineHashingAlgorithmCanonicalReference determines the hashing algorithm reference from a string.

func HasLikelyHexHashStringEntropy

func HasLikelyHexHashStringEntropy(str string) bool

HasLikelyHexHashStringEntropy states whether a string has an entropy which may entail it is a hexadecimal hash This is based on the work done by `detect-secrets` https://github.com/Yelp/detect-secrets/blob/2fc0e31f067af98d97ad0f507dac032c9506f667/detect_secrets/plugins/high_entropy_strings.py#L150

func IsLikelyHexHashString

func IsLikelyHexHashString(str string) bool

IsLikelyHexHashString determines whether the string is likely to be a hexadecimal hash or not.

Types

type IHash

type IHash interface {
	Calculate(reader io.Reader) (string, error)
	CalculateWithContext(ctx context.Context, reader io.Reader) (string, error)
	GetType() string
}

IHash defines a hashing algorithm.

func DetermineHashingAlgorithm

func DetermineHashingAlgorithm(algorithm string) (IHash, error)

DetermineHashingAlgorithm returns a hashing algorithm based on a string reference. Similar to NewHashingAlgorithm but more flexible.

func NewBespokeHashingAlgorithm

func NewBespokeHashingAlgorithm(algorithm hash.Hash) (IHash, error)

NewBespokeHashingAlgorithm defines a bespoke hashing algorithm

func NewHashingAlgorithm

func NewHashingAlgorithm(htype string) (IHash, error)

Directories

Path Synopsis
* Copyright (C) 2020-2026 Arm Limited or its affiliates and Contributors.
* Copyright (C) 2020-2026 Arm Limited or its affiliates and Contributors.

Jump to

Keyboard shortcuts

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