Documentation
¶
Overview ¶
Package shasum provides secure hash algorithm utilities
Index ¶
- Variables
- func BriefFile(file string) (shasum string, err error)
- func BriefSum[V HashInputTypes](data V) (shasum string, err error)
- func File(file string) (shasum string, err error)
- func Hash[V HashInputTypes](data V, t HashType) (shasum string, err error)
- func HashFile(file string, t HashType) (shasum string, err error)
- func MustBriefFile(file string) (shasum string)
- func MustBriefSum[V HashInputTypes](data V) (shasum string)
- func MustFile(file string) (shasum string)
- func MustHash[V HashInputTypes](data V, t HashType) (shasum string)
- func MustHashFile(file string, t HashType) (shasum string)
- func MustSum[V HashInputTypes](data V) (shasum string)
- func MustSum224[V HashInputTypes](data V) (shasum string)
- func MustSum256[V HashInputTypes](data V) (shasum string)
- func MustSum384[V HashInputTypes](data V) (shasum string)
- func MustSum512[V HashInputTypes](data V) (shasum string)
- func Sha1Bytes(data []byte) (shasum [20]byte)
- func Sha1Sum(data []byte) (shasum string)
- func Sum[V HashInputTypes](data V) (shasum string, err error)
- func Sum224[V HashInputTypes](data V) (shasum string, err error)
- func Sum256[V HashInputTypes](data V) (shasum string, err error)
- func Sum384[V HashInputTypes](data V) (shasum string, err error)
- func Sum512[V HashInputTypes](data V) (shasum string, err error)
- func Valid(hash string) (valid bool)
- func Validate(hash string, size HashLength) (valid bool)
- func Verify(hash string, data []byte) (err error)
- func VerifyFile(hash, file string) (err error)
- type HashInputTypes
- type HashLength
- type HashType
Constants ¶
This section is empty.
Variables ¶
var (
DefaultType = Sha256Type
)
var (
ErrVerifyFailed = errors.New("shasum verification failed")
)
Functions ¶
func BriefSum ¶
func BriefSum[V HashInputTypes](data V) (shasum string, err error)
BriefSum is a wrapper around Sum which returns a BriefLength `shasum`
func Hash ¶
func Hash[V HashInputTypes](data V, t HashType) (shasum string, err error)
Hash calculates the shasum of the given `data` and returns the hexadecimal encoded value
BriefType is an alias of Sha256Type and if an unknown HashType is given, Sha256Type is used
func HashFile ¶
HashFile is a convenience wrapper around reading the `file` data and returning the result of a call to Hash
func MustBriefFile ¶
MustBriefFile is a wrapper around File which returns a BriefLength `shasum`
func MustBriefSum ¶
func MustBriefSum[V HashInputTypes](data V) (shasum string)
MustBriefSum is a wrapper around BriefSum which panics with any error
func MustHash ¶
func MustHash[V HashInputTypes](data V, t HashType) (shasum string)
MustHash is a convenience wrapper around Hash which panics with any error
func MustHashFile ¶
MustHashFile is a convenience wrapper around HashFile which panics with any error
func MustSum ¶
func MustSum[V HashInputTypes](data V) (shasum string)
MustSum is a wrapper around Sum which panics with any error
func MustSum224 ¶
func MustSum224[V HashInputTypes](data V) (shasum string)
MustSum224 is a wrapper around Sum224 which panics with any error
func MustSum256 ¶
func MustSum256[V HashInputTypes](data V) (shasum string)
MustSum256 is a wrapper around Sum256 which panics with any error
func MustSum384 ¶
func MustSum384[V HashInputTypes](data V) (shasum string)
MustSum384 is a wrapper around Sum384 which panics with any error
func MustSum512 ¶
func MustSum512[V HashInputTypes](data V) (shasum string)
MustSum512 is a wrapper around Sum512 which panics with any error
func Sha1Bytes ¶
Sha1Bytes is a convenience wrapper around sha1.Sum
Note: do not use SHA-1 for securing data
func Sha1Sum ¶
Sha1Sum is a convenience wrapper around Sha1Bytes, returning the `shasum` as a hexadecimal string instead of a byte array
Note: do not use SHA-1 for securing data
func Sum ¶
func Sum[V HashInputTypes](data V) (shasum string, err error)
Sum is a wrapper around Hash using the DefaultType
func Sum224 ¶
func Sum224[V HashInputTypes](data V) (shasum string, err error)
Sum224 uses SHA-224 to hash the given `data` and return the result as a hexadecimal encoded string of Sha224Length
func Sum256 ¶
func Sum256[V HashInputTypes](data V) (shasum string, err error)
Sum256 uses SHA-256 to hash the given `data` and return the result as a hexadecimal encoded string of Sha256Length
func Sum384 ¶
func Sum384[V HashInputTypes](data V) (shasum string, err error)
Sum384 uses SHA-384 to hash the given `data` and return the result as a hexadecimal encoded string of Sha384Length
func Sum512 ¶
func Sum512[V HashInputTypes](data V) (shasum string, err error)
Sum512 uses SHA-512 to hash the given `data` and return the result as a hexadecimal encoded string of Sha512Length
func Valid ¶
Valid checks if the `hash` given is a valid HashLength string that passes a call to Validate
func Validate ¶
func Validate(hash string, size HashLength) (valid bool)
Validate returns true if the given `hash` is exactly the HashLength required and contains only the digits 0-9 and the lower-case letters a-f
func Verify ¶
Verify compares the given `hash` matches the exact Sum result derived from the given `data`
func VerifyFile ¶
VerifyFile uses Verify to validate the given file's integrity
Types ¶
type HashInputTypes ¶
HashInputTypes is the generic constraint for byte slice and string things
type HashLength ¶
type HashLength uint
HashLength is the length of a hexadecimal encoded string produced from one of the secure hashing functions
const ( // BriefLength is accepted as a short-form Sha256Length BriefLength HashLength = 10 Sha224Length HashLength = 56 Sha256Length HashLength = 64 Sha384Length HashLength = 96 Sha512Length HashLength = 128 )
func (HashLength) Size ¶ added in v1.1.0
func (h HashLength) Size() int