hash

package
v0.0.0-...-f028939 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LevelCRC32  Level = 1 << iota // CRC32 only (fastest)
	LevelMD5                      // MD5
	LevelSHA1                     // SHA1
	LevelSHA256                   // SHA256

	LevelMinimal  = LevelCRC32
	LevelStandard = LevelCRC32 | LevelMD5 | LevelSHA1
	LevelFull     = LevelCRC32 | LevelMD5 | LevelSHA1 | LevelSHA256
)

Variables

This section is empty.

Functions

func VerifyCRC32

func VerifyCRC32(path string, expected string) (bool, error)

VerifyCRC32 checks if a file matches the expected CRC32.

func VerifySHA1

func VerifySHA1(path string, expected string) (bool, error)

VerifySHA1 checks if a file matches the expected SHA1.

Types

type Level

type Level int

Level controls which checksums to compute.

type Result

type Result struct {
	CRC32  string `json:"crc32"`
	MD5    string `json:"md5"`
	SHA1   string `json:"sha1"`
	SHA256 string `json:"sha256"`
	Size   int64  `json:"size"`
}

Result contains all computed checksums for a file.

func File

func File(path string, level Level) (*Result, error)

File computes checksums for a file at the given path. It reads the file once, computing all requested hashes in a single pass.

The path is filepath.Clean'd before opening; callers are still expected to constrain inputs to trusted roots (scan results, DB rows) rather than raw user input. The Clean() step makes CodeQL's path-taint analysis happy.

func Reader

func Reader(r io.Reader, level Level) (*Result, error)

Reader computes checksums from an io.Reader in a single pass.

Jump to

Keyboard shortcuts

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