guix_mirror_bot pushed a commit to branch master
in repository guix.

commit 694785dc13840f36e9dda2fd413f0d6ac176f153
Author: Reepca Russelstein <[email protected]>
AuthorDate: Sun Jun 21 07:14:01 2026 -0500

    daemon: libutil: add isHash32.
    
    * nix/libutil/hash.hh (isHash32): new function.
    * nix/libutil/hash.hh (isHash32): provide implementation.
    
    Signed-off-by: Ludovic Courtès <[email protected]>
---
 nix/libutil/hash.cc | 9 +++++++++
 nix/libutil/hash.hh | 7 ++++++-
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/nix/libutil/hash.cc b/nix/libutil/hash.cc
index 06753d1961..7b363b4f9e 100644
--- a/nix/libutil/hash.cc
+++ b/nix/libutil/hash.cc
@@ -194,6 +194,15 @@ bool isHash(std::string_view s)
     return true;
 }
 
+
+bool isHash32(std::string_view s)
+{
+    if (s.length() != 32) return false;
+    for (unsigned char c : s)
+        if (base32Values[c] == -1) return false;
+    return true;
+}
+
 /* The "hash context".  */
 struct Ctx
 {
diff --git a/nix/libutil/hash.hh b/nix/libutil/hash.hh
index fabe50c11c..40d6b8725d 100644
--- a/nix/libutil/hash.hh
+++ b/nix/libutil/hash.hh
@@ -72,9 +72,14 @@ Hash parseHash32(HashType ht, std::string_view s);
 /* Parse a base-16 or base-32 representation of a hash code. */
 Hash parseHash16or32(HashType ht, std::string_view s);
 
-/* Verify that the given string is a valid hash code. */
+/* Verify that the given string is a valid base16 hash code with 32
+   characters. */
 bool isHash(std::string_view s);
 
+/* Verify that the given string is a valid base32 hash code with 32
+   characters. */
+bool isHash32(std::string_view s);
+
 /* Compute the hash of the given string. */
 Hash hashString(HashType ht, const string & s);
 

Reply via email to