about summary refs log tree commit diff
path: root/src/libstore/store.cc
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2005-01-14T16·04+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2005-01-14T16·04+0000
commitd58a11e019813902b6c4547ca61a127938b2cc20 (patch)
treeddaff27d1a3c0604ffac989867cf63fbf8ce94ff /src/libstore/store.cc
parent9530cc31700f68fd229eee69eabd2baa099f404a (diff)
* Shorten SHA-256 hashes used in store path name generation to 160
  bits, then encode them in a radix-32 representation (using digits
  and letters except e, o, u, and t).  This produces store paths like
  /nix/store/4i0zb0z7f88mwghjirkz702a71dcfivn-aterm-2.3.1.  The nice
  thing about this is that the hash part of the file name is still 32
  characters, as before with MD5.

  (Of course, shortening SHA-256 to 160 bits makes it no better than
  SHA-160 in theory, but hopefully it's a bit more resistant to
  attacks; it's certainly a lot slower.)

Diffstat (limited to 'src/libstore/store.cc')
-rw-r--r--src/libstore/store.cc12
1 files changed, 5 insertions, 7 deletions
diff --git a/src/libstore/store.cc b/src/libstore/store.cc
index 3a76618a5a39..e490bf258195 100644
--- a/src/libstore/store.cc
+++ b/src/libstore/store.cc
@@ -415,14 +415,12 @@ Path makeStorePath(const string & type,
     Hash & hash, const string & suffix)
 {
     /* e.g., "source:sha256:1abc...:/nix/store:foo.tar.gz" */
-    string s = type + ":sha256:" + (string) hash + ":"
+    string s = type + ":sha256:" + printHash(hash) + ":"
         + nixStore + ":" + suffix;
 
-    Hash nameHash = hashString(s, htSHA256);
-
-    printMsg(lvlError, format("name input: %1% -> %2%") % s % (string) nameHash);
-
-    return nixStore + "/" + (string) nameHash + "-" + suffix;
+    return nixStore + "/"
+        + printHash32(compressHash(hashString(s, htSHA256), 20))
+        + "-" + suffix;
 }
 
 
@@ -461,7 +459,7 @@ Path addToStore(const Path & _srcPath)
             Hash h2 = hashPath(dstPath, htSHA256);
             if (h != h2)
                 throw Error(format("contents of `%1%' changed while copying it to `%2%' (%3% -> %4%)")
-                    % srcPath % dstPath % (string) h % (string) h2);
+                    % srcPath % dstPath % printHash(h) % printHash(h2));
 
             makePathReadOnly(dstPath);