From f95cd9245d2e889a756b187452dafaf68e795179 Mon Sep 17 00:00:00 2001 From: Daniel Neus Date: Mon, 11 Jan 2016 11:55:42 +0100 Subject: Remaining cppcheck fixes that are not covered by GH #444 --- src/lib/asn1/alg_id.cpp | 22 +++-------- src/lib/asn1/asn1_attribute.cpp | 14 ++----- src/lib/asn1/asn1_str.cpp | 10 ++--- src/lib/base/algo_registry.h | 2 +- src/lib/base/scan_name.cpp | 4 +- src/lib/cert/x509/x509_ext.cpp | 16 +++----- src/lib/compression/compression.cpp | 2 +- src/lib/entropy/win32_stats/es_win32.cpp | 4 +- src/lib/filters/filter.cpp | 1 - src/lib/filters/pipe_rw.cpp | 1 - src/lib/filters/secqueue.cpp | 1 + src/lib/hash/md2/md2.h | 2 +- src/lib/mac/mac.cpp | 2 +- src/lib/math/numbertheory/pow_mod.cpp | 13 +++++-- src/lib/math/numbertheory/powm_fw.cpp | 7 +--- src/lib/pubkey/blinding.cpp | 5 +-- src/lib/pubkey/dsa/dsa.cpp | 11 ++---- src/lib/pubkey/ecc_key/ecc_key.cpp | 9 +---- src/lib/pubkey/ecc_key/ecc_key.h | 3 +- src/lib/pubkey/if_algo/if_algo.cpp | 9 ++--- src/lib/pubkey/nr/nr.cpp | 11 ++---- src/lib/tls/msg_finished.cpp | 9 ++--- src/lib/tls/msg_server_hello.cpp | 2 +- src/lib/tls/tls_blocking.cpp | 4 +- src/lib/tls/tls_blocking.h | 4 +- src/lib/tls/tls_client.cpp | 4 +- src/lib/tls/tls_client.h | 4 +- src/lib/tls/tls_extensions.cpp | 18 +++------ src/lib/tls/tls_messages.h | 2 +- src/lib/tls/tls_policy.h | 6 +-- src/lib/utils/donna128.h | 4 +- src/tests/test_filters.cpp | 63 ++++++++++++++++++++++++++++++++ src/tests/unit_ecdsa.cpp | 4 +- src/tests/unit_tls.cpp | 4 +- 34 files changed, 141 insertions(+), 136 deletions(-) create mode 100644 src/tests/test_filters.cpp diff --git a/src/lib/asn1/alg_id.cpp b/src/lib/asn1/alg_id.cpp index 7d476a225..75ea78c18 100644 --- a/src/lib/asn1/alg_id.cpp +++ b/src/lib/asn1/alg_id.cpp @@ -16,32 +16,24 @@ namespace Botan { * Create an AlgorithmIdentifier */ AlgorithmIdentifier::AlgorithmIdentifier(const OID& alg_id, - const std::vector& param) - { - oid = alg_id; - parameters = param; - } + const std::vector& param) : oid(alg_id), parameters(param) + {} /* * Create an AlgorithmIdentifier */ AlgorithmIdentifier::AlgorithmIdentifier(const std::string& alg_id, - const std::vector& param) - { - oid = OIDS::lookup(alg_id); - parameters = param; - } + const std::vector& param) : oid(OIDS::lookup(alg_id)), parameters(param) + {} /* * Create an AlgorithmIdentifier */ AlgorithmIdentifier::AlgorithmIdentifier(const OID& alg_id, - Encoding_Option option) + Encoding_Option option) : oid(alg_id), parameters() { const byte DER_NULL[] = { 0x05, 0x00 }; - oid = alg_id; - if(option == USE_NULL_PARAM) parameters += std::pair(DER_NULL, sizeof(DER_NULL)); } @@ -50,12 +42,10 @@ AlgorithmIdentifier::AlgorithmIdentifier(const OID& alg_id, * Create an AlgorithmIdentifier */ AlgorithmIdentifier::AlgorithmIdentifier(const std::string& alg_id, - Encoding_Option option) + Encoding_Option option) : oid(OIDS::lookup(alg_id)), parameters() { const byte DER_NULL[] = { 0x05, 0x00 }; - oid = OIDS::lookup(alg_id); - if(option == USE_NULL_PARAM) parameters += std::pair(DER_NULL, sizeof(DER_NULL)); } diff --git a/src/lib/asn1/asn1_attribute.cpp b/src/lib/asn1/asn1_attribute.cpp index 406a57d9a..bd7e5bf11 100644 --- a/src/lib/asn1/asn1_attribute.cpp +++ b/src/lib/asn1/asn1_attribute.cpp @@ -15,21 +15,15 @@ namespace Botan { /* * Create an Attribute */ -Attribute::Attribute(const OID& attr_oid, const std::vector& attr_value) - { - oid = attr_oid; - parameters = attr_value; - } +Attribute::Attribute(const OID& attr_oid, const std::vector& attr_value) : oid(attr_oid), parameters(attr_value) + {} /* * Create an Attribute */ Attribute::Attribute(const std::string& attr_oid, - const std::vector& attr_value) - { - oid = OIDS::lookup(attr_oid); - parameters = attr_value; - } + const std::vector& attr_value) : oid(OIDS::lookup(attr_oid)), parameters(attr_value) + {} /* * DER encode a Attribute diff --git a/src/lib/asn1/asn1_str.cpp b/src/lib/asn1/asn1_str.cpp index 809448888..fca0f442a 100644 --- a/src/lib/asn1/asn1_str.cpp +++ b/src/lib/asn1/asn1_str.cpp @@ -62,9 +62,8 @@ ASN1_Tag choose_encoding(const std::string& str, /* * Create an ASN1_String */ -ASN1_String::ASN1_String(const std::string& str, ASN1_Tag t) : m_tag(t) +ASN1_String::ASN1_String(const std::string& str, ASN1_Tag t) : m_iso_8859_str(Charset::transcode(str, LOCAL_CHARSET, LATIN1_CHARSET)), m_tag(t) { - m_iso_8859_str = Charset::transcode(str, LOCAL_CHARSET, LATIN1_CHARSET); if(m_tag == DIRECTORY_STRING) m_tag = choose_encoding(m_iso_8859_str, "latin1"); @@ -83,11 +82,8 @@ ASN1_String::ASN1_String(const std::string& str, ASN1_Tag t) : m_tag(t) /* * Create an ASN1_String */ -ASN1_String::ASN1_String(const std::string& str) - { - m_iso_8859_str = Charset::transcode(str, LOCAL_CHARSET, LATIN1_CHARSET); - m_tag = choose_encoding(m_iso_8859_str, "latin1"); - } +ASN1_String::ASN1_String(const std::string& str) : m_iso_8859_str(Charset::transcode(str, LOCAL_CHARSET, LATIN1_CHARSET)), m_tag(choose_encoding(m_iso_8859_str, "latin1")) + {} /* * Return this string in ISO 8859-1 encoding diff --git a/src/lib/base/algo_registry.h b/src/lib/base/algo_registry.h index 162770730..ebc23bfca 100644 --- a/src/lib/base/algo_registry.h +++ b/src/lib/base/algo_registry.h @@ -213,7 +213,7 @@ class Algo_Registry }; template T* -make_a(const typename T::Spec& spec, const std::string provider = "") +make_a(const typename T::Spec& spec, const std::string& provider = "") { return Algo_Registry::global_registry().make(spec, provider); } diff --git a/src/lib/base/scan_name.cpp b/src/lib/base/scan_name.cpp index 4688d0871..08f5e8702 100644 --- a/src/lib/base/scan_name.cpp +++ b/src/lib/base/scan_name.cpp @@ -70,10 +70,8 @@ SCAN_Name::SCAN_Name(const char* algo_spec) : SCAN_Name(std::string(algo_spec)) { } -SCAN_Name::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() { - m_orig_algo_spec = algo_spec; - std::vector > name; size_t level = 0; std::pair accum = std::make_pair(level, ""); diff --git a/src/lib/cert/x509/x509_ext.cpp b/src/lib/cert/x509/x509_ext.cpp index b2a53181b..7dd4a3190 100644 --- a/src/lib/cert/x509/x509_ext.cpp +++ b/src/lib/cert/x509/x509_ext.cpp @@ -309,11 +309,8 @@ void Subject_Key_ID::contents_to(Data_Store& subject, Data_Store&) const /* * Subject_Key_ID Constructor */ -Subject_Key_ID::Subject_Key_ID(const std::vector& pub_key) - { - SHA_160 hash; - m_key_id = unlock(hash.process(pub_key)); - } +Subject_Key_ID::Subject_Key_ID(const std::vector& pub_key) : m_key_id(unlock(SHA_160().process(pub_key))) + {} /* * Encode the extension @@ -384,11 +381,8 @@ void Alternative_Name::contents_to(Data_Store& subject_info, * Alternative_Name Constructor */ Alternative_Name::Alternative_Name(const AlternativeName& alt_name, - const std::string& oid_name_str) - { - this->m_alt_name = alt_name; - this->m_oid_name_str = oid_name_str; - } + const std::string& oid_name_str) : m_alt_name(alt_name), m_oid_name_str(oid_name_str) + {} /* * Subject_Alternative_Name Constructor @@ -476,7 +470,7 @@ std::vector Certificate_Policies::encode_inner() const std::vector policies; for(size_t i = 0; i != m_oids.size(); ++i) - policies.push_back(Policy_Information( m_oids[i] )); + policies.push_back(Policy_Information(m_oids[i])); return DER_Encoder() .start_cons(SEQUENCE) diff --git a/src/lib/compression/compression.cpp b/src/lib/compression/compression.cpp index 178de245f..54faec7b8 100644 --- a/src/lib/compression/compression.cpp +++ b/src/lib/compression/compression.cpp @@ -56,7 +56,7 @@ void Compression_Alloc_Info::do_free(void* ptr) namespace { -Compressor_Transform* do_make_compressor(const std::string& type, const std::string suffix) +Compressor_Transform* do_make_compressor(const std::string& type, const std::string& suffix) { const std::map trans{ {"zlib", "Zlib"}, diff --git a/src/lib/entropy/win32_stats/es_win32.cpp b/src/lib/entropy/win32_stats/es_win32.cpp index 7cb0988db..ce0edea83 100644 --- a/src/lib/entropy/win32_stats/es_win32.cpp +++ b/src/lib/entropy/win32_stats/es_win32.cpp @@ -72,7 +72,6 @@ void Win32_EntropySource::poll(Entropy_Accumulator& accum) if(!accum.polling_finished()) { - size_t heap_lists_found = 0; HEAPLIST32 heap_list; heap_list.dwSize = sizeof(HEAPLIST32); @@ -81,6 +80,7 @@ void Win32_EntropySource::poll(Entropy_Accumulator& accum) if(Heap32ListFirst(snapshot, &heap_list)) { + size_t heap_lists_found = 0; do { accum.add(heap_list, BOTAN_ENTROPY_ESTIMATE_SYSTEM_DATA); @@ -88,12 +88,12 @@ void Win32_EntropySource::poll(Entropy_Accumulator& accum) if(++heap_lists_found > HEAP_LISTS_MAX) break; - size_t heap_objs_found = 0; HEAPENTRY32 heap_entry; heap_entry.dwSize = sizeof(HEAPENTRY32); if(Heap32First(&heap_entry, heap_list.th32ProcessID, heap_list.th32HeapID)) { + size_t heap_objs_found = 0; do { if(heap_objs_found++ > HEAP_OBJS_PER_LIST) diff --git a/src/lib/filters/filter.cpp b/src/lib/filters/filter.cpp index 18ea02b9e..6ae713314 100644 --- a/src/lib/filters/filter.cpp +++ b/src/lib/filters/filter.cpp @@ -6,7 +6,6 @@ */ #include -#include #include namespace Botan { diff --git a/src/lib/filters/pipe_rw.cpp b/src/lib/filters/pipe_rw.cpp index 4d31f43f5..646752e7c 100644 --- a/src/lib/filters/pipe_rw.cpp +++ b/src/lib/filters/pipe_rw.cpp @@ -8,7 +8,6 @@ #include #include -#include namespace Botan { diff --git a/src/lib/filters/secqueue.cpp b/src/lib/filters/secqueue.cpp index 4546ae398..6f4070813 100644 --- a/src/lib/filters/secqueue.cpp +++ b/src/lib/filters/secqueue.cpp @@ -104,6 +104,7 @@ void SecureQueue::destroy() SecureQueue& SecureQueue::operator=(const SecureQueue& input) { destroy(); + m_bytes_read = input.get_bytes_read(); m_head = m_tail = new SecureQueueNode; SecureQueueNode* temp = input.m_head; while(temp) diff --git a/src/lib/hash/md2/md2.h b/src/lib/hash/md2/md2.h index ab29a49cb..58629495a 100644 --- a/src/lib/hash/md2/md2.h +++ b/src/lib/hash/md2/md2.h @@ -25,7 +25,7 @@ class BOTAN_DLL MD2 final : public HashFunction void clear() override; - MD2() : m_X(48), m_checksum(16), m_buffer(16) + MD2() : m_X(48), m_checksum(16), m_buffer(16), m_position(0) { clear(); } private: void add_data(const byte[], size_t) override; diff --git a/src/lib/mac/mac.cpp b/src/lib/mac/mac.cpp index bb5643b59..a3917141d 100644 --- a/src/lib/mac/mac.cpp +++ b/src/lib/mac/mac.cpp @@ -38,7 +38,7 @@ namespace Botan { std::unique_ptr MessageAuthenticationCode::create(const std::string& algo_spec, const std::string& provider) { - return std::unique_ptr(make_a(Botan::MessageAuthenticationCode::Spec(algo_spec), provider)); + return std::unique_ptr(make_a(MessageAuthenticationCode::Spec(algo_spec), provider)); } std::vector MessageAuthenticationCode::providers(const std::string& algo_spec) diff --git a/src/lib/math/numbertheory/pow_mod.cpp b/src/lib/math/numbertheory/pow_mod.cpp index 49ff6cca2..5503f313c 100644 --- a/src/lib/math/numbertheory/pow_mod.cpp +++ b/src/lib/math/numbertheory/pow_mod.cpp @@ -34,10 +34,15 @@ Power_Mod::Power_Mod(const Power_Mod& other) */ Power_Mod& Power_Mod::operator=(const Power_Mod& other) { - delete m_core; - m_core = nullptr; - if(other.m_core) - m_core = other.m_core->copy(); + if(this != &other) + { + delete m_core; + m_core = nullptr; + if(other.m_core) + { + m_core = other.m_core->copy(); + } + } return (*this); } diff --git a/src/lib/math/numbertheory/powm_fw.cpp b/src/lib/math/numbertheory/powm_fw.cpp index 02e9bbe83..7369959a9 100644 --- a/src/lib/math/numbertheory/powm_fw.cpp +++ b/src/lib/math/numbertheory/powm_fw.cpp @@ -60,10 +60,7 @@ BigInt Fixed_Window_Exponentiator::execute() const */ Fixed_Window_Exponentiator::Fixed_Window_Exponentiator(const BigInt& n, Power_Mod::Usage_Hints hints) - { - m_reducer = Modular_Reducer(n); - m_hints = hints; - m_window_bits = 0; - } + : m_reducer{Modular_Reducer(n)}, m_exp{}, m_window_bits{}, m_g{}, m_hints{hints} + {} } diff --git a/src/lib/pubkey/blinding.cpp b/src/lib/pubkey/blinding.cpp index 4a5c5acff..b20a30fa1 100644 --- a/src/lib/pubkey/blinding.cpp +++ b/src/lib/pubkey/blinding.cpp @@ -19,11 +19,8 @@ namespace Botan { Blinder::Blinder(const BigInt& modulus, std::function fwd, std::function inv) : - m_fwd_fn(fwd), m_inv_fn(inv) + m_reducer{Modular_Reducer(modulus)}, m_rng{}, m_fwd_fn(fwd), m_inv_fn(inv), m_modulus_bits{modulus.bits()}, m_e{}, m_d{}, m_counter{} { - m_reducer = Modular_Reducer(modulus); - m_modulus_bits = modulus.bits(); - #if defined(BOTAN_HAS_SYSTEM_RNG) m_rng.reset(new System_RNG); #else diff --git a/src/lib/pubkey/dsa/dsa.cpp b/src/lib/pubkey/dsa/dsa.cpp index 63b7bd07e..471189cd8 100644 --- a/src/lib/pubkey/dsa/dsa.cpp +++ b/src/lib/pubkey/dsa/dsa.cpp @@ -140,13 +140,10 @@ class DSA_Verification_Operation : public PK_Ops::Verification_with_EMSA DSA_Verification_Operation(const DSA_PublicKey& dsa, const std::string& emsa) : PK_Ops::Verification_with_EMSA(emsa), - m_q(dsa.group_q()), m_y(dsa.get_y()) - { - m_powermod_g_p = Fixed_Base_Power_Mod(dsa.group_g(), dsa.group_p()); - m_powermod_y_p = Fixed_Base_Power_Mod(m_y, dsa.group_p()); - m_mod_p = Modular_Reducer(dsa.group_p()); - m_mod_q = Modular_Reducer(dsa.group_q()); - } + m_q(dsa.group_q()), m_y(dsa.get_y()), m_powermod_g_p{Fixed_Base_Power_Mod(dsa.group_g(), dsa.group_p())}, + m_powermod_y_p{Fixed_Base_Power_Mod(m_y, dsa.group_p())}, m_mod_p{Modular_Reducer(dsa.group_p())}, + m_mod_q{Modular_Reducer(dsa.group_q())} + {} size_t message_parts() const override { return 2; } size_t message_part_size() const override { return m_q.bytes(); } diff --git a/src/lib/pubkey/ecc_key/ecc_key.cpp b/src/lib/pubkey/ecc_key/ecc_key.cpp index a3f0ea93d..2dca20725 100644 --- a/src/lib/pubkey/ecc_key/ecc_key.cpp +++ b/src/lib/pubkey/ecc_key/ecc_key.cpp @@ -33,13 +33,8 @@ EC_PublicKey::EC_PublicKey(const EC_Group& dom_par, } EC_PublicKey::EC_PublicKey(const AlgorithmIdentifier& alg_id, - const secure_vector& key_bits) - { - m_domain_params = EC_Group(alg_id.parameters); - m_domain_encoding = EC_DOMPAR_ENC_EXPLICIT; - - m_public_key = OS2ECP(key_bits, domain().get_curve()); - } + const secure_vector& key_bits) : m_domain_params{EC_Group(alg_id.parameters)}, m_public_key{OS2ECP(key_bits, domain().get_curve())}, m_domain_encoding{EC_DOMPAR_ENC_EXPLICIT} + {} bool EC_PublicKey::check_key(RandomNumberGenerator&, bool) const diff --git a/src/lib/pubkey/ecc_key/ecc_key.h b/src/lib/pubkey/ecc_key/ecc_key.h index 3557d0266..3f93a908c 100644 --- a/src/lib/pubkey/ecc_key/ecc_key.h +++ b/src/lib/pubkey/ecc_key/ecc_key.h @@ -81,7 +81,8 @@ class BOTAN_DLL EC_PublicKey : public virtual Public_Key size_t estimated_strength() const override; protected: - EC_PublicKey() : m_domain_encoding(EC_DOMPAR_ENC_EXPLICIT) {} + EC_PublicKey() : m_domain_params{}, m_public_key{}, m_domain_encoding(EC_DOMPAR_ENC_EXPLICIT) + {} EC_Group m_domain_params; PointGFp m_public_key; diff --git a/src/lib/pubkey/if_algo/if_algo.cpp b/src/lib/pubkey/if_algo/if_algo.cpp index a79cad116..e5f3ae20f 100644 --- a/src/lib/pubkey/if_algo/if_algo.cpp +++ b/src/lib/pubkey/if_algo/if_algo.cpp @@ -97,13 +97,11 @@ IF_Scheme_PrivateKey::IF_Scheme_PrivateKey(RandomNumberGenerator& rng, const BigInt& prime2, const BigInt& exp, const BigInt& d_exp, - const BigInt& mod) + const BigInt& mod) : + m_d{ d_exp }, m_p{ prime1 }, m_q{ prime2 }, m_d1{}, m_d2{}, m_c{ inverse_mod( m_q, m_p ) } { - m_p = prime1; - m_q = prime2; - m_e = exp; - m_d = d_exp; m_n = mod.is_nonzero() ? mod : m_p * m_q; + m_e = exp; if(m_d == 0) { @@ -116,7 +114,6 @@ IF_Scheme_PrivateKey::IF_Scheme_PrivateKey(RandomNumberGenerator& rng, m_d1 = m_d % (m_p - 1); m_d2 = m_d % (m_q - 1); - m_c = inverse_mod(m_q, m_p); load_check(rng); } diff --git a/src/lib/pubkey/nr/nr.cpp b/src/lib/pubkey/nr/nr.cpp index 64e08a111..5e2cb1be5 100644 --- a/src/lib/pubkey/nr/nr.cpp +++ b/src/lib/pubkey/nr/nr.cpp @@ -144,13 +144,10 @@ class NR_Verification_Operation : public PK_Ops::Verification_with_EMSA typedef NR_PublicKey Key_Type; NR_Verification_Operation(const NR_PublicKey& nr, const std::string& emsa) : PK_Ops::Verification_with_EMSA(emsa), - m_q(nr.group_q()), m_y(nr.get_y()) - { - m_powermod_g_p = Fixed_Base_Power_Mod(nr.group_g(), nr.group_p()); - m_powermod_y_p = Fixed_Base_Power_Mod(m_y, nr.group_p()); - m_mod_p = Modular_Reducer(nr.group_p()); - m_mod_q = Modular_Reducer(nr.group_q()); - } + m_q(nr.group_q()), m_y(nr.get_y()), m_powermod_g_p{Fixed_Base_Power_Mod(nr.group_g(), nr.group_p())}, + m_powermod_y_p{Fixed_Base_Power_Mod(m_y, nr.group_p())}, m_mod_p{Modular_Reducer(nr.group_p())}, + m_mod_q{Modular_Reducer(nr.group_q())} + {} size_t message_parts() const override { return 2; } size_t message_part_size() const override { return m_q.bytes(); } diff --git a/src/lib/tls/msg_finished.cpp b/src/lib/tls/msg_finished.cpp index b837172b6..2d6b11995 100644 --- a/src/lib/tls/msg_finished.cpp +++ b/src/lib/tls/msg_finished.cpp @@ -48,9 +48,8 @@ std::vector finished_compute_verify(const Handshake_State& state, */ Finished::Finished(Handshake_IO& io, Handshake_State& state, - Connection_Side side) + Connection_Side side) : m_verification_data(finished_compute_verify( state, side )) { - m_verification_data = finished_compute_verify(state, side); state.hash().update(io.send(*this)); } @@ -65,10 +64,8 @@ std::vector Finished::serialize() const /* * Deserialize a Finished message */ -Finished::Finished(const std::vector& buf) - { - m_verification_data = buf; - } +Finished::Finished(const std::vector& buf) : m_verification_data(buf) + {} /* * Verify a Finished message diff --git a/src/lib/tls/msg_server_hello.cpp b/src/lib/tls/msg_server_hello.cpp index f9962a8ee..f8d0c63c7 100644 --- a/src/lib/tls/msg_server_hello.cpp +++ b/src/lib/tls/msg_server_hello.cpp @@ -28,7 +28,7 @@ Server_Hello::Server_Hello(Handshake_IO& io, u16bit ciphersuite, byte compression, bool offer_session_ticket, - const std::string next_protocol) : + const std::string& next_protocol) : m_version(new_session_version), m_session_id(new_session_id), m_random(make_hello_random(rng, policy)), diff --git a/src/lib/tls/tls_blocking.cpp b/src/lib/tls/tls_blocking.cpp index f88b7896c..a1867b6b5 100644 --- a/src/lib/tls/tls_blocking.cpp +++ b/src/lib/tls/tls_blocking.cpp @@ -20,7 +20,7 @@ Blocking_Client::Blocking_Client(read_fn reader, const Policy& policy, RandomNumberGenerator& rng, const Server_Information& server_info, - const Protocol_Version offer_version, + const Protocol_Version& offer_version, const std::vector& next) : m_read(reader), m_channel(writer, @@ -42,7 +42,7 @@ bool Blocking_Client::handshake_cb(const Session& session) return this->handshake_complete(session); } -void Blocking_Client::alert_cb(const Alert alert, const byte[], size_t) +void Blocking_Client::alert_cb(const Alert& alert, const byte[], size_t) { this->alert_notification(alert); } diff --git a/src/lib/tls/tls_blocking.h b/src/lib/tls/tls_blocking.h index 89421f5f5..00e65cbaf 100644 --- a/src/lib/tls/tls_blocking.h +++ b/src/lib/tls/tls_blocking.h @@ -39,7 +39,7 @@ class BOTAN_DLL Blocking_Client const Policy& policy, RandomNumberGenerator& rng, const Server_Information& server_info = Server_Information(), - const Protocol_Version offer_version = Protocol_Version::latest_tls_version(), + const Protocol_Version& offer_version = Protocol_Version::latest_tls_version(), const std::vector& next_protos = {}); /** @@ -89,7 +89,7 @@ class BOTAN_DLL Blocking_Client void data_cb(const byte data[], size_t data_len); - void alert_cb(const Alert alert, const byte data[], size_t data_len); + void alert_cb(const Alert& alert, const byte data[], size_t data_len); read_fn m_read; TLS::Client m_channel; diff --git a/src/lib/tls/tls_client.cpp b/src/lib/tls/tls_client.cpp index 368e4569e..3a219ccff 100644 --- a/src/lib/tls/tls_client.cpp +++ b/src/lib/tls/tls_client.cpp @@ -51,7 +51,7 @@ Client::Client(output_fn output_fn, const Policy& policy, RandomNumberGenerator& rng, const Server_Information& info, - const Protocol_Version offer_version, + const Protocol_Version& offer_version, const std::vector& next_protos, size_t io_buf_sz) : Channel(output_fn, proc_cb, alert_cb, handshake_cb, Channel::handshake_msg_cb(), @@ -75,7 +75,7 @@ Client::Client(output_fn output_fn, const Policy& policy, RandomNumberGenerator& rng, const Server_Information& info, - const Protocol_Version offer_version, + const Protocol_Version& offer_version, const std::vector& next_protos) : Channel(output_fn, proc_cb, alert_cb, handshake_cb, hs_msg_cb, session_manager, rng, policy, offer_version.is_datagram_protocol()), diff --git a/src/lib/tls/tls_client.h b/src/lib/tls/tls_client.h index d17ea74d0..45a741878 100644 --- a/src/lib/tls/tls_client.h +++ b/src/lib/tls/tls_client.h @@ -62,7 +62,7 @@ class BOTAN_DLL Client final : public Channel const Policy& policy, RandomNumberGenerator& rng, const Server_Information& server_info = Server_Information(), - const Protocol_Version offer_version = Protocol_Version::latest_tls_version(), + const Protocol_Version& offer_version = Protocol_Version::latest_tls_version(), const std::vector& next_protocols = {}, size_t reserved_io_buffer_size = 16*1024 ); @@ -77,7 +77,7 @@ class BOTAN_DLL Client final : public Channel const Policy& policy, RandomNumberGenerator& rng, const Server_Information& server_info = Server_Information(), - const Protocol_Version offer_version = Protocol_Version::latest_tls_version(), + const Protocol_Version& offer_version = Protocol_Version::latest_tls_version(), const std::vector& next_protocols = {} ); diff --git a/src/lib/tls/tls_extensions.cpp b/src/lib/tls/tls_extensions.cpp index 35c39ddab..4acf9a6fe 100644 --- a/src/lib/tls/tls_extensions.cpp +++ b/src/lib/tls/tls_extensions.cpp @@ -180,10 +180,8 @@ std::vector Server_Name_Indicator::serialize() const #if defined(BOTAN_HAS_SRP6) SRP_Identifier::SRP_Identifier(TLS_Data_Reader& reader, - u16bit extension_size) + u16bit extension_size) : m_srp_identifier(reader.get_string(1, 1, 255)) { - m_srp_identifier = reader.get_string(1, 1, 255); - if(m_srp_identifier.size() + 1 != extension_size) throw Decoding_Error("Bad encoding for SRP identifier extension"); } @@ -203,10 +201,8 @@ std::vector SRP_Identifier::serialize() const #endif Renegotiation_Extension::Renegotiation_Extension(TLS_Data_Reader& reader, - u16bit extension_size) + u16bit extension_size) : m_reneg_data(reader.get_range(1, 0, 255)) { - m_reneg_data = reader.get_range(1, 0, 255); - if(m_reneg_data.size() + 1 != extension_size) throw Decoding_Error("Bad encoding for secure renegotiation extn"); } @@ -516,16 +512,12 @@ Signature_Algorithms::Signature_Algorithms(TLS_Data_Reader& reader, } Session_Ticket::Session_Ticket(TLS_Data_Reader& reader, - u16bit extension_size) - { - m_ticket = reader.get_elem >(extension_size); - } + u16bit extension_size) : m_ticket(reader.get_elem>(extension_size)) + {} SRTP_Protection_Profiles::SRTP_Protection_Profiles(TLS_Data_Reader& reader, - u16bit extension_size) + u16bit extension_size) : m_pp(reader.get_range(2, 0, 65535)) { - m_pp = reader.get_range(2, 0, 65535); - const std::vector mki = reader.get_range(1, 0, 255); if(m_pp.size() * 2 + mki.size() + 3 != extension_size) diff --git a/src/lib/tls/tls_messages.h b/src/lib/tls/tls_messages.h index 281333f88..00033826f 100644 --- a/src/lib/tls/tls_messages.h +++ b/src/lib/tls/tls_messages.h @@ -267,7 +267,7 @@ class Server_Hello final : public Handshake_Message u16bit ciphersuite, byte compression, bool offer_session_ticket, - const std::string next_protocol); + const std::string& next_protocol); Server_Hello(Handshake_IO& io, Handshake_Hash& hash, diff --git a/src/lib/tls/tls_policy.h b/src/lib/tls/tls_policy.h index 032de81ad..6e4b442c8 100644 --- a/src/lib/tls/tls_policy.h +++ b/src/lib/tls/tls_policy.h @@ -306,10 +306,8 @@ class BOTAN_DLL Text_Policy : public Policy m_kv = read_cfg(iss); } - explicit Text_Policy(std::istream& in) - { - m_kv = read_cfg(in); - } + explicit Text_Policy(std::istream& in) : m_kv(read_cfg(in)) + {} private: diff --git a/src/lib/utils/donna128.h b/src/lib/utils/donna128.h index c72ccb55c..c2a3e0d2e 100644 --- a/src/lib/utils/donna128.h +++ b/src/lib/utils/donna128.h @@ -104,8 +104,8 @@ inline u64bit carry_shift(const donna128& a, size_t shift) return (a >> shift).lo(); } -inline u64bit combine_lower(const donna128 a, size_t s1, - const donna128 b, size_t s2) +inline u64bit combine_lower(const donna128& a, size_t s1, + const donna128& b, size_t s2) { donna128 z = (a >> s1) | (b << s2); return z.lo(); diff --git a/src/tests/test_filters.cpp b/src/tests/test_filters.cpp new file mode 100644 index 000000000..35d578789 --- /dev/null +++ b/src/tests/test_filters.cpp @@ -0,0 +1,63 @@ +/* +* (C) 2016 Daniel Neus +* +* Botan is released under the Simplified BSD License (see license.txt) +*/ + +#include "tests.h" + +#if defined(BOTAN_HAS_FILTERS) + #include +#endif + +namespace Botan_Tests { + +#if defined(BOTAN_HAS_FILTERS) + +class Filter_Tests : public Test + { + public: + std::vector run() override + { + std::vector results; + Test::Result secqueue_result("SecureQueue"); + + try + { + using Botan::SecureQueue; + SecureQueue queue_a; + std::vector test_data = {0x24, 0xB2, 0xBF, 0xC2, 0xE6, 0xD4, 0x7E, 0x04, 0x67, 0xB3}; + queue_a.write(test_data.data(), test_data.size()); + + secqueue_result.test_eq("size of SecureQueue is correct", queue_a.size(), test_data.size()); + secqueue_result.test_eq("0 bytes read so far from SecureQueue", queue_a.get_bytes_read(), 0); + + uint8_t byte; + size_t bytes_read = queue_a.read_byte(byte); + secqueue_result.test_eq("1 byte read", bytes_read, 1); + + Botan::secure_vector produced(byte); + Botan::secure_vector expected(test_data.at(0)); + secqueue_result.test_eq("byte read is correct", produced, expected); + + secqueue_result.test_eq("1 bytes read so far from SecureQueue", queue_a.get_bytes_read(), 1); + + SecureQueue queue_b; + queue_a = queue_b; + secqueue_result.test_eq("bytes_read is set correctly", queue_a.get_bytes_read(), 0); + } + catch (std::exception& e) + { + secqueue_result.test_failure("SecureQueue", e.what()); + } + + results.push_back(secqueue_result); + return results; + } + }; + + BOTAN_REGISTER_TEST("filter", Filter_Tests); + +#endif + +} diff --git a/src/tests/unit_ecdsa.cpp b/src/tests/unit_ecdsa.cpp index 5b750e7fb..ecafb3c7f 100644 --- a/src/tests/unit_ecdsa.cpp +++ b/src/tests/unit_ecdsa.cpp @@ -61,7 +61,7 @@ Test::Result test_hash_larger_than_n() try { - std::vector signature_224 = pk_signer_224.sign_message(message, Test::rng()); + pk_signer_224.sign_message(message, Test::rng()); result.test_failure("bad key/hash combination not rejected"); } catch(Botan::Encoding_Error) @@ -152,8 +152,6 @@ Test::Result test_ec_sign() { Botan::EC_Group dom_pars(Botan::OID("1.3.132.0.8")); Botan::ECDSA_PrivateKey priv_key(Test::rng(), dom_pars); - std::string pem_encoded_key = Botan::PKCS8::PEM_encode(priv_key); - Botan::PK_Signer signer(priv_key, "EMSA1(SHA-224)"); Botan::PK_Verifier verifier(priv_key, "EMSA1(SHA-224)"); diff --git a/src/tests/unit_tls.cpp b/src/tests/unit_tls.cpp index 0fa208858..f125bfcb5 100644 --- a/src/tests/unit_tls.cpp +++ b/src/tests/unit_tls.cpp @@ -527,7 +527,7 @@ Test::Result test_dtls_handshake(Botan::TLS::Protocol_Version offer_version, { input.resize(needed); Test::rng().randomize(input.data(), input.size()); - needed = client.received_data(input.data(), input.size()); + client.received_data(input.data(), input.size()); } } catch(std::exception&) @@ -567,7 +567,7 @@ Test::Result test_dtls_handshake(Botan::TLS::Protocol_Version offer_version, { input.resize(needed); Test::rng().randomize(input.data(), input.size()); - needed = client.received_data(input.data(), input.size()); + client.received_data(input.data(), input.size()); } } catch(std::exception&) -- cgit v1.2.3