about summary refs log tree commit diff
path: root/src/nix-hash
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2005-01-13T17·39+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2005-01-13T17·39+0000
commit7e8961f72056f53ccf78eba0ee8c240bc2310ab8 (patch)
treef4ae8ee014f3d86aa9ec1706d1aa9e83c2329a73 /src/nix-hash
parent73992371a3bc16b27b22e53d5f7ae600dea9cf60 (diff)
* Added SHA-1 support. `nix-hash' now has an option `--type sha1' to
  select SHA-1 hashing.

Diffstat (limited to 'src/nix-hash')
-rw-r--r--src/nix-hash/nix-hash.cc15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/nix-hash/nix-hash.cc b/src/nix-hash/nix-hash.cc
index 23309ff7469e..6a044972afb7 100644
--- a/src/nix-hash/nix-hash.cc
+++ b/src/nix-hash/nix-hash.cc
@@ -13,13 +13,24 @@ void printHelp()
 
 void run(Strings args)
 {
+    HashType ht = htMD5;
     bool flat = false;
+    
     for (Strings::iterator i = args.begin();
          i != args.end(); i++)
+    {
         if (*i == "--flat") flat = true;
+        else if (*i == "--type") {
+            ++i;
+            if (i == args.end()) throw UsageError("`--type' requires an argument");
+            if (*i == "md5") ht = htMD5;
+            else if (*i == "sha1") ht = htSHA1;
+            else throw UsageError(format("unknown hash type `%1%'") % *i);
+        }
         else
-            cout << format("%1%\n") % (string) 
-                (flat ? hashFile(*i) : hashPath(*i));
+            cout << format("%1%\n") % (string)
+                (flat ? hashFile(*i, ht) : hashPath(*i, ht));
+    }
 }