diff options
author | Jack Lloyd <[email protected]> | 2021-04-03 15:20:21 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2021-04-03 15:20:21 -0400 |
commit | a7e30a97fe3748e970283bf03936c239642036e6 (patch) | |
tree | a652d36ff75e3393d579020655b259a82c122bc1 /src | |
parent | 6858f5cb7d8feb169a722c86cafc8175bf733ccc (diff) | |
parent | 0b5554cf3edbcfcfdbb2d500c0fb45e69a047616 (diff) |
Merge GH #2688 Use make_unique in HashFunction copy_state impl
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/hash/blake2/blake2b.cpp | 2 | ||||
-rw-r--r-- | src/lib/hash/checksum/adler32/adler32.cpp | 2 | ||||
-rw-r--r-- | src/lib/hash/checksum/crc24/crc24.cpp | 2 | ||||
-rw-r--r-- | src/lib/hash/checksum/crc32/crc32.cpp | 2 | ||||
-rw-r--r-- | src/lib/hash/comb4p/comb4p.cpp | 4 | ||||
-rw-r--r-- | src/lib/hash/gost_3411/gost_3411.cpp | 2 | ||||
-rw-r--r-- | src/lib/hash/keccak/keccak.cpp | 2 | ||||
-rw-r--r-- | src/lib/hash/md4/md4.cpp | 2 | ||||
-rw-r--r-- | src/lib/hash/md5/md5.cpp | 2 | ||||
-rw-r--r-- | src/lib/hash/par_hash/par_hash.cpp | 4 | ||||
-rw-r--r-- | src/lib/hash/rmd160/rmd160.cpp | 2 | ||||
-rw-r--r-- | src/lib/hash/sha1/sha160.cpp | 2 | ||||
-rw-r--r-- | src/lib/hash/sha2_32/sha2_32.cpp | 4 | ||||
-rw-r--r-- | src/lib/hash/sha2_64/sha2_64.cpp | 6 | ||||
-rw-r--r-- | src/lib/hash/sha3/sha3.cpp | 2 | ||||
-rw-r--r-- | src/lib/hash/shake/shake.cpp | 4 | ||||
-rw-r--r-- | src/lib/hash/skein/skein_512.cpp | 9 | ||||
-rw-r--r-- | src/lib/hash/sm3/sm3.cpp | 2 | ||||
-rw-r--r-- | src/lib/hash/streebog/streebog.cpp | 2 | ||||
-rw-r--r-- | src/lib/hash/whirlpool/whirlpool.cpp | 2 |
20 files changed, 28 insertions, 31 deletions
diff --git a/src/lib/hash/blake2/blake2b.cpp b/src/lib/hash/blake2/blake2b.cpp index 1d5b8b718..9f825acf5 100644 --- a/src/lib/hash/blake2/blake2b.cpp +++ b/src/lib/hash/blake2/blake2b.cpp @@ -209,7 +209,7 @@ HashFunction* BLAKE2b::clone() const std::unique_ptr<HashFunction> BLAKE2b::copy_state() const { - return std::unique_ptr<HashFunction>(new BLAKE2b(*this)); + return std::make_unique<BLAKE2b>(*this); } void BLAKE2b::key_schedule(const uint8_t key[], size_t length) diff --git a/src/lib/hash/checksum/adler32/adler32.cpp b/src/lib/hash/checksum/adler32/adler32.cpp index 241844ab2..8d8b61b2e 100644 --- a/src/lib/hash/checksum/adler32/adler32.cpp +++ b/src/lib/hash/checksum/adler32/adler32.cpp @@ -80,7 +80,7 @@ void Adler32::final_result(uint8_t output[]) std::unique_ptr<HashFunction> Adler32::copy_state() const { - return std::unique_ptr<HashFunction>(new Adler32(*this)); + return std::make_unique<Adler32>(*this); } } diff --git a/src/lib/hash/checksum/crc24/crc24.cpp b/src/lib/hash/checksum/crc24/crc24.cpp index 8db920f8c..4d1af3bd8 100644 --- a/src/lib/hash/checksum/crc24/crc24.cpp +++ b/src/lib/hash/checksum/crc24/crc24.cpp @@ -188,7 +188,7 @@ inline uint32_t process32(uint32_t crc, uint32_t word) std::unique_ptr<HashFunction> CRC24::copy_state() const { - return std::unique_ptr<HashFunction>(new CRC24(*this)); + return std::make_unique<CRC24>(*this); } /* diff --git a/src/lib/hash/checksum/crc32/crc32.cpp b/src/lib/hash/checksum/crc32/crc32.cpp index 3030403d5..32f70ee37 100644 --- a/src/lib/hash/checksum/crc32/crc32.cpp +++ b/src/lib/hash/checksum/crc32/crc32.cpp @@ -105,7 +105,7 @@ void CRC32::final_result(uint8_t output[]) std::unique_ptr<HashFunction> CRC32::copy_state() const { - return std::unique_ptr<HashFunction>(new CRC32(*this)); + return std::make_unique<CRC32>(*this); } } diff --git a/src/lib/hash/comb4p/comb4p.cpp b/src/lib/hash/comb4p/comb4p.cpp index 24b606e48..bf8f412c7 100644 --- a/src/lib/hash/comb4p/comb4p.cpp +++ b/src/lib/hash/comb4p/comb4p.cpp @@ -71,11 +71,11 @@ void Comb4P::clear() std::unique_ptr<HashFunction> Comb4P::copy_state() const { + // Can't use make_unique as this constructor is private std::unique_ptr<Comb4P> copy(new Comb4P); copy->m_hash1 = m_hash1->copy_state(); copy->m_hash2 = m_hash2->copy_state(); - // work around GCC 4.8 bug - return std::unique_ptr<HashFunction>(copy.release()); + return copy; } void Comb4P::add_data(const uint8_t input[], size_t length) diff --git a/src/lib/hash/gost_3411/gost_3411.cpp b/src/lib/hash/gost_3411/gost_3411.cpp index 4f91a731d..22354d124 100644 --- a/src/lib/hash/gost_3411/gost_3411.cpp +++ b/src/lib/hash/gost_3411/gost_3411.cpp @@ -34,7 +34,7 @@ void GOST_34_11::clear() std::unique_ptr<HashFunction> GOST_34_11::copy_state() const { - return std::unique_ptr<HashFunction>(new GOST_34_11(*this)); + return std::make_unique<GOST_34_11>(*this); } /** diff --git a/src/lib/hash/keccak/keccak.cpp b/src/lib/hash/keccak/keccak.cpp index aab8386fc..7a1612205 100644 --- a/src/lib/hash/keccak/keccak.cpp +++ b/src/lib/hash/keccak/keccak.cpp @@ -14,7 +14,7 @@ namespace Botan { std::unique_ptr<HashFunction> Keccak_1600::copy_state() const { - return std::unique_ptr<HashFunction>(new Keccak_1600(*this)); + return std::make_unique<Keccak_1600>(*this); } Keccak_1600::Keccak_1600(size_t output_bits) : diff --git a/src/lib/hash/md4/md4.cpp b/src/lib/hash/md4/md4.cpp index 0f857a102..9d6d4d52e 100644 --- a/src/lib/hash/md4/md4.cpp +++ b/src/lib/hash/md4/md4.cpp @@ -14,7 +14,7 @@ namespace Botan { std::unique_ptr<HashFunction> MD4::copy_state() const { - return std::unique_ptr<HashFunction>(new MD4(*this)); + return std::make_unique<MD4>(*this); } namespace { diff --git a/src/lib/hash/md5/md5.cpp b/src/lib/hash/md5/md5.cpp index 66c06ef71..fbdbb916c 100644 --- a/src/lib/hash/md5/md5.cpp +++ b/src/lib/hash/md5/md5.cpp @@ -14,7 +14,7 @@ namespace Botan { std::unique_ptr<HashFunction> MD5::copy_state() const { - return std::unique_ptr<HashFunction>(new MD5(*this)); + return std::make_unique<MD5>(*this); } namespace { diff --git a/src/lib/hash/par_hash/par_hash.cpp b/src/lib/hash/par_hash/par_hash.cpp index d615e63ce..8f375537c 100644 --- a/src/lib/hash/par_hash/par_hash.cpp +++ b/src/lib/hash/par_hash/par_hash.cpp @@ -60,12 +60,12 @@ std::unique_ptr<HashFunction> Parallel::copy_state() const { std::vector<std::unique_ptr<HashFunction>> hash_clones; - for(const std::unique_ptr<HashFunction>& hash : m_hashes) + for(const auto& hash : m_hashes) { hash_clones.push_back(hash->copy_state()); } - return std::unique_ptr<HashFunction>(new Parallel(hash_clones)); + return std::make_unique<Parallel>(hash_clones); } void Parallel::clear() diff --git a/src/lib/hash/rmd160/rmd160.cpp b/src/lib/hash/rmd160/rmd160.cpp index e091dc32d..cc18679eb 100644 --- a/src/lib/hash/rmd160/rmd160.cpp +++ b/src/lib/hash/rmd160/rmd160.cpp @@ -14,7 +14,7 @@ namespace Botan { std::unique_ptr<HashFunction> RIPEMD_160::copy_state() const { - return std::unique_ptr<HashFunction>(new RIPEMD_160(*this)); + return std::make_unique<RIPEMD_160>(*this); } namespace { diff --git a/src/lib/hash/sha1/sha160.cpp b/src/lib/hash/sha1/sha160.cpp index a6a918e52..daba22a0d 100644 --- a/src/lib/hash/sha1/sha160.cpp +++ b/src/lib/hash/sha1/sha160.cpp @@ -15,7 +15,7 @@ namespace Botan { std::unique_ptr<HashFunction> SHA_160::copy_state() const { - return std::unique_ptr<HashFunction>(new SHA_160(*this)); + return std::make_unique<SHA_160>(*this); } namespace SHA1_F { diff --git a/src/lib/hash/sha2_32/sha2_32.cpp b/src/lib/hash/sha2_32/sha2_32.cpp index c43fe3db6..01d3dfce3 100644 --- a/src/lib/hash/sha2_32/sha2_32.cpp +++ b/src/lib/hash/sha2_32/sha2_32.cpp @@ -46,12 +46,12 @@ std::string sha256_provider() std::unique_ptr<HashFunction> SHA_224::copy_state() const { - return std::unique_ptr<HashFunction>(new SHA_224(*this)); + return std::make_unique<SHA_224>(*this); } std::unique_ptr<HashFunction> SHA_256::copy_state() const { - return std::unique_ptr<HashFunction>(new SHA_256(*this)); + return std::make_unique<SHA_256>(*this); } /* diff --git a/src/lib/hash/sha2_64/sha2_64.cpp b/src/lib/hash/sha2_64/sha2_64.cpp index cc4690bbd..73a42824f 100644 --- a/src/lib/hash/sha2_64/sha2_64.cpp +++ b/src/lib/hash/sha2_64/sha2_64.cpp @@ -31,17 +31,17 @@ std::string sha512_provider() std::unique_ptr<HashFunction> SHA_384::copy_state() const { - return std::unique_ptr<HashFunction>(new SHA_384(*this)); + return std::make_unique<SHA_384>(*this); } std::unique_ptr<HashFunction> SHA_512::copy_state() const { - return std::unique_ptr<HashFunction>(new SHA_512(*this)); + return std::make_unique<SHA_512>(*this); } std::unique_ptr<HashFunction> SHA_512_256::copy_state() const { - return std::unique_ptr<HashFunction>(new SHA_512_256(*this)); + return std::make_unique<SHA_512_256>(*this); } /* diff --git a/src/lib/hash/sha3/sha3.cpp b/src/lib/hash/sha3/sha3.cpp index 8ff2d06ee..83393acdd 100644 --- a/src/lib/hash/sha3/sha3.cpp +++ b/src/lib/hash/sha3/sha3.cpp @@ -234,7 +234,7 @@ std::string SHA_3::provider() const std::unique_ptr<HashFunction> SHA_3::copy_state() const { - return std::unique_ptr<HashFunction>(new SHA_3(*this)); + return std::make_unique<SHA_3>(*this); } HashFunction* SHA_3::clone() const diff --git a/src/lib/hash/shake/shake.cpp b/src/lib/hash/shake/shake.cpp index 6740581c6..01f1d9dfa 100644 --- a/src/lib/hash/shake/shake.cpp +++ b/src/lib/hash/shake/shake.cpp @@ -31,7 +31,7 @@ HashFunction* SHAKE_128::clone() const std::unique_ptr<HashFunction> SHAKE_128::copy_state() const { - return std::unique_ptr<HashFunction>(new SHAKE_128(*this)); + return std::make_unique<SHAKE_128>(*this); } void SHAKE_128::clear() @@ -72,7 +72,7 @@ HashFunction* SHAKE_256::clone() const std::unique_ptr<HashFunction> SHAKE_256::copy_state() const { - return std::unique_ptr<HashFunction>(new SHAKE_256(*this)); + return std::make_unique<SHAKE_256>(*this); } void SHAKE_256::clear() diff --git a/src/lib/hash/skein/skein_512.cpp b/src/lib/hash/skein/skein_512.cpp index caa16f26e..78cd3e794 100644 --- a/src/lib/hash/skein/skein_512.cpp +++ b/src/lib/hash/skein/skein_512.cpp @@ -16,7 +16,7 @@ Skein_512::Skein_512(size_t arg_output_bits, const std::string& arg_personalization) : m_personalization(arg_personalization), m_output_bits(arg_output_bits), - m_threefish(new Threefish_512), + m_threefish(std::make_unique<Threefish_512>()), m_T(2), m_buffer(64), m_buf_pos(0) { if(m_output_bits == 0 || m_output_bits % 8 != 0 || m_output_bits > 512) @@ -40,15 +40,12 @@ HashFunction* Skein_512::clone() const std::unique_ptr<HashFunction> Skein_512::copy_state() const { - std::unique_ptr<Skein_512> copy(new Skein_512(m_output_bits, m_personalization)); - + auto copy = std::make_unique<Skein_512>(m_output_bits, m_personalization); copy->m_threefish->m_K = this->m_threefish->m_K; copy->m_T = this->m_T; copy->m_buffer = this->m_buffer; copy->m_buf_pos = this->m_buf_pos; - - // work around GCC 4.8 bug - return std::unique_ptr<HashFunction>(copy.release()); + return copy; } void Skein_512::clear() diff --git a/src/lib/hash/sm3/sm3.cpp b/src/lib/hash/sm3/sm3.cpp index d29f2b505..4f75f5b20 100644 --- a/src/lib/hash/sm3/sm3.cpp +++ b/src/lib/hash/sm3/sm3.cpp @@ -15,7 +15,7 @@ namespace Botan { std::unique_ptr<HashFunction> SM3::copy_state() const { - return std::unique_ptr<HashFunction>(new SM3(*this)); + return std::make_unique<SM3>(*this); } namespace { diff --git a/src/lib/hash/streebog/streebog.cpp b/src/lib/hash/streebog/streebog.cpp index f0b4dfbfa..8d0167c53 100644 --- a/src/lib/hash/streebog/streebog.cpp +++ b/src/lib/hash/streebog/streebog.cpp @@ -17,7 +17,7 @@ extern const uint64_t STREEBOG_C[12][8]; std::unique_ptr<HashFunction> Streebog::copy_state() const { - return std::unique_ptr<HashFunction>(new Streebog(*this)); + return std::make_unique<Streebog>(*this); } Streebog::Streebog(size_t output_bits) : diff --git a/src/lib/hash/whirlpool/whirlpool.cpp b/src/lib/hash/whirlpool/whirlpool.cpp index bded759a1..6a6899d60 100644 --- a/src/lib/hash/whirlpool/whirlpool.cpp +++ b/src/lib/hash/whirlpool/whirlpool.cpp @@ -270,7 +270,7 @@ void Whirlpool::copy_out(uint8_t output[]) std::unique_ptr<HashFunction> Whirlpool::copy_state() const { - return std::unique_ptr<HashFunction>(new Whirlpool(*this)); + return std::make_unique<Whirlpool>(*this); } /* |