Index: net/base/x509_certificate.cc |
diff --git a/net/base/x509_certificate.cc b/net/base/x509_certificate.cc |
index 089bf096ff396fd10686af7250db78ef969eb105..91ed346d010d3d504dab36fbb9daea7c31c3f8a8 100644 |
--- a/net/base/x509_certificate.cc |
+++ b/net/base/x509_certificate.cc |
@@ -4,6 +4,8 @@ |
#include "net/base/x509_certificate.h" |
+#include <stdlib.h> |
+ |
#include <map> |
#include <string> |
#include <vector> |
@@ -12,6 +14,7 @@ |
#include "base/logging.h" |
#include "base/memory/singleton.h" |
#include "base/metrics/histogram.h" |
+#include "base/sha1.h" |
#include "base/string_piece.h" |
#include "base/string_util.h" |
#include "base/time.h" |
@@ -113,6 +116,12 @@ X509Certificate* X509CertificateCache::Find( |
return pos->second; |
}; |
+// CompareSHA1Hashes is a helper function for using bsearch() with an array of |
+// SHA1 hashes. |
+static int CompareSHA1Hashes(const void* a, const void* b) { |
+ return memcmp(a, b, base::SHA1_LENGTH); |
+} |
+ |
} // namespace |
bool X509Certificate::LessThan::operator()(X509Certificate* lhs, |
@@ -528,4 +537,14 @@ bool X509Certificate::IsBlacklisted() const { |
return false; |
} |
+// static |
+bool X509Certificate::IsSHA1HashInSortedArray(const SHA1Fingerprint& hash, |
+ const uint8* array, |
+ size_t array_byte_len) { |
+ DCHECK_EQ(0u, array_byte_len % base::SHA1_LENGTH); |
+ const unsigned arraylen = array_byte_len / base::SHA1_LENGTH; |
+ return NULL != bsearch(hash.data, array, arraylen, base::SHA1_LENGTH, |
+ CompareSHA1Hashes); |
+} |
+ |
} // namespace net |