diff options
Diffstat (limited to 'nix')
| -rw-r--r-- | nix/libutil/hash.cc | 9 | ||||
| -rw-r--r-- | nix/libutil/hash.hh | 7 |
2 files changed, 15 insertions, 1 deletions
diff --git a/nix/libutil/hash.cc b/nix/libutil/hash.cc index 06753d19619..7b363b4f9e7 100644 --- a/nix/libutil/hash.cc +++ b/nix/libutil/hash.cc | |||
| @@ -194,6 +194,15 @@ bool isHash(std::string_view s) | |||
| 194 | return true; | 194 | return true; |
| 195 | } | 195 | } |
| 196 | 196 | ||
| 197 | |||
| 198 | bool isHash32(std::string_view s) | ||
| 199 | { | ||
| 200 | if (s.length() != 32) return false; | ||
| 201 | for (unsigned char c : s) | ||
| 202 | if (base32Values[c] == -1) return false; | ||
| 203 | return true; | ||
| 204 | } | ||
| 205 | |||
| 197 | /* The "hash context". */ | 206 | /* The "hash context". */ |
| 198 | struct Ctx | 207 | struct Ctx |
| 199 | { | 208 | { |
diff --git a/nix/libutil/hash.hh b/nix/libutil/hash.hh index fabe50c11c6..40d6b8725dd 100644 --- a/nix/libutil/hash.hh +++ b/nix/libutil/hash.hh | |||
| @@ -72,9 +72,14 @@ Hash parseHash32(HashType ht, std::string_view s); | |||
| 72 | /* Parse a base-16 or base-32 representation of a hash code. */ | 72 | /* Parse a base-16 or base-32 representation of a hash code. */ |
| 73 | Hash parseHash16or32(HashType ht, std::string_view s); | 73 | Hash parseHash16or32(HashType ht, std::string_view s); |
| 74 | 74 | ||
| 75 | /* Verify that the given string is a valid hash code. */ | 75 | /* Verify that the given string is a valid base16 hash code with 32 |
| 76 | characters. */ | ||
| 76 | bool isHash(std::string_view s); | 77 | bool isHash(std::string_view s); |
| 77 | 78 | ||
| 79 | /* Verify that the given string is a valid base32 hash code with 32 | ||
| 80 | characters. */ | ||
| 81 | bool isHash32(std::string_view s); | ||
| 82 | |||
| 78 | /* Compute the hash of the given string. */ | 83 | /* Compute the hash of the given string. */ |
| 79 | Hash hashString(HashType ht, const string & s); | 84 | Hash hashString(HashType ht, const string & s); |
| 80 | 85 | ||
