about summary refs log tree commit diff
path: root/src/nix-hash/nix-hash.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/nix-hash/nix-hash.cc')
-rw-r--r--src/nix-hash/nix-hash.cc17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/nix-hash/nix-hash.cc b/src/nix-hash/nix-hash.cc
index 2cef7818e857..78c6f44012b4 100644
--- a/src/nix-hash/nix-hash.cc
+++ b/src/nix-hash/nix-hash.cc
@@ -15,22 +15,25 @@ void run(Strings args)
 {
     HashType ht = htMD5;
     bool flat = false;
+    bool base32 = false;
     
     for (Strings::iterator i = args.begin();
          i != args.end(); i++)
     {
         if (*i == "--flat") flat = true;
+        else if (*i == "--base32") base32 = 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 if (*i == "sha256") ht = htSHA256;
-            else throw UsageError(format("unknown hash type `%1%'") % *i);
+            ht = parseHashType(*i);
+            if (ht == htUnknown)
+                throw UsageError(format("unknown hash type `%1%'") % *i);
+        }
+        else {
+            Hash h = flat ? hashFile(ht, *i) : hashPath(ht, *i);
+            cout << format("%1%\n") %
+                (base32 ? printHash32(h) : printHash(h));
         }
-        else
-            cout << format("%1%\n") % printHash(
-                (flat ? hashFile(*i, ht) : hashPath(*i, ht)));
     }
 }