#include "config.h" #include #include #ifdef HAVE_OPENSSL #include #include #else extern "C" { #include "md5.h" #include "sha1.h" #include "sha256.h" #include "sha512.h" } #endif #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; if (type == htMD5) hashSize = md5HashSize; else if (type == htSHA1) hashSize = sha1HashSize; else if (type == htSHA256) hashSize = sha256HashSize; else if (type == htSHA512) hashSize = sha512HashSize; else 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
aboutsummaryrefslogtreecommitdiff