diff options
Diffstat (limited to 'nix/libutil')
-rw-r--r-- | nix/libutil/archive.cc | 2 | ||||
-rw-r--r-- | nix/libutil/hash.cc | 8 | ||||
-rw-r--r-- | nix/libutil/hash.hh | 5 | ||||
-rw-r--r-- | nix/libutil/sha512.h | 35 | ||||
-rw-r--r-- | nix/libutil/util.cc | 2 | ||||
-rw-r--r-- | nix/libutil/util.hh | 11 |
6 files changed, 50 insertions, 13 deletions
diff --git a/nix/libutil/archive.cc b/nix/libutil/archive.cc index 6856ea0f28..4e3d99356a 100644 --- a/nix/libutil/archive.cc +++ b/nix/libutil/archive.cc @@ -256,7 +256,7 @@ static void parse(ParseSink & sink, Source & source, const Path & path) if (i != names.end()) { printMsg(lvlDebug, format("case collision between `%1%' and `%2%'") % i->first % name); name += caseHackSuffix; - name += int2String(++i->second); + name += std::to_string(++i->second); } else names[name] = 0; } diff --git a/nix/libutil/hash.cc b/nix/libutil/hash.cc index 2da00a53de..ea69aa64f9 100644 --- a/nix/libutil/hash.cc +++ b/nix/libutil/hash.cc @@ -11,6 +11,7 @@ extern "C" { #include "md5.h" #include "sha1.h" #include "sha256.h" +#include "sha512.h" } #endif @@ -40,6 +41,7 @@ Hash::Hash(HashType 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); @@ -199,6 +201,7 @@ struct Ctx MD5_CTX md5; SHA_CTX sha1; SHA256_CTX sha256; + SHA512_CTX sha512; }; @@ -207,6 +210,7 @@ static void start(HashType ht, Ctx & ctx) if (ht == htMD5) MD5_Init(&ctx.md5); else if (ht == htSHA1) SHA1_Init(&ctx.sha1); else if (ht == htSHA256) SHA256_Init(&ctx.sha256); + else if (ht == htSHA512) SHA512_Init(&ctx.sha512); } @@ -216,6 +220,7 @@ static void update(HashType ht, Ctx & ctx, if (ht == htMD5) MD5_Update(&ctx.md5, bytes, len); else if (ht == htSHA1) SHA1_Update(&ctx.sha1, bytes, len); else if (ht == htSHA256) SHA256_Update(&ctx.sha256, bytes, len); + else if (ht == htSHA512) SHA512_Update(&ctx.sha512, bytes, len); } @@ -224,6 +229,7 @@ static void finish(HashType ht, Ctx & ctx, unsigned char * hash) if (ht == htMD5) MD5_Final(hash, &ctx.md5); else if (ht == htSHA1) SHA1_Final(hash, &ctx.sha1); else if (ht == htSHA256) SHA256_Final(hash, &ctx.sha256); + else if (ht == htSHA512) SHA512_Final(hash, &ctx.sha512); } @@ -321,6 +327,7 @@ 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 return htUnknown; } @@ -330,6 +337,7 @@ 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 throw Error("cannot print unknown hash type"); } diff --git a/nix/libutil/hash.hh b/nix/libutil/hash.hh index 8f099c4f07..6b5e47cd8a 100644 --- a/nix/libutil/hash.hh +++ b/nix/libutil/hash.hh @@ -7,19 +7,20 @@ namespace nix { -typedef enum { htUnknown, htMD5, htSHA1, htSHA256 } HashType; +typedef enum { htUnknown, htMD5, htSHA1, htSHA256, htSHA512 } HashType; const int md5HashSize = 16; const int sha1HashSize = 20; const int sha256HashSize = 32; +const int sha512HashSize = 64; extern const string base32Chars; struct Hash { - static const unsigned int maxHashSize = 32; + static const unsigned int maxHashSize = 64; unsigned int hashSize; unsigned char hash[maxHashSize]; diff --git a/nix/libutil/sha512.h b/nix/libutil/sha512.h new file mode 100644 index 0000000000..d2abab4c5f --- /dev/null +++ b/nix/libutil/sha512.h @@ -0,0 +1,35 @@ +/* GNU Guix --- Functional package management for GNU + Copyright (C) 2012, 2015 Ludovic Courtès <ludo@gnu.org> + + This file is part of GNU Guix. + + GNU Guix is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or (at + your option) any later version. + + GNU Guix is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. */ + +#include <gcrypt-hash.hh> + +#define SHA512_CTX guix_hash_context + +static inline void +SHA512_Init (struct SHA512_CTX *ctx) +{ + guix_hash_init (ctx, GCRY_MD_SHA512); +} + +#define SHA512_Update guix_hash_update + +static inline void +SHA512_Final (void *resbuf, struct SHA512_CTX *ctx) +{ + guix_hash_final (resbuf, ctx, GCRY_MD_SHA512); +} diff --git a/nix/libutil/util.cc b/nix/libutil/util.cc index 14026ab829..c07754487e 100644 --- a/nix/libutil/util.cc +++ b/nix/libutil/util.cc @@ -433,7 +433,7 @@ Nest::~Nest() static string escVerbosity(Verbosity level) { - return int2String((int) level); + return std::to_string((int) level); } diff --git a/nix/libutil/util.hh b/nix/libutil/util.hh index 24e16ba36a..e84d64d10a 100644 --- a/nix/libutil/util.hh +++ b/nix/libutil/util.hh @@ -153,8 +153,8 @@ void printMsg_(Verbosity level, const FormatOrString & fs); #define printMsg(level, f) \ do { \ - if (level <= verbosity) { \ - printMsg_(level, (f)); \ + if (level <= nix::verbosity) { \ + nix::printMsg_(level, (f)); \ } \ } while (0) @@ -337,13 +337,6 @@ template<class N> bool string2Int(const string & s, N & n) return str && str.get() == EOF; } -template<class N> string int2String(N n) -{ - std::ostringstream str; - str << n; - return str.str(); -} - /* Return true iff `s' ends in `suffix'. */ bool hasSuffix(const string & s, const string & suffix); |