Nix 2.93.3
Lix: A modern, delicious implementation of the Nix package manager; unstable internal interfaces
Loading...
Searching...
No Matches
hash.hh File Reference
#include <openssl/evp.h>
#include "lix/libutil/archive.hh"
#include "lix/libutil/types.hh"
#include "lix/libutil/serialise.hh"
#include "lix/libutil/file-system.hh"

Go to the source code of this file.

Classes

struct  nix::Hash
struct  nix::AbstractHashSink
class  nix::HashSink

Typedefs

using nix::detail::EvpMdCtxPtr = std::unique_ptr<EVP_MD_CTX, decltype(&EVP_MD_CTX_free)>
typedef std::pair< Hash, uint64_t > nix::HashResult

Enumerations

enum class  HashType : char { MD5 = 42 , SHA1 , SHA256 , SHA512 }
enum class  Base : int { Base64 , Base32 , Base16 , SRI }

Functions

 nix::MakeError (BadHash, Error)
Hash nix::newHashAllowEmpty (std::string_view hashStr, std::optional< HashType > ht)
std::string nix::printHash16or32 (const Hash &hash)
Hash nix::hashString (HashType ht, std::string_view s)
Hash nix::hashFile (HashType ht, const Path &path)
HashResult nix::hashPath (HashType ht, const PreparedDump &path)
HashResult nix::hashPath (HashType ht, Path path)
Hash nix::compressHash (const Hash &hash, unsigned int newSize)
HashType nix::parseHashType (std::string_view s)
std::optional< HashType > nix::parseHashTypeOpt (std::string_view s)
std::string_view nix::printHashType (HashType ht)
HashResult nix::hashSource (HashType ht, Source &source)

Variables

const int nix::md5HashSize = 16
const int nix::sha1HashSize = 20
const int nix::sha256HashSize = 32
const int nix::sha512HashSize = 64

Typedef Documentation

◆ HashResult

typedef std::pair<Hash, uint64_t> nix::HashResult

Compute the hash of the given path. The hash is defined as (essentially) hashString(ht, dumpPath(path)).

Function Documentation

◆ compressHash()

Hash nix::compressHash ( const Hash & hash,
unsigned int newSize )

Compress a hash to the specified number of bytes by cyclically XORing bytes together.

◆ hashFile()

Hash nix::hashFile ( HashType ht,
const Path & path )

Compute the hash of the given file.

◆ hashString()

Hash nix::hashString ( HashType ht,
std::string_view s )

Compute the hash of the given string.

◆ newHashAllowEmpty()

Hash nix::newHashAllowEmpty ( std::string_view hashStr,
std::optional< HashType > ht )

Helper that defaults empty hashes to the 0 hash.

◆ parseHashType()

HashType nix::parseHashType ( std::string_view s)

Parse a string representing a hash type.

◆ parseHashTypeOpt()

std::optional< HashType > nix::parseHashTypeOpt ( std::string_view s)

Will return nothing on parse error

◆ printHash16or32()

std::string nix::printHash16or32 ( const Hash & hash)

Print a hash in base-16 if it's MD5, or base-32 otherwise.

◆ printHashType()

std::string_view nix::printHashType ( HashType ht)

And the reverse.