From 8e272045fbf58223be5d8cffa2f1592380dd79a7 Mon Sep 17 00:00:00 2001 From: Nuno Goncalves Date: Sun, 5 Mar 2017 11:18:27 +0100 Subject: Refactor find_cert_by_pubkey_sha1 to reuse hash object Signed-off-by: Nuno Goncalves --- src/lib/x509/certstor.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/lib') diff --git a/src/lib/x509/certstor.cpp b/src/lib/x509/certstor.cpp index e068baa18..63a5cd645 100644 --- a/src/lib/x509/certstor.cpp +++ b/src/lib/x509/certstor.cpp @@ -71,9 +71,13 @@ Certificate_Store_In_Memory::find_cert_by_pubkey_sha1(const std::vector if(key_hash.size() != 20) throw Invalid_Argument("Certificate_Store_In_Memory::find_cert_by_pubkey_sha1 invalid hash"); - for(const auto& cert : m_certs) - if(key_hash == cert->subject_public_key_bitstring_sha1()) + std::unique_ptr hash(HashFunction::create("SHA-1")); + + for(const auto& cert : m_certs){ + hash->update(cert->subject_public_key_bitstring()); + if(key_hash == hash->final_stdvec()) //final_stdvec also clears the hash to initial state return cert; + } return nullptr; } -- cgit v1.2.3