Documentation
¶
Index ¶
- Constants
- Variables
- func SetMockHasher(t *testing.T)
- func ValidateAlgorithm(algorithm string) bool
- type Config
- type Hasher
- type MockHasher
- func (m *MockHasher) Hash(ctx context.Context, reader io.Reader, name string) (Result, error)
- func (m *MockHasher) HashBytes(ctx context.Context, data []byte, name string) (Result, error)
- func (m *MockHasher) HashFile(ctx context.Context, filePath string) (Result, error)
- func (m *MockHasher) HashFiles(ctx context.Context, files []string) ([]Result, error)
- type Result
Constants ¶
View Source
const ( // DefaultBufferSize is the default buffer size for reading files (64KB). DefaultBufferSize = 64 * 1024 // DefaultWorkers is 0, which means runtime.NumCPU() / 2 (minimum 1). DefaultWorkers = 0 // DefaultWorkerDivisor is used to calculate the default number of workers. DefaultWorkerDivisor = 2 // MinWorkers is the minimum number of workers to prevent deadlock. MinWorkers = 1 )
View Source
const ( AlgorithmSHA256 = "sha256" AlgorithmSHA512 = "sha512" AlgorithmBLAKE3 = "blake3" AlgorithmSHA3_256 = "sha3-256" AlgorithmSHA3_512 = "sha3-512" )
Supported hash algorithms.
Variables ¶
View Source
var New = newHasher
New creates a new Hasher with the given configuration.
View Source
var ( SupportedAlgorithms = []string{ AlgorithmSHA256, AlgorithmSHA512, AlgorithmBLAKE3, AlgorithmSHA3_256, AlgorithmSHA3_512, } )
Functions ¶
func SetMockHasher ¶
func ValidateAlgorithm ¶
ValidateAlgorithm checks if an algorithm is supported.
Types ¶
type Config ¶
type Config struct {
// Algorithms is the list of hash algorithms to use.
Algorithms []string
// Workers is the number of parallel workers for hashing.
// 0 means runtime.NumCPU() / 2 (minimum 1).
Workers int
// BufferSize is the size of the buffer for reading files.
BufferSize int
}
Config holds configuration for the hasher.
type Hasher ¶
type Hasher interface {
// Hash computes hashes for data from an io.Reader using all configured algorithms.
Hash(ctx context.Context, reader io.Reader, name string) (Result, error)
// HashBytes computes hashes for in-memory byte data.
HashBytes(ctx context.Context, data []byte, name string) (Result, error)
// HashFile computes hashes for a single file.
HashFile(ctx context.Context, filePath string) (Result, error)
// HashFiles computes hashes for multiple files in parallel.
HashFiles(ctx context.Context, files []string) ([]Result, error)
}
Hasher provides high-performance cryptographic hashing capabilities.
type MockHasher ¶
MockHasher is a mock implementation of the Hasher interface.
func NewMockHasher ¶
func NewMockHasher() *MockHasher
NewMockHasher creates a new MockHasher instance.
type Result ¶
type Result struct {
// Path is the file path that was hashed.
Path string
// Digests maps algorithm name to hex-encoded digest.
Digests map[string]string
// Size is the file size in bytes.
Size int64
// Error is any error that occurred during hashing.
Error error
}
Result holds the hashing result for a single file.
Click to show internal directories.
Click to hide internal directories.