diff options
73 files changed, 164 insertions, 159 deletions
diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index a6191eaeb..6f945a9e7 100644 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -63,7 +63,7 @@ int Command::run(const std::vector<std::string>& params) { const std::string output_file = get_arg("output"); - if(output_file != "") + if(!output_file.empty()) { m_output_stream.reset(new std::ofstream(output_file, std::ios::binary)); if(!m_output_stream->good()) @@ -75,7 +75,7 @@ int Command::run(const std::vector<std::string>& params) { const std::string output_file = get_arg("error-output"); - if(output_file != "") + if(!output_file.empty()) { m_error_output_stream.reset(new std::ofstream(output_file, std::ios::binary)); if(!m_error_output_stream->good()) diff --git a/src/cli/cli_rng.cpp b/src/cli/cli_rng.cpp index 064286d55..ee441cf28 100644 --- a/src/cli/cli_rng.cpp +++ b/src/cli/cli_rng.cpp @@ -50,7 +50,7 @@ cli_make_rng(const std::string& rng_type, const std::string& hex_drbg_seed) else rng = std::make_unique<Botan::AutoSeeded_RNG>(); - if(drbg_seed.size() > 0) + if(!drbg_seed.empty()) rng->add_entropy(drbg_seed.data(), drbg_seed.size()); return rng; } diff --git a/src/cli/pk_crypt.cpp b/src/cli/pk_crypt.cpp index 5be2f7d1b..0fbeb186d 100644 --- a/src/cli/pk_crypt.cpp +++ b/src/cli/pk_crypt.cpp @@ -160,7 +160,7 @@ class PK_Decrypt final : public Command } const std::string aead_algo = Botan::OIDS::oid2str_or_empty(aead_oid); - if(aead_algo == "") + if(aead_algo.empty()) { error_output() << "Ciphertext was encrypted with an unknown algorithm"; return set_return_code(1); diff --git a/src/cli/pubkey.cpp b/src/cli/pubkey.cpp index 8b31327ec..2faff835f 100644 --- a/src/cli/pubkey.cpp +++ b/src/cli/pubkey.cpp @@ -500,14 +500,14 @@ class Gen_DL_Group final : public Command if(type == "strong") { - if(seed_str.size() > 0) + if(!seed_str.empty()) { throw CLI_Usage_Error("Seed only supported for DSA param gen"); } Botan::DL_Group grp(rng(), Botan::DL_Group::Strong, pbits); output() << grp.PEM_encode(Botan::DL_Group_Format::ANSI_X9_42); } else if(type == "subgroup") { - if(seed_str.size() > 0) + if(!seed_str.empty()) { throw CLI_Usage_Error("Seed only supported for DSA param gen"); } Botan::DL_Group grp(rng(), Botan::DL_Group::Prime_Subgroup, pbits, qbits); output() << grp.PEM_encode(Botan::DL_Group_Format::ANSI_X9_42); diff --git a/src/cli/speed.cpp b/src/cli/speed.cpp index a0b940135..605953389 100644 --- a/src/cli/speed.cpp +++ b/src/cli/speed.cpp @@ -211,7 +211,7 @@ class Summary final std::ostringstream result_ss; result_ss << std::fixed; - if(m_bps_entries.size() > 0) + if(!m_bps_entries.empty()) { result_ss << "\n"; @@ -254,7 +254,7 @@ class Summary final result_ss << "\n[results are the number of 1000s bytes processed per second]\n"; } - if(m_ops_entries.size() > 0) + if(!m_ops_entries.empty()) { result_ss << std::setprecision(6) << "\n"; @@ -509,7 +509,7 @@ class Speed final : public Command // Since everything might be disabled, need a block to else if from } #if defined(BOTAN_HAS_HASH) - else if(Botan::HashFunction::providers(algo).size() > 0) + else if(!Botan::HashFunction::providers(algo).empty()) { bench_providers_of<Botan::HashFunction>( algo, provider, msec, buf_sizes, @@ -517,7 +517,7 @@ class Speed final : public Command } #endif #if defined(BOTAN_HAS_BLOCK_CIPHER) - else if(Botan::BlockCipher::providers(algo).size() > 0) + else if(!Botan::BlockCipher::providers(algo).empty()) { bench_providers_of<Botan::BlockCipher>( algo, provider, msec, buf_sizes, @@ -525,7 +525,7 @@ class Speed final : public Command } #endif #if defined(BOTAN_HAS_STREAM_CIPHER) - else if(Botan::StreamCipher::providers(algo).size() > 0) + else if(!Botan::StreamCipher::providers(algo).empty()) { bench_providers_of<Botan::StreamCipher>( algo, provider, msec, buf_sizes, @@ -540,7 +540,7 @@ class Speed final : public Command } #endif #if defined(BOTAN_HAS_MAC) - else if(Botan::MessageAuthenticationCode::providers(algo).size() > 0) + else if(!Botan::MessageAuthenticationCode::providers(algo).empty()) { bench_providers_of<Botan::MessageAuthenticationCode>( algo, provider, msec, buf_sizes, @@ -1049,7 +1049,7 @@ class Speed final : public Command decrypt_timer->run([&]() { dec.start(iv); dec.finish(buffer); }); - if(iv.size() > 0) + if(!iv.empty()) { iv[iv.size()-1] += 1; } diff --git a/src/cli/timing_tests.cpp b/src/cli/timing_tests.cpp index d1ebc79c3..c044e5111 100644 --- a/src/cli/timing_tests.cpp +++ b/src/cli/timing_tests.cpp @@ -516,7 +516,7 @@ class Timing_Test_Command final : public Command std::string line; while(std::getline(infile, line)) { - if(line.size() > 0 && line.at(0) != '#') + if(!line.empty() && line.at(0) != '#') { lines.push_back(line); } diff --git a/src/cli/tls_client.cpp b/src/cli/tls_client.cpp index be5f7dfcd..ef355fb74 100644 --- a/src/cli/tls_client.cpp +++ b/src/cli/tls_client.cpp @@ -139,7 +139,7 @@ class TLS_Client final : public Command, public Botan::TLS::Callbacks if(first_active && !protocols_to_offer.empty()) { std::string app = client.application_protocol(); - if(app != "") + if(!app.empty()) { output() << "Server choose protocol: " << client.application_protocol() << "\n"; } @@ -296,7 +296,7 @@ class TLS_Client final : public Command, public Botan::TLS::Callbacks { auto status = result.all_statuses(); - if(status.size() > 0 && status[0].count(Botan::Certificate_Status_Code::OCSP_RESPONSE_GOOD)) + if(!status.empty() && status[0].count(Botan::Certificate_Status_Code::OCSP_RESPONSE_GOOD)) { output() << "Valid OCSP response for this server\n"; } diff --git a/src/lib/asn1/asn1_oid.cpp b/src/lib/asn1/asn1_oid.cpp index 460882777..9844f842a 100644 --- a/src/lib/asn1/asn1_oid.cpp +++ b/src/lib/asn1/asn1_oid.cpp @@ -69,7 +69,7 @@ OID OID::from_string(const std::string& str) std::vector<uint32_t> raw = parse_oid_str(str); - if(raw.size() > 0) + if(!raw.empty()) return OID(std::move(raw)); throw Lookup_Error("No OID associated with name " + str); diff --git a/src/lib/asn1/asn1_print.cpp b/src/lib/asn1/asn1_print.cpp index 1a1654fef..da0b54768 100644 --- a/src/lib/asn1/asn1_print.cpp +++ b/src/lib/asn1/asn1_print.cpp @@ -294,7 +294,7 @@ std::string ASN1_Pretty_Printer::format(ASN1_Type type_tag, << ", l=" << std::setw(4) << length << ":" << std::string(level + 1, ' ') << format_type(type_tag, class_tag); - if(value != "" && !should_skip) + if(!value.empty() && !should_skip) { const size_t current_pos = static_cast<size_t>(oss.tellp()); const size_t spaces_to_align = diff --git a/src/lib/asn1/der_enc.cpp b/src/lib/asn1/der_enc.cpp index e40b492d8..cc83ba67c 100644 --- a/src/lib/asn1/der_enc.cpp +++ b/src/lib/asn1/der_enc.cpp @@ -154,7 +154,7 @@ DER_Encoder::DER_Sequence::DER_Sequence(ASN1_Type t1, ASN1_Class t2) : */ secure_vector<uint8_t> DER_Encoder::get_contents() { - if(m_subsequences.size() != 0) + if(!m_subsequences.empty()) throw Invalid_State("DER_Encoder: Sequence hasn't been marked done"); if(m_append_output) @@ -167,7 +167,7 @@ secure_vector<uint8_t> DER_Encoder::get_contents() std::vector<uint8_t> DER_Encoder::get_contents_unlocked() { - if(m_subsequences.size() != 0) + if(!m_subsequences.empty()) throw Invalid_State("DER_Encoder: Sequence hasn't been marked done"); if(m_append_output) @@ -230,7 +230,7 @@ DER_Encoder& DER_Encoder::end_explicit() */ DER_Encoder& DER_Encoder::raw_bytes(const uint8_t bytes[], size_t length) { - if(m_subsequences.size()) + if(!m_subsequences.empty()) { m_subsequences[m_subsequences.size()-1].add_bytes(bytes, length); } @@ -256,7 +256,7 @@ DER_Encoder& DER_Encoder::add_object(ASN1_Type type_tag, ASN1_Class class_tag, encode_tag(hdr, type_tag, class_tag); encode_length(hdr, length); - if(m_subsequences.size()) + if(!m_subsequences.empty()) { m_subsequences[m_subsequences.size()-1].add_bytes(hdr.data(), hdr.size(), rep, length); } diff --git a/src/lib/block/aria/aria.cpp b/src/lib/block/aria/aria.cpp index 5326cf1a9..6ba443257 100644 --- a/src/lib/block/aria/aria.cpp +++ b/src/lib/block/aria/aria.cpp @@ -422,37 +422,37 @@ void key_schedule(secure_vector<uint32_t>& ERK, void ARIA_128::encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const { - verify_key_set(m_ERK.size() > 0); + verify_key_set(!m_ERK.empty()); ARIA_F::transform(in, out, blocks, m_ERK); } void ARIA_192::encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const { - verify_key_set(m_ERK.size() > 0); + verify_key_set(!m_ERK.empty()); ARIA_F::transform(in, out, blocks, m_ERK); } void ARIA_256::encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const { - verify_key_set(m_ERK.size() > 0); + verify_key_set(!m_ERK.empty()); ARIA_F::transform(in, out, blocks, m_ERK); } void ARIA_128::decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const { - verify_key_set(m_DRK.size() > 0); + verify_key_set(!m_DRK.empty()); ARIA_F::transform(in, out, blocks, m_DRK); } void ARIA_192::decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const { - verify_key_set(m_DRK.size() > 0); + verify_key_set(!m_DRK.empty()); ARIA_F::transform(in, out, blocks, m_DRK); } void ARIA_256::decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const { - verify_key_set(m_DRK.size() > 0); + verify_key_set(!m_DRK.empty()); ARIA_F::transform(in, out, blocks, m_DRK); } diff --git a/src/lib/entropy/rdseed/rdseed.cpp b/src/lib/entropy/rdseed/rdseed.cpp index fe6669ee2..db27d9747 100644 --- a/src/lib/entropy/rdseed/rdseed.cpp +++ b/src/lib/entropy/rdseed/rdseed.cpp @@ -83,7 +83,7 @@ size_t Intel_Rdseed::poll(RandomNumberGenerator& rng) break; } - if(seed.size() > 0) + if(!seed.empty()) { rng.add_entropy(reinterpret_cast<const uint8_t*>(seed.data()), seed.size() * sizeof(uint32_t)); diff --git a/src/lib/ffi/ffi.cpp b/src/lib/ffi/ffi.cpp index 9f21533c6..6a042756c 100644 --- a/src/lib/ffi/ffi.cpp +++ b/src/lib/ffi/ffi.cpp @@ -23,7 +23,7 @@ int ffi_error_exception_thrown(const char* func_name, const char* exn, int rc) g_last_exception_what.assign(exn); std::string val; - if(Botan::OS::read_env_variable(val, "BOTAN_FFI_PRINT_EXCEPTIONS") == true && val != "") + if(Botan::OS::read_env_variable(val, "BOTAN_FFI_PRINT_EXCEPTIONS") == true && !val.empty()) { std::fprintf(stderr, "in %s exception '%s' returning %d\n", func_name, exn, rc); } diff --git a/src/lib/filters/filter.cpp b/src/lib/filters/filter.cpp index 6653fc781..3a0aae3ee 100644 --- a/src/lib/filters/filter.cpp +++ b/src/lib/filters/filter.cpp @@ -33,7 +33,7 @@ void Filter::send(const uint8_t input[], size_t length) for(size_t j = 0; j != total_ports(); ++j) if(m_next[j]) { - if(m_write_queue.size()) + if(!m_write_queue.empty()) m_next[j]->write(m_write_queue.data(), m_write_queue.size()); m_next[j]->write(input, length); nothing_attached = false; diff --git a/src/lib/filters/out_buf.cpp b/src/lib/filters/out_buf.cpp index 0473477ac..aa66fbd4e 100644 --- a/src/lib/filters/out_buf.cpp +++ b/src/lib/filters/out_buf.cpp @@ -77,12 +77,14 @@ void Output_Buffers::add(SecureQueue* queue) void Output_Buffers::retire() { for(size_t i = 0; i != m_buffers.size(); ++i) - if(m_buffers[i] && m_buffers[i]->size() == 0) + { + if(m_buffers[i] && m_buffers[i]->empty()) { m_buffers[i].reset(); } + } - while(m_buffers.size() && !m_buffers[0]) + while(!m_buffers.empty() && !m_buffers[0]) { m_buffers.pop_front(); m_offset = m_offset + Pipe::message_id(1); diff --git a/src/lib/filters/threaded_fork.cpp b/src/lib/filters/threaded_fork.cpp index 2d77f9fd1..16206bfa2 100644 --- a/src/lib/filters/threaded_fork.cpp +++ b/src/lib/filters/threaded_fork.cpp @@ -101,7 +101,7 @@ void Threaded_Fork::set_next(Filter* f[], size_t n) void Threaded_Fork::send(const uint8_t input[], size_t length) { - if(m_write_queue.size()) + if(!m_write_queue.empty()) thread_delegate_work(m_write_queue.data(), m_write_queue.size()); thread_delegate_work(input, length); diff --git a/src/lib/hash/skein/skein_512.cpp b/src/lib/hash/skein/skein_512.cpp index 7689b5004..800bf3239 100644 --- a/src/lib/hash/skein/skein_512.cpp +++ b/src/lib/hash/skein/skein_512.cpp @@ -27,7 +27,7 @@ Skein_512::Skein_512(size_t arg_output_bits, std::string Skein_512::name() const { - if(m_personalization != "") + if(!m_personalization.empty()) return "Skein-512(" + std::to_string(m_output_bits) + "," + m_personalization + ")"; return "Skein-512(" + std::to_string(m_output_bits) + ")"; @@ -78,7 +78,7 @@ void Skein_512::initial_block() reset_tweak(SKEIN_CONFIG, true); ubi_512(config_str, sizeof(config_str)); - if(m_personalization != "") + if(!m_personalization.empty()) { /* This is a limitation of this implementation, and not of the diff --git a/src/lib/math/bigint/big_code.cpp b/src/lib/math/bigint/big_code.cpp index f908e92ab..46855b969 100644 --- a/src/lib/math/bigint/big_code.cpp +++ b/src/lib/math/bigint/big_code.cpp @@ -59,7 +59,7 @@ std::string BigInt::to_dec_string() const } // remove leading zeros - while(digits.size() > 0 && digits.back() == 0) + while(!digits.empty() && digits.back() == 0) { digits.pop_back(); } diff --git a/src/lib/math/numbertheory/monty.cpp b/src/lib/math/numbertheory/monty.cpp index 893f3212a..4d4dffa71 100644 --- a/src/lib/math/numbertheory/monty.cpp +++ b/src/lib/math/numbertheory/monty.cpp @@ -8,6 +8,8 @@ #include <botan/reducer.h> #include <botan/internal/mp_core.h> +#include <utility> + namespace Botan { word monty_inverse(word a) @@ -249,7 +251,7 @@ void Montgomery_Params::square_this(BigInt& x, copy_mem(x.mutable_data(), z_data, output_size); } -Montgomery_Int::Montgomery_Int(const std::shared_ptr<const Montgomery_Params> params, +Montgomery_Int::Montgomery_Int(const std::shared_ptr<const Montgomery_Params>& params, const BigInt& v, bool redc_needed) : m_params(params) @@ -266,7 +268,7 @@ Montgomery_Int::Montgomery_Int(const std::shared_ptr<const Montgomery_Params> pa } } -Montgomery_Int::Montgomery_Int(std::shared_ptr<const Montgomery_Params> params, +Montgomery_Int::Montgomery_Int(const std::shared_ptr<const Montgomery_Params>& params, const uint8_t bits[], size_t len, bool redc_needed) : m_params(params), @@ -283,7 +285,7 @@ Montgomery_Int::Montgomery_Int(std::shared_ptr<const Montgomery_Params> params, Montgomery_Int::Montgomery_Int(std::shared_ptr<const Montgomery_Params> params, const word words[], size_t len, bool redc_needed) : - m_params(params) + m_params(std::move(params)) { m_v.set_words(words, len); diff --git a/src/lib/math/numbertheory/monty.h b/src/lib/math/numbertheory/monty.h index 5a2cb0964..9d1078572 100644 --- a/src/lib/math/numbertheory/monty.h +++ b/src/lib/math/numbertheory/monty.h @@ -36,14 +36,14 @@ class BOTAN_TEST_API Montgomery_Int final /** * Create a Montgomery_Int */ - Montgomery_Int(std::shared_ptr<const Montgomery_Params> params, + Montgomery_Int(const std::shared_ptr<const Montgomery_Params>& params, const BigInt& v, bool redc_needed = true); /** * Create a Montgomery_Int */ - Montgomery_Int(std::shared_ptr<const Montgomery_Params> params, + Montgomery_Int(const std::shared_ptr<const Montgomery_Params>& params, const uint8_t bits[], size_t len, bool redc_needed = true); diff --git a/src/lib/math/numbertheory/monty_exp.cpp b/src/lib/math/numbertheory/monty_exp.cpp index 0c17bc2bd..41d6c1954 100644 --- a/src/lib/math/numbertheory/monty_exp.cpp +++ b/src/lib/math/numbertheory/monty_exp.cpp @@ -18,7 +18,7 @@ namespace Botan { class Montgomery_Exponentation_State { public: - Montgomery_Exponentation_State(std::shared_ptr<const Montgomery_Params> params, + Montgomery_Exponentation_State(const std::shared_ptr<const Montgomery_Params>& params, const BigInt& g, size_t window_bits, bool const_time); @@ -32,10 +32,11 @@ class Montgomery_Exponentation_State size_t m_window_bits; }; -Montgomery_Exponentation_State::Montgomery_Exponentation_State(std::shared_ptr<const Montgomery_Params> params, - const BigInt& g, - size_t window_bits, - bool const_time) : +Montgomery_Exponentation_State::Montgomery_Exponentation_State( + const std::shared_ptr<const Montgomery_Params>& params, + const BigInt& g, + size_t window_bits, + bool const_time) : m_params(params), m_window_bits(window_bits == 0 ? 4 : window_bits) { @@ -150,7 +151,7 @@ BigInt Montgomery_Exponentation_State::exponentiation_vartime(const BigInt& scal } std::shared_ptr<const Montgomery_Exponentation_State> -monty_precompute(std::shared_ptr<const Montgomery_Params> params, +monty_precompute(const std::shared_ptr<const Montgomery_Params>& params, const BigInt& g, size_t window_bits, bool const_time) @@ -170,7 +171,7 @@ BigInt monty_execute_vartime(const Montgomery_Exponentation_State& precomputed_s return precomputed_state.exponentiation_vartime(k); } -BigInt monty_multi_exp(std::shared_ptr<const Montgomery_Params> params_p, +BigInt monty_multi_exp(const std::shared_ptr<const Montgomery_Params>& params_p, const BigInt& x_bn, const BigInt& z1, const BigInt& y_bn, diff --git a/src/lib/math/numbertheory/monty_exp.h b/src/lib/math/numbertheory/monty_exp.h index 091815a6e..c0cafb3c7 100644 --- a/src/lib/math/numbertheory/monty_exp.h +++ b/src/lib/math/numbertheory/monty_exp.h @@ -22,7 +22,7 @@ class Montgomery_Exponentation_State; * Precompute for calculating values g^x mod p */ std::shared_ptr<const Montgomery_Exponentation_State> -monty_precompute(std::shared_ptr<const Montgomery_Params> params_p, +monty_precompute(const std::shared_ptr<const Montgomery_Params>& params_p, const BigInt& g, size_t window_bits, bool const_time = true); @@ -59,7 +59,7 @@ BigInt monty_exp_vartime(std::shared_ptr<const Montgomery_Params> params_p, /** * Return (x^z1 * y^z2) % p */ -BigInt monty_multi_exp(std::shared_ptr<const Montgomery_Params> params_p, +BigInt monty_multi_exp(const std::shared_ptr<const Montgomery_Params>& params_p, const BigInt& x, const BigInt& z1, const BigInt& y, diff --git a/src/lib/misc/roughtime/roughtime.cpp b/src/lib/misc/roughtime/roughtime.cpp index 21cdda2a2..e953c87be 100644 --- a/src/lib/misc/roughtime/roughtime.cpp +++ b/src/lib/misc/roughtime/roughtime.cpp @@ -452,7 +452,7 @@ std::vector<Server_Information> servers_from_str(const std::string& str) } } (); - if(addresses.size() == 0) + if(addresses.empty()) { throw Decoding_Error(ERROR_MESSAGE); } diff --git a/src/lib/modes/aead/ccm/ccm.cpp b/src/lib/modes/aead/ccm/ccm.cpp index 5ae52eced..88f943894 100644 --- a/src/lib/modes/aead/ccm/ccm.cpp +++ b/src/lib/modes/aead/ccm/ccm.cpp @@ -109,7 +109,7 @@ void CCM_Mode::start_msg(const uint8_t nonce[], size_t nonce_len) size_t CCM_Mode::process(uint8_t buf[], size_t sz) { - BOTAN_STATE_CHECK(m_nonce.size() > 0); + BOTAN_STATE_CHECK(!m_nonce.empty()); m_msg_buf.insert(m_msg_buf.end(), buf, buf + sz); return 0; // no output until finished } @@ -141,7 +141,7 @@ secure_vector<uint8_t> CCM_Mode::format_b0(size_t sz) secure_vector<uint8_t> B0(CCM_BS); const uint8_t b_flags = - static_cast<uint8_t>((m_ad_buf.size() ? 64 : 0) + (((tag_size()/2)-1) << 3) + (L()-1)); + static_cast<uint8_t>((!m_ad_buf.empty() ? 64 : 0) + (((tag_size()/2)-1) << 3) + (L()-1)); B0[0] = b_flags; copy_mem(&B0[1], m_nonce.data(), m_nonce.size()); diff --git a/src/lib/modes/aead/eax/eax.cpp b/src/lib/modes/aead/eax/eax.cpp index fc1e82b25..9cdb733c7 100644 --- a/src/lib/modes/aead/eax/eax.cpp +++ b/src/lib/modes/aead/eax/eax.cpp @@ -123,7 +123,7 @@ void EAX_Mode::start_msg(const uint8_t nonce[], size_t nonce_len) size_t EAX_Encryption::process(uint8_t buf[], size_t sz) { - BOTAN_STATE_CHECK(m_nonce_mac.size() > 0); + BOTAN_STATE_CHECK(!m_nonce_mac.empty()); m_ctr->cipher(buf, buf, sz); m_cmac->update(buf, sz); return sz; @@ -149,7 +149,7 @@ void EAX_Encryption::finish(secure_vector<uint8_t>& buffer, size_t offset) size_t EAX_Decryption::process(uint8_t buf[], size_t sz) { - BOTAN_STATE_CHECK(m_nonce_mac.size() > 0); + BOTAN_STATE_CHECK(!m_nonce_mac.empty()); m_cmac->update(buf, sz); m_ctr->cipher(buf, buf, sz); return sz; diff --git a/src/lib/modes/aead/siv/siv.cpp b/src/lib/modes/aead/siv/siv.cpp index daa097039..54dfa68e6 100644 --- a/src/lib/modes/aead/siv/siv.cpp +++ b/src/lib/modes/aead/siv/siv.cpp @@ -127,7 +127,7 @@ secure_vector<uint8_t> SIV_Mode::S2V(const uint8_t* text, size_t text_len) V ^= m_ad_macs[i]; } - if(m_nonce.size()) + if(!m_nonce.empty()) { poly_double_n(V.data(), V.size()); V ^= m_nonce; @@ -178,7 +178,7 @@ void SIV_Decryption::finish(secure_vector<uint8_t>& buffer, size_t offset) { BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane"); - if(msg_buf().size() > 0) + if(!msg_buf().empty()) { buffer.insert(buffer.begin() + offset, msg_buf().begin(), msg_buf().end()); msg_buf().clear(); diff --git a/src/lib/passhash/argon2fmt/argon2fmt.cpp b/src/lib/passhash/argon2fmt/argon2fmt.cpp index acad2f754..2959d1459 100644 --- a/src/lib/passhash/argon2fmt/argon2fmt.cpp +++ b/src/lib/passhash/argon2fmt/argon2fmt.cpp @@ -17,7 +17,7 @@ namespace { std::string strip_padding(std::string s) { - while(s.size() > 0 && s[s.size()-1] == '=') + while(!s.empty() && s[s.size()-1] == '=') s.resize(s.size() - 1); return s; } diff --git a/src/lib/passhash/bcrypt/bcrypt.cpp b/src/lib/passhash/bcrypt/bcrypt.cpp index 3cbb8f45d..9c2ca3f81 100644 --- a/src/lib/passhash/bcrypt/bcrypt.cpp +++ b/src/lib/passhash/bcrypt/bcrypt.cpp @@ -77,7 +77,7 @@ std::string bcrypt_base64_encode(const uint8_t input[], size_t length) { std::string b64 = base64_encode(input, length); - while(b64.size() && b64[b64.size()-1] == '=') + while(!b64.empty() && b64[b64.size()-1] == '=') b64 = b64.substr(0, b64.size() - 1); for(size_t i = 0; i != b64.size(); ++i) diff --git a/src/lib/pubkey/ec_group/ec_group.cpp b/src/lib/pubkey/ec_group/ec_group.cpp index d43c6a76a..30373cd55 100644 --- a/src/lib/pubkey/ec_group/ec_group.cpp +++ b/src/lib/pubkey/ec_group/ec_group.cpp @@ -437,7 +437,7 @@ EC_Group::EC_Group(const OID& domain_oid) EC_Group::EC_Group(const std::string& str) { - if(str == "") + if(str.empty()) return; // no initialization / uninitialized try diff --git a/src/lib/pubkey/ed25519/ed25519_key.cpp b/src/lib/pubkey/ed25519/ed25519_key.cpp index f3957d89e..e723d6590 100644 --- a/src/lib/pubkey/ed25519/ed25519_key.cpp +++ b/src/lib/pubkey/ed25519/ed25519_key.cpp @@ -297,7 +297,7 @@ Ed25519_PublicKey::create_verification_op(const std::string& params, { if(provider == "base" || provider.empty()) { - if(params == "" || params == "Identity" || params == "Pure") + if(params.empty() || params == "Identity" || params == "Pure") return std::make_unique<Ed25519_Pure_Verify_Operation>(*this); else if(params == "Ed25519ph") return std::make_unique<Ed25519_Hashed_Verify_Operation>(*this, "SHA-512", true); @@ -314,7 +314,7 @@ Ed25519_PrivateKey::create_signature_op(RandomNumberGenerator&, { if(provider == "base" || provider.empty()) { - if(params == "" || params == "Identity" || params == "Pure") + if(params.empty() || params == "Identity" || params == "Pure") return std::make_unique<Ed25519_Pure_Sign_Operation>(*this); else if(params == "Ed25519ph") return std::make_unique<Ed25519_Hashed_Sign_Operation>(*this, "SHA-512", true); diff --git a/src/lib/pubkey/mce/code_based_key_gen.cpp b/src/lib/pubkey/mce/code_based_key_gen.cpp index ab965eff7..e9ebe1784 100644 --- a/src/lib/pubkey/mce/code_based_key_gen.cpp +++ b/src/lib/pubkey/mce/code_based_key_gen.cpp @@ -182,7 +182,7 @@ std::unique_ptr<binary_matrix> generate_R(std::vector<gf2m> &L, polyn_gf2m* g, c }//The H matrix is fed. secure_vector<size_t> perm = H.row_reduced_echelon_form(); - if(perm.size() == 0) + if(perm.empty()) { throw Invalid_State("McEliece keygen failed - could not bring matrix to row reduced echelon form"); } diff --git a/src/lib/pubkey/mce/polyn_gf2m.cpp b/src/lib/pubkey/mce/polyn_gf2m.cpp index 508c7c6e5..ffe1d49fc 100644 --- a/src/lib/pubkey/mce/polyn_gf2m.cpp +++ b/src/lib/pubkey/mce/polyn_gf2m.cpp @@ -97,7 +97,7 @@ polyn_gf2m::polyn_gf2m(polyn_gf2m const& other) polyn_gf2m::polyn_gf2m(int d, const std::shared_ptr<GF2m_Field>& sp_field) :m_deg(-1), coeff(d+1), - m_sp_field(std::move(sp_field)) + m_sp_field(sp_field) { } diff --git a/src/lib/pubkey/pem/pem.cpp b/src/lib/pubkey/pem/pem.cpp index d2433860d..6fbde7210 100644 --- a/src/lib/pubkey/pem/pem.cpp +++ b/src/lib/pubkey/pem/pem.cpp @@ -27,7 +27,7 @@ std::string linewrap(size_t width, const std::string& in) } out.push_back(in[i]); } - if(out.size() > 0 && out[out.size()-1] != '\n') + if(!out.empty() && out[out.size()-1] != '\n') { out.push_back('\n'); } diff --git a/src/lib/pubkey/pkcs8.cpp b/src/lib/pubkey/pkcs8.cpp index e910d79ee..73210f426 100644 --- a/src/lib/pubkey/pkcs8.cpp +++ b/src/lib/pubkey/pkcs8.cpp @@ -335,11 +335,11 @@ namespace { */ std::unique_ptr<Private_Key> load_key(DataSource& source, - std::function<std::string ()> get_pass, + const std::function<std::string ()>& get_pass, bool is_encrypted) { AlgorithmIdentifier alg_id; - secure_vector<uint8_t> pkcs8_key = PKCS8_decode(source, std::move(get_pass), alg_id, is_encrypted); + secure_vector<uint8_t> pkcs8_key = PKCS8_decode(source, get_pass, alg_id, is_encrypted); const std::string alg_name = OIDS::oid2str_or_empty(alg_id.get_oid()); if(alg_name.empty()) diff --git a/src/lib/rng/hmac_drbg/hmac_drbg.cpp b/src/lib/rng/hmac_drbg/hmac_drbg.cpp index 2b66a839c..024e8c27e 100644 --- a/src/lib/rng/hmac_drbg/hmac_drbg.cpp +++ b/src/lib/rng/hmac_drbg/hmac_drbg.cpp @@ -119,7 +119,7 @@ HMAC_DRBG::HMAC_DRBG(const std::string& hmac_hash) : void HMAC_DRBG::clear_state() { - if(m_V.size() == 0) + if(m_V.empty()) { const size_t output_length = m_mac->output_length(); m_V.resize(output_length); diff --git a/src/lib/tls/msg_cert_req.cpp b/src/lib/tls/msg_cert_req.cpp index ea9ae3711..a621c9c39 100644 --- a/src/lib/tls/msg_cert_req.cpp +++ b/src/lib/tls/msg_cert_req.cpp @@ -124,7 +124,7 @@ std::vector<uint8_t> Certificate_Req::serialize() const append_tls_length_value(buf, cert_types, 1); - if(m_schemes.size() > 0) + if(!m_schemes.empty()) buf += Signature_Algorithms(m_schemes).serialize(Connection_Side::SERVER); std::vector<uint8_t> encoded_names; diff --git a/src/lib/tls/msg_certificate.cpp b/src/lib/tls/msg_certificate.cpp index b49ffeb3d..3815c981a 100644 --- a/src/lib/tls/msg_certificate.cpp +++ b/src/lib/tls/msg_certificate.cpp @@ -72,7 +72,7 @@ Certificate::Certificate(const std::vector<uint8_t>& buf, const Policy& policy) * the intermediates are outside of the control of the server. * But, require that the leaf certificate be v3 */ - if(m_certs.size() > 0 && m_certs[0].x509_version() != 3) + if(!m_certs.empty() && m_certs[0].x509_version() != 3) { throw TLS_Exception(Alert::BAD_CERTIFICATE, "The leaf certificate must be v3"); diff --git a/src/lib/tls/msg_client_hello.cpp b/src/lib/tls/msg_client_hello.cpp index f04b80989..9d7b09f61 100644 --- a/src/lib/tls/msg_client_hello.cpp +++ b/src/lib/tls/msg_client_hello.cpp @@ -63,7 +63,7 @@ Hello_Request::Hello_Request(Handshake_IO& io) */ Hello_Request::Hello_Request(const std::vector<uint8_t>& buf) { - if(buf.size()) + if(!buf.empty()) throw Decoding_Error("Bad Hello_Request, has non-zero size"); } @@ -109,7 +109,7 @@ Client_Hello::Client_Hello(Handshake_IO& io, m_extensions.add(new Supported_Versions(m_version, policy)); - if(client_settings.hostname() != "") + if(!client_settings.hostname().empty()) m_extensions.add(new Server_Name_Indicator(client_settings.hostname())); if(policy.support_cert_status_message()) @@ -125,7 +125,7 @@ Client_Hello::Client_Hello(Handshake_IO& io, auto supported_groups = std::make_unique<Supported_Groups>(policy.key_exchange_groups()); - if(supported_groups->ec_groups().size() > 0) + if(!supported_groups->ec_groups().empty()) { m_extensions.add(new Supported_Point_Formats(policy.use_ecc_point_compression())); } @@ -177,7 +177,7 @@ Client_Hello::Client_Hello(Handshake_IO& io, auto supported_groups = std::make_unique<Supported_Groups>(policy.key_exchange_groups()); - if(supported_groups->ec_groups().size() > 0) + if(!supported_groups->ec_groups().empty()) { m_extensions.add(new Supported_Point_Formats(policy.use_ecc_point_compression())); } diff --git a/src/lib/tls/msg_client_kex.cpp b/src/lib/tls/msg_client_kex.cpp index 469463bf1..f768e48b6 100644 --- a/src/lib/tls/msg_client_kex.cpp +++ b/src/lib/tls/msg_client_kex.cpp @@ -120,7 +120,7 @@ Client_Key_Exchange::Client_Key_Exchange(Handshake_IO& io, const std::string curve_name = state.callbacks().tls_decode_group_param(curve_id); - if(curve_name == "") + if(curve_name.empty()) throw Decoding_Error("Server sent unknown named curve " + std::to_string(static_cast<uint16_t>(curve_id))); diff --git a/src/lib/tls/msg_server_hello.cpp b/src/lib/tls/msg_server_hello.cpp index 9122ce523..a6e9c600e 100644 --- a/src/lib/tls/msg_server_hello.cpp +++ b/src/lib/tls/msg_server_hello.cpp @@ -222,7 +222,7 @@ Server_Hello_Done::Server_Hello_Done(Handshake_IO& io, */ Server_Hello_Done::Server_Hello_Done(const std::vector<uint8_t>& buf) { - if(buf.size()) + if(!buf.empty()) throw Decoding_Error("Server_Hello_Done: Must be empty, and is not"); } diff --git a/src/lib/tls/msg_server_kex.cpp b/src/lib/tls/msg_server_kex.cpp index f022d953d..bf3b2da8b 100644 --- a/src/lib/tls/msg_server_kex.cpp +++ b/src/lib/tls/msg_server_kex.cpp @@ -232,7 +232,7 @@ std::vector<uint8_t> Server_Key_Exchange::serialize() const { std::vector<uint8_t> buf = params(); - if(m_signature.size()) + if(!m_signature.empty()) { if(m_scheme != Signature_Scheme::NONE) { diff --git a/src/lib/tls/tls_channel.cpp b/src/lib/tls/tls_channel.cpp index bdf124767..c96ee8916 100644 --- a/src/lib/tls/tls_channel.cpp +++ b/src/lib/tls/tls_channel.cpp @@ -706,7 +706,7 @@ SymmetricKey Channel::key_material_export(const std::string& label, salt += active->client_hello()->random(); salt += active->server_hello()->random(); - if(context != "") + if(!context.empty()) { size_t context_size = context.length(); if(context_size > 0xFFFF) diff --git a/src/lib/tls/tls_ciphersuite.cpp b/src/lib/tls/tls_ciphersuite.cpp index 4adec977e..0a6426a1d 100644 --- a/src/lib/tls/tls_ciphersuite.cpp +++ b/src/lib/tls/tls_ciphersuite.cpp @@ -118,13 +118,13 @@ namespace { bool have_hash(const std::string& prf) { - return (HashFunction::providers(prf).size() > 0); + return (!HashFunction::providers(prf).empty()); } bool have_cipher(const std::string& cipher) { - return (BlockCipher::providers(cipher).size() > 0) || - (StreamCipher::providers(cipher).size() > 0); + return (!BlockCipher::providers(cipher).empty()) || + (!StreamCipher::providers(cipher).empty()); } } diff --git a/src/lib/tls/tls_client.cpp b/src/lib/tls/tls_client.cpp index 479bfd5c5..fa3ee3e1c 100644 --- a/src/lib/tls/tls_client.cpp +++ b/src/lib/tls/tls_client.cpp @@ -718,7 +718,7 @@ void Client::process_handshake_msg(const Handshake_State* active_state, const bool should_save = save_session(session_info); - if(session_id.size() > 0 && state.is_a_resumption() == false) + if(!session_id.empty() && state.is_a_resumption() == false) { if(should_save) session_manager().save(session_info); diff --git a/src/lib/tls/tls_extensions.cpp b/src/lib/tls/tls_extensions.cpp index 792ebb5fc..d6d2bf55c 100644 --- a/src/lib/tls/tls_extensions.cpp +++ b/src/lib/tls/tls_extensions.cpp @@ -265,7 +265,7 @@ std::vector<uint8_t> Application_Layer_Protocol_Notification::serialize(Connecti { if(p.length() >= 256) throw TLS_Exception(Alert::INTERNAL_ERROR, "ALPN name too long"); - if(p != "") + if(!p.empty()) append_tls_length_value(buf, cast_char_ptr_to_uint8(p.data()), p.size(), @@ -557,7 +557,7 @@ std::vector<uint8_t> Supported_Versions::serialize(Connection_Side whoami) const } else { - BOTAN_ASSERT_NOMSG(m_versions.size() >= 1); + BOTAN_ASSERT_NOMSG(!m_versions.empty()); const uint8_t len = static_cast<uint8_t>(m_versions.size() * 2); buf.push_back(len); diff --git a/src/lib/tls/tls_handshake_io.cpp b/src/lib/tls/tls_handshake_io.cpp index 04dc1fe49..b2370036d 100644 --- a/src/lib/tls/tls_handshake_io.cpp +++ b/src/lib/tls/tls_handshake_io.cpp @@ -106,7 +106,7 @@ Stream_Handshake_IO::format(const std::vector<uint8_t>& msg, store_be24(&send_buf[1], buf_size); - if (msg.size() > 0) + if (!msg.empty()) { copy_mem(&send_buf[4], msg.data(), msg.size()); } @@ -149,7 +149,7 @@ void Datagram_Handshake_IO::retransmit_flight(size_t flight_idx) { const std::vector<uint16_t>& flight = m_flights.at(flight_idx); - BOTAN_ASSERT(flight.size() > 0, "Nonempty flight to retransmit"); + BOTAN_ASSERT(!flight.empty(), "Nonempty flight to retransmit"); uint16_t epoch = m_flight_data[flight[0]].epoch; diff --git a/src/lib/tls/tls_record.cpp b/src/lib/tls/tls_record.cpp index fbf8879a4..ffe91afe8 100644 --- a/src/lib/tls/tls_record.cpp +++ b/src/lib/tls/tls_record.cpp @@ -89,7 +89,7 @@ std::vector<uint8_t> Connection_Cipher_State::aead_nonce(uint64_t seq, RandomNum { case Nonce_Format::CBC_MODE: { - if(m_nonce.size()) + if(!m_nonce.empty()) { std::vector<uint8_t> nonce; nonce.swap(m_nonce); @@ -126,7 +126,7 @@ Connection_Cipher_State::aead_nonce(const uint8_t record[], size_t record_len, u { case Nonce_Format::CBC_MODE: { - if(nonce_bytes_from_record() == 0 && m_nonce.size()) + if(nonce_bytes_from_record() == 0 && !m_nonce.empty()) { std::vector<uint8_t> nonce; nonce.swap(m_nonce); diff --git a/src/lib/tls/tls_server.cpp b/src/lib/tls/tls_server.cpp index 6dc1ba9f2..fb56126b0 100644 --- a/src/lib/tls/tls_server.cpp +++ b/src/lib/tls/tls_server.cpp @@ -105,7 +105,7 @@ bool check_for_resume(Session& session_info, return false; // client sent a different SNI hostname - if(client_hello->sni_hostname() != "") + if(!client_hello->sni_hostname().empty()) { if(client_hello->sni_hostname() != session_info.server_info().hostname()) return false; @@ -288,7 +288,7 @@ std::vector<X509_Certificate> Server::get_peer_cert_chain(const Handshake_State& state_base) const { const Server_Handshake_State& state = dynamic_cast<const Server_Handshake_State&>(state_base); - if(state.resume_peer_certs().size() > 0) + if(!state.resume_peer_certs().empty()) return state.resume_peer_certs(); if(state.client_certs()) @@ -320,7 +320,7 @@ Protocol_Version select_version(const Botan::TLS::Policy& policy, const Protocol_Version latest_supported = policy.latest_supported_version(is_datagram); - if(supported_versions.size() > 0) + if(!supported_versions.empty()) { if(is_datagram) { @@ -818,7 +818,7 @@ void Server::session_create(Server_Handshake_State& pending_state, cert_chains = get_server_certs(sni_hostname, m_creds); - if(sni_hostname != "" && cert_chains.empty()) + if(!sni_hostname.empty() && cert_chains.empty()) { cert_chains = get_server_certs("", m_creds); @@ -878,7 +878,7 @@ void Server::session_create(Server_Handshake_State& pending_state, // csr is non-null if client_hello()->supports_cert_status_message() BOTAN_ASSERT_NOMSG(csr != nullptr); const auto resp_bytes = callbacks().tls_provide_cert_status(cert_chains[algo_used], *csr); - if(resp_bytes.size() > 0) + if(!resp_bytes.empty()) { pending_state.server_cert_status(new Certificate_Status( pending_state.handshake_io(), diff --git a/src/lib/utils/ghash/ghash.cpp b/src/lib/utils/ghash/ghash.cpp index af4f52765..b387333ce 100644 --- a/src/lib/utils/ghash/ghash.cpp +++ b/src/lib/utils/ghash/ghash.cpp @@ -212,7 +212,7 @@ void GHASH::final(uint8_t mac[], size_t mac_len) void GHASH::nonce_hash(secure_vector<uint8_t>& y0, const uint8_t nonce[], size_t nonce_len) { - BOTAN_ASSERT(m_ghash.size() == 0, "nonce_hash called during wrong time"); + BOTAN_ASSERT(m_ghash.empty(), "nonce_hash called during wrong time"); ghash_update(y0, nonce, nonce_len); add_final_block(y0, 0, nonce_len); diff --git a/src/lib/utils/locking_allocator/locking_allocator.cpp b/src/lib/utils/locking_allocator/locking_allocator.cpp index e0e40068e..995f23f20 100644 --- a/src/lib/utils/locking_allocator/locking_allocator.cpp +++ b/src/lib/utils/locking_allocator/locking_allocator.cpp @@ -49,7 +49,7 @@ mlock_allocator::mlock_allocator() { m_locked_pages = OS::allocate_locked_pages(mem_to_lock / page_size); - if(m_locked_pages.size() > 0) + if(!m_locked_pages.empty()) { m_pool.reset(new Memory_Pool(m_locked_pages, page_size)); } diff --git a/src/lib/utils/mem_pool/mem_pool.cpp b/src/lib/utils/mem_pool/mem_pool.cpp index d568cb1a7..87becd6ba 100644 --- a/src/lib/utils/mem_pool/mem_pool.cpp +++ b/src/lib/utils/mem_pool/mem_pool.cpp @@ -355,7 +355,7 @@ void* Memory_Pool::allocate(size_t n) // Otoh bucket search should be very fast } - if(m_free_pages.size() > 0) + if(!m_free_pages.empty()) { uint8_t* ptr = m_free_pages[0]; m_free_pages.pop_front(); diff --git a/src/lib/utils/read_kv.cpp b/src/lib/utils/read_kv.cpp index 8666b6c13..e8813b3e0 100644 --- a/src/lib/utils/read_kv.cpp +++ b/src/lib/utils/read_kv.cpp @@ -12,7 +12,7 @@ namespace Botan { std::map<std::string, std::string> read_kv(const std::string& kv) { std::map<std::string, std::string> m; - if(kv == "") + if(kv.empty()) return m; std::vector<std::string> parts; diff --git a/src/lib/utils/scan_name.cpp b/src/lib/utils/scan_name.cpp index 56c06dcc5..8819c1b0c 100644 --- a/src/lib/utils/scan_name.cpp +++ b/src/lib/utils/scan_name.cpp @@ -62,7 +62,7 @@ SCAN_Name::SCAN_Name(const char* algo_spec) : SCAN_Name(std::string(algo_spec)) SCAN_Name::SCAN_Name(std::string algo_spec) : m_orig_algo_spec(algo_spec), m_alg_name(), m_args(), m_mode_info() { - if(algo_spec.size() == 0) + if(algo_spec.empty()) throw Invalid_Argument("Expected algorithm name, got empty string"); std::vector<std::pair<size_t, std::string>> name; @@ -90,7 +90,7 @@ SCAN_Name::SCAN_Name(std::string algo_spec) : m_orig_algo_spec(algo_spec), m_alg accum.second.push_back(c); else { - if(accum.second != "") + if(!accum.second.empty()) name.push_back(accum); accum = std::make_pair(level, ""); } @@ -99,13 +99,13 @@ SCAN_Name::SCAN_Name(std::string algo_spec) : m_orig_algo_spec(algo_spec), m_alg accum.second.push_back(c); } - if(accum.second != "") + if(!accum.second.empty()) name.push_back(accum); if(level != 0) throw Decoding_Error(decoding_error + "Missing close paren"); - if(name.size() == 0) + if(name.empty()) throw Decoding_Error(decoding_error + "Empty name"); m_alg_name = name[0].second; diff --git a/src/lib/utils/timer.cpp b/src/lib/utils/timer.cpp index 404da5ce8..15aeeaa66 100644 --- a/src/lib/utils/timer.cpp +++ b/src/lib/utils/timer.cpp @@ -66,7 +66,7 @@ bool Timer::operator<(const Timer& other) const std::string Timer::to_string() const { - if(m_custom_msg.size() > 0) + if(!m_custom_msg.empty()) { return m_custom_msg; } diff --git a/src/lib/x509/asn1_alt_name.cpp b/src/lib/x509/asn1_alt_name.cpp index 6fe0433d4..060632657 100644 --- a/src/lib/x509/asn1_alt_name.cpp +++ b/src/lib/x509/asn1_alt_name.cpp @@ -123,7 +123,7 @@ X509_DN AlternativeName::dn() const */ bool AlternativeName::has_items() const { - return (m_alt_info.size() > 0 || m_othernames.size() > 0); + return (!m_alt_info.empty() || !m_othernames.empty()); } namespace { diff --git a/src/lib/x509/certstor.cpp b/src/lib/x509/certstor.cpp index 7108575e2..854046411 100644 --- a/src/lib/x509/certstor.cpp +++ b/src/lib/x509/certstor.cpp @@ -59,11 +59,11 @@ Certificate_Store_In_Memory::find_cert(const X509_DN& subject_dn, for(const auto& cert : m_certs) { // Only compare key ids if set in both call and in the cert - if(key_id.size()) + if(!key_id.empty()) { std::vector<uint8_t> skid = cert.subject_key_id(); - if(skid.size() && skid != key_id) // no match + if(!skid.empty() && skid != key_id) // no match continue; } @@ -82,11 +82,11 @@ std::vector<X509_Certificate> Certificate_Store_In_Memory::find_all_certs( for(const auto& cert : m_certs) { - if(key_id.size()) + if(!key_id.empty()) { std::vector<uint8_t> skid = cert.subject_key_id(); - if(skid.size() && skid != key_id) // no match + if(!skid.empty() && skid != key_id) // no match continue; } @@ -157,11 +157,11 @@ std::optional<X509_CRL> Certificate_Store_In_Memory::find_crl_for(const X509_Cer for(const auto& c : m_crls) { // Only compare key ids if set in both call and in the CRL - if(key_id.size()) + if(!key_id.empty()) { std::vector<uint8_t> akid = c.authority_key_id(); - if(akid.size() && akid != key_id) // no match + if(!akid.empty() && akid != key_id) // no match continue; } diff --git a/src/lib/x509/ocsp.cpp b/src/lib/x509/ocsp.cpp index 9442d50d5..1bbe43761 100644 --- a/src/lib/x509/ocsp.cpp +++ b/src/lib/x509/ocsp.cpp @@ -207,7 +207,7 @@ Certificate_Status_Code Response::check_signature(const std::vector<Certificate_ } } - if(m_key_hash.size() > 0) + if(!m_key_hash.empty()) { signing_cert = trusted_roots[i]->find_cert_by_pubkey_sha1(m_key_hash); if(signing_cert) @@ -229,7 +229,7 @@ Certificate_Status_Code Response::check_signature(const std::vector<Certificate_ break; } - if(m_key_hash.size() > 0 && ee_cert_path[i].subject_public_key_bitstring_sha1() == m_key_hash) + if(!m_key_hash.empty() && ee_cert_path[i].subject_public_key_bitstring_sha1() == m_key_hash) { signing_cert = ee_cert_path[i]; break; @@ -237,7 +237,7 @@ Certificate_Status_Code Response::check_signature(const std::vector<Certificate_ } } - if(!signing_cert && m_certs.size() > 0) + if(!signing_cert && !m_certs.empty()) { for(size_t i = 0; i < m_certs.size(); ++i) { @@ -248,7 +248,7 @@ Certificate_Status_Code Response::check_signature(const std::vector<Certificate_ break; } - if(m_key_hash.size() > 0 && m_certs[i].subject_public_key_bitstring_sha1() == m_key_hash) + if(!m_key_hash.empty() && m_certs[i].subject_public_key_bitstring_sha1() == m_key_hash) { signing_cert = m_certs[i]; break; diff --git a/src/lib/x509/x509_ca.cpp b/src/lib/x509/x509_ca.cpp index f5ceb70f7..096eb7805 100644 --- a/src/lib/x509/x509_ca.cpp +++ b/src/lib/x509/x509_ca.cpp @@ -285,7 +285,7 @@ X509_CRL X509_CA::make_crl(const std::vector<CRL_Entry>& revoked, .encode(m_ca_cert.subject_dn()) .encode(X509_Time(issue_time)) .encode(X509_Time(expire_time)) - .encode_if(revoked.size() > 0, + .encode_if(!revoked.empty(), DER_Encoder() .start_sequence() .encode_list(revoked) diff --git a/src/lib/x509/x509_obj.cpp b/src/lib/x509/x509_obj.cpp index c0268306f..2266e0020 100644 --- a/src/lib/x509/x509_obj.cpp +++ b/src/lib/x509/x509_obj.cpp @@ -186,7 +186,7 @@ Certificate_Status_Code X509_Object::verify_signature(const Public_Key& pub_key) const std::vector<std::string> sig_info = split_on(m_sig_algo.get_oid().to_formatted_string(), '/'); - if(sig_info.size() < 1 || sig_info.size() > 2 || sig_info[0] != pub_key.algo_name()) + if(sig_info.empty() || sig_info.size() > 2 || sig_info[0] != pub_key.algo_name()) return Certificate_Status_Code::SIGNATURE_ALGO_BAD_PARAMS; const std::string pub_key_algo = sig_info[0]; diff --git a/src/lib/x509/x509cert.cpp b/src/lib/x509/x509cert.cpp index 05ac29150..9382ef0f1 100644 --- a/src/lib/x509/x509cert.cpp +++ b/src/lib/x509/x509cert.cpp @@ -607,7 +607,7 @@ std::vector<std::string> X509_Certificate::ca_issuers() const std::string X509_Certificate::crl_distribution_point() const { // just returns the first (arbitrarily) - if(data().m_crl_distribution_points.size() > 0) + if(!data().m_crl_distribution_points.empty()) return data().m_crl_distribution_points[0]; return ""; } @@ -700,9 +700,9 @@ std::string X509_Certificate::fingerprint(const std::string& hash_name) const * left empty in which case we fall back to create_hex_fingerprint * which will throw if the hash is unavailable. */ - if(hash_name == "SHA-256" && data().m_fingerprint_sha256.size() > 0) + if(hash_name == "SHA-256" && !data().m_fingerprint_sha256.empty()) return data().m_fingerprint_sha256; - else if(hash_name == "SHA-1" && data().m_fingerprint_sha1.size() > 0) + else if(hash_name == "SHA-1" && !data().m_fingerprint_sha1.empty()) return data().m_fingerprint_sha1; else return create_hex_fingerprint(this->BER_encode(), hash_name); @@ -857,10 +857,10 @@ std::string X509_Certificate::to_string() const out << "Serial number: " << hex_encode(this->serial_number()) << "\n"; - if(this->authority_key_id().size()) + if(!this->authority_key_id().empty()) out << "Authority keyid: " << hex_encode(this->authority_key_id()) << "\n"; - if(this->subject_key_id().size()) + if(!this->subject_key_id().empty()) out << "Subject keyid: " << hex_encode(this->subject_key_id()) << "\n"; try diff --git a/src/lib/x509/x509opt.cpp b/src/lib/x509/x509opt.cpp index 25cba112a..b3b4354be 100644 --- a/src/lib/x509/x509opt.cpp +++ b/src/lib/x509/x509opt.cpp @@ -91,7 +91,7 @@ X509_Cert_Options::X509_Cert_Options(const std::string& initial_opts, throw Invalid_Argument("X.509 cert options: Too many names: " + initial_opts); - if(parsed.size() >= 1) common_name = parsed[0]; + if(!parsed.empty()) common_name = parsed[0]; if(parsed.size() >= 2) country = parsed[1]; if(parsed.size() >= 3) organization = parsed[2]; if(parsed.size() == 4) org_unit = parsed[3]; diff --git a/src/lib/x509/x509path.cpp b/src/lib/x509/x509path.cpp index f71266d56..cb248d563 100644 --- a/src/lib/x509/x509path.cpp +++ b/src/lib/x509/x509path.cpp @@ -140,7 +140,7 @@ PKIX::check_chain(const std::vector<X509_Certificate>& cert_path, } // Ignore untrusted hashes on self-signed roots - if(trusted_hashes.size() > 0 && !at_self_signed_root) + if(!trusted_hashes.empty() && !at_self_signed_root) { if(trusted_hashes.count(subject->hash_used_for_signature()) == 0) status.insert(Certificate_Status_Code::UNTRUSTED_HASH); @@ -255,7 +255,7 @@ PKIX::check_ocsp(const std::vector<X509_Certificate>& cert_path, } } - while(cert_status.size() > 0 && cert_status.back().empty()) + while(!cert_status.empty() && cert_status.back().empty()) cert_status.pop_back(); return cert_status; @@ -313,7 +313,7 @@ PKIX::check_crl(const std::vector<X509_Certificate>& cert_path, // for example see #1652 // is the extension critical and unknown? - if(extension.second && OIDS::oid2str_or_empty(extension.first->oid_of()) == "") + if(extension.second && OIDS::oid2str_or_empty(extension.first->oid_of()).empty()) { /* NIST Certificate Path Valiadation Testing document: "When an implementation does not recognize a critical extension in the * crlExtensions field, it shall assume that identified certificates have been revoked and are no longer valid" @@ -325,7 +325,7 @@ PKIX::check_crl(const std::vector<X509_Certificate>& cert_path, } } - while(cert_status.size() > 0 && cert_status.back().empty()) + while(!cert_status.empty() && cert_status.back().empty()) cert_status.pop_back(); return cert_status; @@ -384,7 +384,7 @@ PKIX::check_ocsp_online(const std::vector<X509_Certificate>& cert_path, const std::optional<X509_Certificate>& subject = cert_path.at(i); const std::optional<X509_Certificate>& issuer = cert_path.at(i+1); - if(subject->ocsp_responder() == "") + if(subject->ocsp_responder().empty()) { ocsp_response_futures.emplace_back(std::async(std::launch::deferred, [&]() -> std::optional<OCSP::Response> { return OCSP::Response(Certificate_Status_Code::OCSP_NO_REVOCATION_URL); @@ -463,7 +463,7 @@ PKIX::check_crl_online(const std::vector<X509_Certificate>& cert_path, */ future_crls.emplace_back(std::future<std::optional<X509_CRL>>()); } - else if(cert->crl_distribution_point() == "") + else if(cert->crl_distribution_point().empty()) { // Avoid creating a thread for this case future_crls.emplace_back(std::async(std::launch::deferred, [&]() -> std::optional<X509_CRL> { @@ -781,7 +781,7 @@ void PKIX::merge_revocation_status(CertificatePathStatusCodes& chain_status, { bool had_crl = false, had_ocsp = false; - if(i < crl.size() && crl[i].size() > 0) + if(i < crl.size() && !crl[i].empty()) { for(auto&& code : crl[i]) { @@ -793,7 +793,7 @@ void PKIX::merge_revocation_status(CertificatePathStatusCodes& chain_status, } } - if(i < ocsp.size() && ocsp[i].size() > 0) + if(i < ocsp.size() && !ocsp[i].empty()) { for(auto&& code : ocsp[i]) { @@ -888,7 +888,7 @@ Path_Validation_Result x509_path_validate( CertificatePathStatusCodes ocsp_status; - if(ocsp_resp.size() > 0) + if(!ocsp_resp.empty()) { ocsp_status = PKIX::check_ocsp(cert_path, ocsp_resp, trusted_roots, ref_time, restrictions.max_ocsp_age()); } diff --git a/src/scripts/run_clang_tidy.py b/src/scripts/run_clang_tidy.py index 3b882d78d..185d727b2 100755 --- a/src/scripts/run_clang_tidy.py +++ b/src/scripts/run_clang_tidy.py @@ -19,7 +19,7 @@ enabled_checks = [ #'modernize-*', #'portability-*', #'readability-*', - #'readability-container-size-empty' + 'readability-container-size-empty' ] disabled_checks = [ diff --git a/src/tests/test_aead.cpp b/src/tests/test_aead.cpp index 852b46bbc..36e0d7850 100644 --- a/src/tests/test_aead.cpp +++ b/src/tests/test_aead.cpp @@ -354,7 +354,7 @@ class AEAD_Tests final : public Text_Based_Test } // test decryption with modified nonce - if(nonce.size() > 0) + if(!nonce.empty()) { buf.assign(input.begin(), input.end()); std::vector<uint8_t> bad_nonce = mutate_vec(nonce); diff --git a/src/tests/test_block.cpp b/src/tests/test_block.cpp index 24a035f98..d48f0554a 100644 --- a/src/tests/test_block.cpp +++ b/src/tests/test_block.cpp @@ -104,7 +104,7 @@ class Block_Cipher_Tests final : public Text_Based_Test cipher->set_key(key); - if(tweak.size() > 0) + if(!tweak.empty()) { Botan::Tweakable_Block_Cipher* tbc = dynamic_cast<Botan::Tweakable_Block_Cipher*>(cipher.get()); if(tbc == nullptr) diff --git a/src/tests/test_ffi.cpp b/src/tests/test_ffi.cpp index 85938670e..4c93d21c8 100644 --- a/src/tests/test_ffi.cpp +++ b/src/tests/test_ffi.cpp @@ -2039,7 +2039,7 @@ class FFI_Unit_Tests final : public Test botan_pk_op_verify_t verifier = nullptr; - if(signature.size() > 0 && TEST_FFI_OK(botan_pk_op_verify_create, (&verifier, pub, "EMSA1(SHA-256)", 0))) + if(!signature.empty() && TEST_FFI_OK(botan_pk_op_verify_create, (&verifier, pub, "EMSA1(SHA-256)", 0))) { TEST_FFI_OK(botan_pk_op_verify_update, (verifier, message.data(), message.size())); TEST_FFI_OK(botan_pk_op_verify_finish, (verifier, signature.data(), signature.size())); @@ -2148,7 +2148,7 @@ class FFI_Unit_Tests final : public Test botan_pk_op_verify_t verifier = nullptr; - if(signature.size() > 0 && TEST_FFI_OK(botan_pk_op_verify_create, (&verifier, pub, "EMSA1(SHA-384)", flags))) + if(!signature.empty() && TEST_FFI_OK(botan_pk_op_verify_create, (&verifier, pub, "EMSA1(SHA-384)", flags))) { TEST_FFI_OK(botan_pk_op_verify_update, (verifier, message.data(), message.size())); TEST_FFI_OK(botan_pk_op_verify_finish, (verifier, signature.data(), signature.size())); @@ -2244,7 +2244,7 @@ class FFI_Unit_Tests final : public Test botan_pk_op_verify_t verifier = nullptr; - if(signature.size() > 0 && TEST_FFI_OK(botan_pk_op_verify_create, (&verifier, pub, sm2_ident.c_str(), 0))) + if(!signature.empty() && TEST_FFI_OK(botan_pk_op_verify_create, (&verifier, pub, sm2_ident.c_str(), 0))) { TEST_FFI_OK(botan_pk_op_verify_update, (verifier, message.data(), message.size())); TEST_FFI_OK(botan_pk_op_verify_finish, (verifier, signature.data(), signature.size())); diff --git a/src/tests/test_hash.cpp b/src/tests/test_hash.cpp index 80bf5224d..a35c7d211 100644 --- a/src/tests/test_hash.cpp +++ b/src/tests/test_hash.cpp @@ -125,7 +125,7 @@ class Hash_Function_Tests final : public Text_Based_Test // Test that misaligned inputs work - if(input.size() > 0) + if(!input.empty()) { std::vector<uint8_t> misaligned = input; const size_t current_alignment = reinterpret_cast<uintptr_t>(misaligned.data()) % 16; diff --git a/src/tests/test_pubkey.cpp b/src/tests/test_pubkey.cpp index d82f354a4..85d9d425f 100644 --- a/src/tests/test_pubkey.cpp +++ b/src/tests/test_pubkey.cpp @@ -86,7 +86,7 @@ void check_invalid_ciphertexts(Test::Result& result, std::string PK_Test::choose_padding(const VarMap& vars, const std::string& pad_hdr) { - if(pad_hdr != "") + if(!pad_hdr.empty()) return pad_hdr; return vars.get_opt_str("Padding", this->default_padding(vars)); } diff --git a/src/tests/test_runner.cpp b/src/tests/test_runner.cpp index 74bd2028c..dbabab81e 100644 --- a/src/tests/test_runner.cpp +++ b/src/tests/test_runner.cpp @@ -153,7 +153,7 @@ int Test_Runner::run(const Test_Options& opts) output() << "Testing " << Botan::version_string() << "\n"; const std::string cpuid = Botan::CPUID::to_string(); - if(cpuid.size() > 0) + if(!cpuid.empty()) output() << "CPU flags: " << cpuid << "\n"; output() << "Starting tests"; diff --git a/src/tests/test_stream.cpp b/src/tests/test_stream.cpp index 1992fec3d..bea97f9ce 100644 --- a/src/tests/test_stream.cpp +++ b/src/tests/test_stream.cpp @@ -61,7 +61,7 @@ class Stream_Cipher_Tests final : public Text_Based_Test if(cipher->default_iv_length() == 0) { - result.confirm("if default iv length is zero, no iv supported", nonce.size() == 0); + result.confirm("if default iv length is zero, no iv supported", nonce.empty()); // This should still succeed cipher->set_iv(nullptr, 0); @@ -98,7 +98,7 @@ class Stream_Cipher_Tests final : public Text_Based_Test } bool accepted_nonce_early = false; - if(nonce.size() > 0) + if(!nonce.empty()) { try { @@ -136,7 +136,7 @@ class Stream_Cipher_Tests final : public Text_Based_Test not set. So, don't set the nonce now, to ensure the previous call had an effect. */ - if(nonce.size() > 0 && accepted_nonce_early == false) + if(!nonce.empty() && accepted_nonce_early == false) { cipher->set_iv(nonce.data(), nonce.size()); } @@ -158,7 +158,7 @@ class Stream_Cipher_Tests final : public Text_Based_Test result.test_eq(provider, "encrypt", buf, expected); } - if(nonce.size() > 0) + if(!nonce.empty()) { std::vector<uint8_t> buf = input; cipher->set_iv(nonce.data(), nonce.size()); diff --git a/src/tests/test_x509_path.cpp b/src/tests/test_x509_path.cpp index e777f85fe..c09354e19 100644 --- a/src/tests/test_x509_path.cpp +++ b/src/tests/test_x509_path.cpp @@ -46,7 +46,7 @@ std::map<std::string, std::string> read_results(const std::string& results_file, while(in.good()) { std::getline(in, line); - if(line == "") + if(line.empty()) { continue; } diff --git a/src/tests/tests.cpp b/src/tests/tests.cpp index 68e315adb..d8454c4ac 100644 --- a/src/tests/tests.cpp +++ b/src/tests/tests.cpp @@ -62,7 +62,7 @@ void Test::Result::end_timer() void Test::Result::test_note(const std::string& note, const char* extra) { - if(note != "") + if(!note.empty()) { std::ostringstream out; out << who() << " " << note; @@ -460,7 +460,7 @@ std::string Test::Result::result_string() const report << "Failure " << (i + 1) << ": " << m_fail_log[i] << "\n"; } - if(m_fail_log.size() > 0 || tests_run() == 0 || verbose) + if(!m_fail_log.empty() || tests_run() == 0 || verbose) { for(size_t i = 0; i != m_log.size(); ++i) { @@ -1078,7 +1078,7 @@ std::vector<Test::Result> Text_Based_Test::run() uint64_t start = Test::timestamp(); Test::Result result = run_one_test(header, vars); - if(m_cpu_flags.size() > 0) + if(!m_cpu_flags.empty()) { for(auto const& cpuid_u64 : m_cpu_flags) { diff --git a/src/tests/unit_tls.cpp b/src/tests/unit_tls.cpp index 0b8b6ba8a..3061f9119 100644 --- a/src/tests/unit_tls.cpp +++ b/src/tests/unit_tls.cpp @@ -519,7 +519,7 @@ void TLS_Handshake_Test::go() server_has_written = true; } - if(m_c2s.size() > 0) + if(!m_c2s.empty()) { /* * Use this as a temp value to hold the queues as otherwise they @@ -535,7 +535,7 @@ void TLS_Handshake_Test::go() continue; } - if(m_s2c.size() > 0) + if(!m_s2c.empty()) { std::vector<uint8_t> input; std::swap(m_s2c, input); @@ -546,12 +546,12 @@ void TLS_Handshake_Test::go() continue; } - if(m_client_recv.size()) + if(!m_client_recv.empty()) { m_results.test_eq("client recv", m_client_recv, server_msg); } - if(m_server_recv.size()) + if(!m_server_recv.empty()) { m_results.test_eq("server recv", m_server_recv, client_msg); } @@ -586,7 +586,7 @@ void TLS_Handshake_Test::go() } } - if(m_server_recv.size() && m_client_recv.size()) + if(!m_server_recv.empty() && !m_client_recv.empty()) { Botan::SymmetricKey client_key = client->key_material_export("label", "context", 32); Botan::SymmetricKey server_key = m_server->key_material_export("label", "context", 32); @@ -1053,7 +1053,7 @@ class DTLS_Reconnection_Test : public Test return {result}; } - if(c1_c2s.size() > 0) + if(!c1_c2s.empty()) { std::vector<uint8_t> input; std::swap(c1_c2s, input); @@ -1061,7 +1061,7 @@ class DTLS_Reconnection_Test : public Test continue; } - if(s2c.size() > 0) + if(!s2c.empty()) { std::vector<uint8_t> input; std::swap(s2c, input); @@ -1080,7 +1080,7 @@ class DTLS_Reconnection_Test : public Test server.send(server_to_c1_magic); } - if(server_recv.size() > 0 && client1_recv.size() > 0) + if(!server_recv.empty() && !client1_recv.empty()) { result.test_eq("Expected message from client1", server_recv, c1_to_server_magic); result.test_eq("Expected message to client1", client1_recv, server_to_c1_magic); @@ -1119,7 +1119,7 @@ class DTLS_Reconnection_Test : public Test return {result}; } - if(c2_c2s.size() > 0) + if(!c2_c2s.empty()) { std::vector<uint8_t> input; std::swap(c2_c2s, input); @@ -1127,7 +1127,7 @@ class DTLS_Reconnection_Test : public Test continue; } - if(s2c.size() > 0) + if(!s2c.empty()) { std::vector<uint8_t> input; std::swap(s2c, input); @@ -1146,7 +1146,7 @@ class DTLS_Reconnection_Test : public Test server.send(server_to_c2_magic); } - if(server_recv.size() > 0 && client2_recv.size() > 0) + if(!server_recv.empty() && !client2_recv.empty()) { result.test_eq("Expected message from client2", server_recv, c2_to_server_magic); result.test_eq("Expected message to client2", client2_recv, server_to_c2_magic); |