diff options
author | Nuno Goncalves <[email protected]> | 2017-02-27 16:08:31 +0100 |
---|---|---|
committer | Nuno Goncalves <[email protected]> | 2017-04-03 22:39:11 +0200 |
commit | 2d96d71f78ff1924ffb48cf49568b8f487e9018f (patch) | |
tree | 0cc211ad3e4a9807e91763fccb3d957c2dc14293 /src/lib/x509/certstor.cpp | |
parent | 753b4c2d5301574d3c9390b79aa275a49809e6c8 (diff) |
Refactor and modernize files to be edited
Signed-off-by: Nuno Goncalves <[email protected]>
Diffstat (limited to 'src/lib/x509/certstor.cpp')
-rw-r--r-- | src/lib/x509/certstor.cpp | 57 |
1 files changed, 24 insertions, 33 deletions
diff --git a/src/lib/x509/certstor.cpp b/src/lib/x509/certstor.cpp index 10178a526..e068baa18 100644 --- a/src/lib/x509/certstor.cpp +++ b/src/lib/x509/certstor.cpp @@ -13,27 +13,23 @@ namespace Botan { std::shared_ptr<const X509_CRL> Certificate_Store::find_crl_for(const X509_Certificate&) const { - return std::shared_ptr<const X509_CRL>(); + return {}; } void Certificate_Store_In_Memory::add_certificate(const X509_Certificate& cert) { - for(size_t i = 0; i != m_certs.size(); ++i) - { - if(*m_certs[i] == cert) + for(const auto& c : m_certs) + if(*c == cert) return; - } m_certs.push_back(std::make_shared<const X509_Certificate>(cert)); } void Certificate_Store_In_Memory::add_certificate(std::shared_ptr<const X509_Certificate> cert) { - for(size_t i = 0; i != m_certs.size(); ++i) - { - if(*m_certs[i] == *cert) + for(const auto& c : m_certs) + if(*c == *cert) return; - } m_certs.push_back(cert); } @@ -41,8 +37,8 @@ void Certificate_Store_In_Memory::add_certificate(std::shared_ptr<const X509_Cer std::vector<X509_DN> Certificate_Store_In_Memory::all_subjects() const { std::vector<X509_DN> subjects; - for(size_t i = 0; i != m_certs.size(); ++i) - subjects.push_back(m_certs[i]->subject_dn()); + for(const auto& cert : m_certs) + subjects.push_back(cert->subject_dn()); return subjects; } @@ -50,22 +46,22 @@ std::shared_ptr<const X509_Certificate> Certificate_Store_In_Memory::find_cert(const X509_DN& subject_dn, const std::vector<uint8_t>& key_id) const { - for(size_t i = 0; i != m_certs.size(); ++i) + for(const auto& cert : m_certs) { // Only compare key ids if set in both call and in the cert if(key_id.size()) { - std::vector<uint8_t> skid = m_certs[i]->subject_key_id(); + std::vector<uint8_t> skid = cert->subject_key_id(); if(skid.size() && skid != key_id) // no match continue; } - if(m_certs[i]->subject_dn() == subject_dn) - return m_certs[i]; + if(cert->subject_dn() == subject_dn) + return cert; } - return std::shared_ptr<const X509_Certificate>(); + return nullptr; } @@ -75,14 +71,9 @@ Certificate_Store_In_Memory::find_cert_by_pubkey_sha1(const std::vector<uint8_t> if(key_hash.size() != 20) throw Invalid_Argument("Certificate_Store_In_Memory::find_cert_by_pubkey_sha1 invalid hash"); - for(size_t i = 0; i != m_certs.size(); ++i) - { - const std::vector<uint8_t> hash_i = m_certs[i]->subject_public_key_bitstring_sha1(); - if(key_hash == hash_i) - { - return m_certs[i]; - } - } + for(const auto& cert : m_certs) + if(key_hash == cert->subject_public_key_bitstring_sha1()) + return cert; return nullptr; } @@ -97,13 +88,13 @@ void Certificate_Store_In_Memory::add_crl(std::shared_ptr<const X509_CRL> crl) { X509_DN crl_issuer = crl->issuer_dn(); - for(size_t i = 0; i != m_crls.size(); ++i) + for(auto& c : m_crls) { // Found an update of a previously existing one; replace it - if(m_crls[i]->issuer_dn() == crl_issuer) + if(c->issuer_dn() == crl_issuer) { - if(m_crls[i]->this_update() <= crl->this_update()) - m_crls[i] = crl; + if(c->this_update() <= crl->this_update()) + c = crl; return; } } @@ -116,22 +107,22 @@ std::shared_ptr<const X509_CRL> Certificate_Store_In_Memory::find_crl_for(const { const std::vector<uint8_t>& key_id = subject.authority_key_id(); - for(size_t i = 0; i != m_crls.size(); ++i) + for(const auto& c : m_crls) { // Only compare key ids if set in both call and in the CRL if(key_id.size()) { - std::vector<uint8_t> akid = m_crls[i]->authority_key_id(); + std::vector<uint8_t> akid = c->authority_key_id(); if(akid.size() && akid != key_id) // no match continue; } - if(m_crls[i]->issuer_dn() == subject.issuer_dn()) - return m_crls[i]; + if(c->issuer_dn() == subject.issuer_dn()) + return c; } - return std::shared_ptr<const X509_CRL>(); + return {}; } Certificate_Store_In_Memory::Certificate_Store_In_Memory(const X509_Certificate& cert) |