diff options
Diffstat (limited to 'Source/cmCryptoHash.cxx')
-rw-r--r-- | Source/cmCryptoHash.cxx | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/Source/cmCryptoHash.cxx b/Source/cmCryptoHash.cxx index 7995b2c..d914eb1 100644 --- a/Source/cmCryptoHash.cxx +++ b/Source/cmCryptoHash.cxx @@ -2,11 +2,14 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmCryptoHash.h" +#include "cmAlgorithms.h" #include "cm_kwiml.h" #include "cm_rhash.h" #include "cmsys/FStream.hxx" #include <string.h> +#include <memory> // IWYU pragma: keep + static unsigned int const cmCryptoHashAlgoToId[] = { /* clang-format needs this comment to break after the opening brace */ RHASH_MD5, // @@ -43,39 +46,39 @@ cmCryptoHash::~cmCryptoHash() rhash_free(this->CTX); } -CM_AUTO_PTR<cmCryptoHash> cmCryptoHash::New(const char* algo) +std::unique_ptr<cmCryptoHash> cmCryptoHash::New(const char* algo) { if (strcmp(algo, "MD5") == 0) { - return CM_AUTO_PTR<cmCryptoHash>(new cmCryptoHash(AlgoMD5)); + return cm::make_unique<cmCryptoHash>(AlgoMD5); } if (strcmp(algo, "SHA1") == 0) { - return CM_AUTO_PTR<cmCryptoHash>(new cmCryptoHash(AlgoSHA1)); + return cm::make_unique<cmCryptoHash>(AlgoSHA1); } if (strcmp(algo, "SHA224") == 0) { - return CM_AUTO_PTR<cmCryptoHash>(new cmCryptoHash(AlgoSHA224)); + return cm::make_unique<cmCryptoHash>(AlgoSHA224); } if (strcmp(algo, "SHA256") == 0) { - return CM_AUTO_PTR<cmCryptoHash>(new cmCryptoHash(AlgoSHA256)); + return cm::make_unique<cmCryptoHash>(AlgoSHA256); } if (strcmp(algo, "SHA384") == 0) { - return CM_AUTO_PTR<cmCryptoHash>(new cmCryptoHash(AlgoSHA384)); + return cm::make_unique<cmCryptoHash>(AlgoSHA384); } if (strcmp(algo, "SHA512") == 0) { - return CM_AUTO_PTR<cmCryptoHash>(new cmCryptoHash(AlgoSHA512)); + return cm::make_unique<cmCryptoHash>(AlgoSHA512); } if (strcmp(algo, "SHA3_224") == 0) { - return CM_AUTO_PTR<cmCryptoHash>(new cmCryptoHash(AlgoSHA3_224)); + return cm::make_unique<cmCryptoHash>(AlgoSHA3_224); } if (strcmp(algo, "SHA3_256") == 0) { - return CM_AUTO_PTR<cmCryptoHash>(new cmCryptoHash(AlgoSHA3_256)); + return cm::make_unique<cmCryptoHash>(AlgoSHA3_256); } if (strcmp(algo, "SHA3_384") == 0) { - return CM_AUTO_PTR<cmCryptoHash>(new cmCryptoHash(AlgoSHA3_384)); + return cm::make_unique<cmCryptoHash>(AlgoSHA3_384); } if (strcmp(algo, "SHA3_512") == 0) { - return CM_AUTO_PTR<cmCryptoHash>(new cmCryptoHash(AlgoSHA3_512)); + return cm::make_unique<cmCryptoHash>(AlgoSHA3_512); } - return CM_AUTO_PTR<cmCryptoHash>(CM_NULLPTR); + return std::unique_ptr<cmCryptoHash>(nullptr); } bool cmCryptoHash::IntFromHexDigit(char input, char& output) @@ -103,10 +106,9 @@ std::string cmCryptoHash::ByteHashToString( '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; std::string res; - for (std::vector<unsigned char>::const_iterator vit = hash.begin(); - vit != hash.end(); ++vit) { - res.push_back(hex[(*vit) >> 4]); - res.push_back(hex[(*vit) & 0xF]); + for (unsigned char v : hash) { + res.push_back(hex[v >> 4]); + res.push_back(hex[v & 0xF]); } return res; } |