forked from lix-project/lix
d58a11e019
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.)
40 lines
895 B
C++
40 lines
895 B
C++
#include <iostream>
|
|
|
|
#include "hash.hh"
|
|
#include "shared.hh"
|
|
#include "help.txt.hh"
|
|
|
|
|
|
void printHelp()
|
|
{
|
|
cout << string((char *) helpText, sizeof helpText);
|
|
}
|
|
|
|
|
|
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 if (*i == "sha256") ht = htSHA256;
|
|
else throw UsageError(format("unknown hash type `%1%'") % *i);
|
|
}
|
|
else
|
|
cout << format("%1%\n") % printHash(
|
|
(flat ? hashFile(*i, ht) : hashPath(*i, ht)));
|
|
}
|
|
}
|
|
|
|
|
|
string programId = "nix-hash";
|
|
|