mirror of
https://github.com/NixOS/nix
synced 2025-07-04 23:51:47 +02:00
WIP: Make Hash always store a valid hash type
This commit is contained in:
parent
984e521392
commit
20799a5151
8 changed files with 53 additions and 52 deletions
|
@ -25,14 +25,11 @@ enum Base : int { Base64, Base32, Base16, SRI };
|
|||
|
||||
struct Hash
|
||||
{
|
||||
static const unsigned int maxHashSize = 64;
|
||||
unsigned int hashSize = 0;
|
||||
unsigned char hash[maxHashSize] = {};
|
||||
constexpr static size_t maxHashSize = 64;
|
||||
size_t hashSize = 0;
|
||||
uint8_t hash[maxHashSize] = {};
|
||||
|
||||
std::optional<HashType> type = {};
|
||||
|
||||
/* Create an unset hash object. */
|
||||
Hash() { };
|
||||
HashType type;
|
||||
|
||||
/* Create a zero-filled hash object. */
|
||||
Hash(HashType type) : type(type) { init(); };
|
||||
|
@ -105,7 +102,7 @@ Hash newHashAllowEmpty(std::string hashStr, std::optional<HashType> ht);
|
|||
string printHash16or32(const Hash & hash);
|
||||
|
||||
/* Compute the hash of the given string. */
|
||||
Hash hashString(HashType ht, const string & s);
|
||||
Hash hashString(HashType ht, std::string_view s);
|
||||
|
||||
/* Compute the hash of the given file. */
|
||||
Hash hashFile(HashType ht, const Path & path);
|
||||
|
@ -121,9 +118,9 @@ HashResult hashPath(HashType ht, const Path & path,
|
|||
Hash compressHash(const Hash & hash, unsigned int newSize);
|
||||
|
||||
/* Parse a string representing a hash type. */
|
||||
HashType parseHashType(const string & s);
|
||||
HashType parseHashType(std::string_view s);
|
||||
/* Will return nothing on parse error */
|
||||
std::optional<HashType> parseHashTypeOpt(const string & s);
|
||||
std::optional<HashType> parseHashTypeOpt(std::string_view s);
|
||||
|
||||
/* And the reverse. */
|
||||
string printHashType(HashType ht);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue