From 46da4e841e4bcfbdd2e1dd194da8234230e29898 Mon Sep 17 00:00:00 2001 From: Jack Lloyd Date: Sat, 3 Apr 2021 11:29:02 -0400 Subject: Use make_unique in type factory functions --- src/lib/hash/hash.cpp | 60 ++++++++++++++++++++++++--------------------------- 1 file changed, 28 insertions(+), 32 deletions(-) (limited to 'src/lib/hash') diff --git a/src/lib/hash/hash.cpp b/src/lib/hash/hash.cpp index 7d0d15159..9cfb382eb 100644 --- a/src/lib/hash/hash.cpp +++ b/src/lib/hash/hash.cpp @@ -133,92 +133,92 @@ std::unique_ptr HashFunction::create(const std::string& algo_spec, algo_spec == "SHA-1" || algo_spec == "SHA1") { - return std::unique_ptr(new SHA_160); + return std::make_unique(); } #endif #if defined(BOTAN_HAS_SHA2_32) if(algo_spec == "SHA-224") { - return std::unique_ptr(new SHA_224); + return std::make_unique(); } if(algo_spec == "SHA-256") { - return std::unique_ptr(new SHA_256); + return std::make_unique(); } #endif #if defined(BOTAN_HAS_SHA2_64) if(algo_spec == "SHA-384") { - return std::unique_ptr(new SHA_384); + return std::make_unique(); } if(algo_spec == "SHA-512") { - return std::unique_ptr(new SHA_512); + return std::make_unique(); } if(algo_spec == "SHA-512-256") { - return std::unique_ptr(new SHA_512_256); + return std::make_unique(); } #endif #if defined(BOTAN_HAS_RIPEMD_160) if(algo_spec == "RIPEMD-160") { - return std::unique_ptr(new RIPEMD_160); + return std::make_unique(); } #endif #if defined(BOTAN_HAS_WHIRLPOOL) if(algo_spec == "Whirlpool") { - return std::unique_ptr(new Whirlpool); + return std::make_unique(); } #endif #if defined(BOTAN_HAS_MD5) if(algo_spec == "MD5") { - return std::unique_ptr(new MD5); + return std::make_unique(); } #endif #if defined(BOTAN_HAS_MD4) if(algo_spec == "MD4") { - return std::unique_ptr(new MD4); + return std::make_unique(); } #endif #if defined(BOTAN_HAS_GOST_34_11) if(algo_spec == "GOST-R-34.11-94" || algo_spec == "GOST-34.11") { - return std::unique_ptr(new GOST_34_11); + return std::make_unique(); } #endif #if defined(BOTAN_HAS_ADLER32) if(algo_spec == "Adler32") { - return std::unique_ptr(new Adler32); + return std::make_unique(); } #endif #if defined(BOTAN_HAS_CRC24) if(algo_spec == "CRC24") { - return std::unique_ptr(new CRC24); + return std::make_unique(); } #endif #if defined(BOTAN_HAS_CRC32) if(algo_spec == "CRC32") { - return std::unique_ptr(new CRC32); + return std::make_unique(); } #endif @@ -227,68 +227,64 @@ std::unique_ptr HashFunction::create(const std::string& algo_spec, #if defined(BOTAN_HAS_SKEIN_512) if(req.algo_name() == "Skein-512") { - return std::unique_ptr( - new Skein_512(req.arg_as_integer(0, 512), req.arg(1, ""))); + return std::make_unique(req.arg_as_integer(0, 512), req.arg(1, "")); } #endif #if defined(BOTAN_HAS_BLAKE2B) if(req.algo_name() == "Blake2b" || req.algo_name() == "BLAKE2b") { - return std::unique_ptr( - new Blake2b(req.arg_as_integer(0, 512))); + return std::make_unique(req.arg_as_integer(0, 512)); } #endif #if defined(BOTAN_HAS_KECCAK) if(req.algo_name() == "Keccak-1600") { - return std::unique_ptr( - new Keccak_1600(req.arg_as_integer(0, 512))); + return std::make_unique(req.arg_as_integer(0, 512)); } #endif #if defined(BOTAN_HAS_SHA3) if(req.algo_name() == "SHA-3") { - return std::unique_ptr( - new SHA_3(req.arg_as_integer(0, 512))); + return std::make_unique(req.arg_as_integer(0, 512)); } #endif #if defined(BOTAN_HAS_SHAKE) if(req.algo_name() == "SHAKE-128" && req.arg_count() == 1) { - return std::unique_ptr(new SHAKE_128(req.arg_as_integer(0))); + return std::make_unique(req.arg_as_integer(0)); } if(req.algo_name() == "SHAKE-256" && req.arg_count() == 1) { - return std::unique_ptr(new SHAKE_256(req.arg_as_integer(0))); + return std::make_unique(req.arg_as_integer(0)); } #endif #if defined(BOTAN_HAS_STREEBOG) if(algo_spec == "Streebog-256") { - return std::unique_ptr(new Streebog_256); + return std::make_unique(); } if(algo_spec == "Streebog-512") { - return std::unique_ptr(new Streebog_512); + return std::make_unique(); } #endif #if defined(BOTAN_HAS_SM3) if(algo_spec == "SM3") { - return std::unique_ptr(new SM3); + return std::make_unique(); } #endif #if defined(BOTAN_HAS_WHIRLPOOL) if(req.algo_name() == "Whirlpool") { - return std::unique_ptr(new Whirlpool); + return std::make_unique(); } #endif @@ -307,18 +303,18 @@ std::unique_ptr HashFunction::create(const std::string& algo_spec, hashes.push_back(std::move(h)); } - return std::unique_ptr(new Parallel(hashes)); + return std::make_unique(hashes); } #endif #if defined(BOTAN_HAS_COMB4P) if(req.algo_name() == "Comb4P" && req.arg_count() == 2) { - std::unique_ptr h1(HashFunction::create(req.arg(0))); - std::unique_ptr h2(HashFunction::create(req.arg(1))); + std::unique_ptr h1 = HashFunction::create(req.arg(0)); + std::unique_ptr h2 = HashFunction::create(req.arg(1)); if(h1 && h2) - return std::unique_ptr(new Comb4P(h1.release(), h2.release())); + return std::make_unique(h1.release(), h2.release()); } #endif -- cgit v1.2.3