about summary refs log tree commit diff
path: root/src/libutil/hash.hh
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2016-04-20T12·12+0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2016-04-20T12·12+0200
commit451ebf24ce532f8d59f929efd486104fcebf1aa6 (patch)
tree08bf43e0aad39626a1cc1ab9d5e638fdf90567b9 /src/libutil/hash.hh
parente0204f8d462041387651af388074491fd0bf36d6 (diff)
Cache path info lookups in SQLite
This re-implements the binary cache database in C++, allowing it to be
used by other Store backends, in particular the S3 backend.
Diffstat (limited to 'src/libutil/hash.hh')
-rw-r--r--src/libutil/hash.hh12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/libutil/hash.hh b/src/libutil/hash.hh
index bac2ebf2dcfa..02e213fc7b35 100644
--- a/src/libutil/hash.hh
+++ b/src/libutil/hash.hh
@@ -7,6 +7,9 @@
 namespace nix {
 
 
+MakeError(BadHash, Error);
+
+
 enum HashType : char { htUnknown, htMD5, htSHA1, htSHA256, htSHA512 };
 
 
@@ -26,12 +29,15 @@ struct Hash
 
     HashType type;
 
-    /* Create an unusable hash object. */
+    /* Create an unset hash object. */
     Hash();
 
     /* Create a zero-filled hash object. */
     Hash(HashType type);
 
+    /* Check whether a hash is set. */
+    operator bool () const { return type != htUnknown; }
+
     /* Check whether two hash are equal. */
     bool operator == (const Hash & h2) const;
 
@@ -52,12 +58,16 @@ struct Hash
     {
         return (hashSize * 8 - 1) / 5 + 1;
     }
+
+    std::string to_string(bool base32 = true) const;
 };
 
 
 /* Convert a hash to a hexadecimal representation. */
 string printHash(const Hash & hash);
 
+Hash parseHash(const string & s);
+
 /* Parse a hexadecimal representation of a hash code. */
 Hash parseHash(HashType ht, const string & s);