#include "config.h" #include #include #include "hash.hh" #include "archive.hh" #include "util.hh" #include #include #include namespace nix { Hash::Hash() { type = htUnknown; hashSize = 0; memset(hash, 0, maxHashSize); } Hash::Hash(HashType type) { this->type = type; hashSize = gcry_md_get_algo_dlen(type); if (hashSize == 0) throw Error("unknown hash type"); assert(hashSize <= maxHashSize); memset(hash, 0, maxHashSize); } bool Hash::operator == (const Hash & h2) const { if (hashSize != h2.hashSize) return false; for (unsigned int i = 0; i < hashSize; i++) if (hash[i] != h2.hash[i]) return false; return true; } bool Hash::operator != (const Hash & h2) const { return !(*this == h2); } bool Hash::operator < (const Hash & h) const { for (unsigned int i = 0; i < hashSize; i++) { if (hash[i] < h.hash[i]) return true; if (hash[i] > h.hash[i]) return false; } return false; } const string ba
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEfraim Flashner <efraim@flashner.co.il>2024-01-07 12:02:28 +0200
committerEfraim Flashner <efraim@flashner.co.il>2024-02-20 13:57:33 +0200
commita85203a525c7a7eafbcafeab757cfad9b97eb839 (patch)
tree971a0ed4042334137d814d87efffb471e11de335 /gnu/tests/rsync.scm
parenta9cb99563b0782109d0ce73511439e532f297722 (diff)
downloadguix-a85203a525c7a7eafbcafeab757cfad9b97eb839.tar.gz
guix-a85203a525c7a7eafbcafeab757cfad9b97eb839.zip
gnu: Add rust-anstyle-0.3.
* gnu/packages/crates-io.scm (rust-anstyle-0.3): New variable. Change-Id: I01e626109ab3863a41778d5c767750880396c5bd
Diffstat (limited to 'gnu/tests/rsync.scm')
0 files changed, 0 insertions, 0 deletions
2 = *ctx; Hash hash(ht); nix::finish(ht, ctx2, hash.hash); return HashResult(hash, bytes); } HashResult hashPath( HashType ht, const Path & path, PathFilter & filter) { HashSink sink(ht); dumpPath(path, sink, filter); return sink.finish(); } Hash compressHash(const Hash & hash, unsigned int newSize) { Hash h; h.hashSize = newSize; for (unsigned int i = 0; i < hash.hashSize; ++i) h.hash[i % newSize] ^= hash.hash[i]; return h; } HashType parseHashType(const string & s) { if (s == "md5") return htMD5; else if (s == "sha1") return htSHA1; else if (s == "sha256") return htSHA256; else if (s == "sha512") return htSHA512; else if (s == "sha3-256") return htSHA3_256; else if (s == "sha3-512") return htSHA3_512; else if (s == "blake2s-256") return htBLAKE2s_256; else return htUnknown; } string printHashType(HashType ht) { if (ht == htMD5) return "md5"; else if (ht == htSHA1) return "sha1"; else if (ht == htSHA256) return "sha256"; else if (ht == htSHA512) return "sha512"; else if (ht == htSHA3_256) return "sha3-256"; else if (ht == htSHA3_512) return "sha3-512"; else if (ht == htBLAKE2s_256) return "blake2s-256"; else throw Error("cannot print unknown hash type"); } }