diff options
author | David Benjamin <davidben@google.com> | 2023-07-04 12:48:02 -0400 |
---|---|---|
committer | Boringssl LUCI CQ <boringssl-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2023-07-11 19:22:41 +0000 |
commit | a36ac0a2e78adc0752a46eb01b7e048272241769 (patch) | |
tree | 7d2c6371e62f05383664ee9a4ebee4b1b9de209c /tool | |
parent | 417069f8b2fd6dd4f8c2f5f69de7c038a2397050 (diff) | |
download | boringssl-a36ac0a2e78adc0752a46eb01b7e048272241769.zip boringssl-a36ac0a2e78adc0752a46eb01b7e048272241769.tar.gz boringssl-a36ac0a2e78adc0752a46eb01b7e048272241769.tar.bz2 |
Use std::make_unique when possible
We've required C++14 for a while now. As we're mostly C with a little
C++, this is less helpful, but may as well avoid bare new where
possible.
Change-Id: Icf3386e3f3b6f2092bb0089ed874cc50985f1a40
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/61429
Reviewed-by: Bob Beck <bbe@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
Diffstat (limited to 'tool')
-rw-r--r-- | tool/digest.cc | 2 | ||||
-rw-r--r-- | tool/pkcs12.cc | 2 | ||||
-rw-r--r-- | tool/sign.cc | 2 | ||||
-rw-r--r-- | tool/speed.cc | 21 |
4 files changed, 13 insertions, 14 deletions
diff --git a/tool/digest.cc b/tool/digest.cc index d810928..e66f013 100644 --- a/tool/digest.cc +++ b/tool/digest.cc @@ -115,7 +115,7 @@ static bool SumFile(std::string *out_hex, const EVP_MD *md, } static const size_t kBufSize = 8192; - std::unique_ptr<uint8_t[]> buf(new uint8_t[kBufSize]); + auto buf = std::make_unique<uint8_t[]>(kBufSize); bssl::ScopedEVP_MD_CTX ctx; if (!EVP_DigestInit_ex(ctx.get(), md, NULL)) { diff --git a/tool/pkcs12.cc b/tool/pkcs12.cc index 3d8a1cd..c19fd3a 100644 --- a/tool/pkcs12.cc +++ b/tool/pkcs12.cc @@ -72,7 +72,7 @@ bool DoPKCS12(const std::vector<std::string> &args) { } const size_t size = st.st_size; - std::unique_ptr<uint8_t[]> contents(new uint8_t[size]); + auto contents = std::make_unique<uint8_t[]>(size); size_t off = 0; while (off < size) { size_t bytes_read; diff --git a/tool/sign.cc b/tool/sign.cc index a511e8d..038d853 100644 --- a/tool/sign.cc +++ b/tool/sign.cc @@ -68,7 +68,7 @@ bool Sign(const std::vector<std::string> &args) { } size_t sig_len = EVP_PKEY_size(key.get()); - std::unique_ptr<uint8_t[]> sig(new uint8_t[sig_len]); + auto sig = std::make_unique<uint8_t[]>(sig_len); if (!EVP_DigestSign(ctx.get(), sig.get(), &sig_len, data.data(), data.size())) { return false; diff --git a/tool/speed.cc b/tool/speed.cc index 8b4b13c..089a460 100644 --- a/tool/speed.cc +++ b/tool/speed.cc @@ -476,22 +476,21 @@ static bool SpeedAEADChunk(const EVP_AEAD *aead, std::string name, const size_t nonce_len = EVP_AEAD_nonce_length(aead); const size_t overhead_len = EVP_AEAD_max_overhead(aead); - std::unique_ptr<uint8_t[]> key(new uint8_t[key_len]); + auto key = std::make_unique<uint8_t[]>(key_len); OPENSSL_memset(key.get(), 0, key_len); - std::unique_ptr<uint8_t[]> nonce(new uint8_t[nonce_len]); + auto nonce = std::make_unique<uint8_t[]>(nonce_len); OPENSSL_memset(nonce.get(), 0, nonce_len); - std::unique_ptr<uint8_t[]> in_storage(new uint8_t[chunk_len + kAlignment]); + auto in_storage = std::make_unique<uint8_t[]>(chunk_len + kAlignment); // N.B. for EVP_AEAD_CTX_seal_scatter the input and output buffers may be the // same size. However, in the direction == evp_aead_open case we still use // non-scattering seal, hence we add overhead_len to the size of this buffer. - std::unique_ptr<uint8_t[]> out_storage( - new uint8_t[chunk_len + overhead_len + kAlignment]); - std::unique_ptr<uint8_t[]> in2_storage( - new uint8_t[chunk_len + overhead_len + kAlignment]); - std::unique_ptr<uint8_t[]> ad(new uint8_t[ad_len]); + auto out_storage = + std::make_unique<uint8_t[]>(chunk_len + overhead_len + kAlignment); + auto in2_storage = + std::make_unique<uint8_t[]>(chunk_len + overhead_len + kAlignment); + auto ad = std::make_unique<uint8_t[]>(ad_len); OPENSSL_memset(ad.get(), 0, ad_len); - std::unique_ptr<uint8_t[]> tag_storage( - new uint8_t[overhead_len + kAlignment]); + auto tag_storage = std::make_unique<uint8_t[]>(overhead_len + kAlignment); uint8_t *const in = @@ -760,7 +759,7 @@ static bool SpeedECDHCurve(const std::string &name, int nid, if (peer_value_len == 0) { return false; } - std::unique_ptr<uint8_t[]> peer_value(new uint8_t[peer_value_len]); + auto peer_value = std::make_unique<uint8_t[]>(peer_value_len); peer_value_len = EC_POINT_point2oct( EC_KEY_get0_group(peer_key.get()), EC_KEY_get0_public_key(peer_key.get()), POINT_CONVERSION_UNCOMPRESSED, peer_value.get(), peer_value_len, nullptr); |