Documentation ¶
Overview ¶
Package nixhash provides methods to serialize and deserialize some of the hashes used in nix code and .narinfo files.
Nix uses different representation of hashes depending on the context and history of the project. This package provides the utilities to handle them.
Index ¶
- Constants
- func CompressHash(input []byte, outputSize int) []byte
- type Algorithm
- type Encoding
- type Hash
- type HashWithEncoding
- func MustNewHashWithEncoding(algo Algorithm, digest []byte, encoding Encoding, includeAlgo bool) *HashWithEncoding
- func NewHashWithEncoding(algo Algorithm, digest []byte, encoding Encoding, includeAlgo bool) (*HashWithEncoding, error)
- func ParseAny(s string, optAlgo *Algorithm) (*HashWithEncoding, error)
Constants ¶
const ( // All the algorithms that Nix understands MD5 = Algorithm(iota) SHA1 = Algorithm(iota) SHA256 = Algorithm(iota) SHA512 = Algorithm(iota) )
const ( // All the encodings that Nix understands Base16 = Encoding(iota) // Lowercase hexadecimal encoding. Base64 = Encoding(iota) // [IETF RFC 4648, section 4](https://datatracker.ietf.org/doc/html/rfc4648#section-4). NixBase32 = Encoding(iota) // Nix-specific base-32 encoding. SRI = Encoding(iota) // W3C recommendation [Subresource Intergrity](https://www.w3.org/TR/SRI/) )
Variables ¶
This section is empty.
Functions ¶
func CompressHash ¶
CompressHash takes an arbitrary long sequence of bytes (usually a hash digest), and returns a sequence of bytes of length newSize. It's calculated by rotating through the bytes in the output buffer (zero-initialized), and XOR'ing with each byte in the passed input It consumes 1 byte at a time, and XOR's it with the current value in the output buffer.
Types ¶
type Algorithm ¶
type Algorithm uint8
Algorithm represent the hashing algorithm used to digest the data.
func ParseAlgorithm ¶
type Hash ¶
type Hash struct {
// contains filtered or unexported fields
}
func MustNewHash ¶
func MustParseNixBase32 ¶
MustParseNixBase32 returns a new Hash struct, by parsing a hashtype:nixbase32 string, or panics on error.
func ParseNixBase32 ¶
ParseNixBase32 returns a new Hash struct, by parsing a hashtype:nixbase32 string, or an error.
type HashWithEncoding ¶
type HashWithEncoding struct { Hash // contains filtered or unexported fields }
HashWithEncoding stores the original encoding so the user can get error messages with the same encoding.
func MustNewHashWithEncoding ¶
func MustNewHashWithEncoding(algo Algorithm, digest []byte, encoding Encoding, includeAlgo bool) *HashWithEncoding
func NewHashWithEncoding ¶
func ParseAny ¶
func ParseAny(s string, optAlgo *Algorithm) (*HashWithEncoding, error)
Parse the hash from a string representation in the format "[<type>:]<base16|base32|base64>" or "<type>-<base64>" (a Subresource Integrity hash expression). If the 'optAlgo' argument is not present, then the hash algorithm must be specified in the string.
func (HashWithEncoding) String ¶
func (h HashWithEncoding) String() string
String return the previous representation of a given hash.