* nix-hash: option `--truncate' to truncate the hash to 160 bits. Hmm,
kind of ad hoc ;-)
This commit is contained in:
parent
2fd22c6360
commit
0399365675
|
@ -6,3 +6,4 @@ files.
|
||||||
--flat: compute hash of regular file contents, not metadata
|
--flat: compute hash of regular file contents, not metadata
|
||||||
--base32: print hash in base-32 instead of hexadecimal
|
--base32: print hash in base-32 instead of hexadecimal
|
||||||
--type HASH: use hash algorithm HASH ("md5" (default), "sha1", "sha256")
|
--type HASH: use hash algorithm HASH ("md5" (default), "sha1", "sha256")
|
||||||
|
--truncate: truncate the hash to 160 bits
|
||||||
|
|
|
@ -16,12 +16,14 @@ void run(Strings args)
|
||||||
HashType ht = htMD5;
|
HashType ht = htMD5;
|
||||||
bool flat = false;
|
bool flat = false;
|
||||||
bool base32 = false;
|
bool base32 = false;
|
||||||
|
bool truncate = false;
|
||||||
|
|
||||||
for (Strings::iterator i = args.begin();
|
for (Strings::iterator i = args.begin();
|
||||||
i != args.end(); i++)
|
i != args.end(); i++)
|
||||||
{
|
{
|
||||||
if (*i == "--flat") flat = true;
|
if (*i == "--flat") flat = true;
|
||||||
else if (*i == "--base32") base32 = true;
|
else if (*i == "--base32") base32 = true;
|
||||||
|
else if (*i == "--truncate") truncate = true;
|
||||||
else if (*i == "--type") {
|
else if (*i == "--type") {
|
||||||
++i;
|
++i;
|
||||||
if (i == args.end()) throw UsageError("`--type' requires an argument");
|
if (i == args.end()) throw UsageError("`--type' requires an argument");
|
||||||
|
@ -31,6 +33,7 @@ void run(Strings args)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Hash h = flat ? hashFile(ht, *i) : hashPath(ht, *i);
|
Hash h = flat ? hashFile(ht, *i) : hashPath(ht, *i);
|
||||||
|
if (truncate && h.hashSize > 20) h = compressHash(h, 20);
|
||||||
cout << format("%1%\n") %
|
cout << format("%1%\n") %
|
||||||
(base32 ? printHash32(h) : printHash(h));
|
(base32 ? printHash32(h) : printHash(h));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue