Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1611)

Unified Diff: net/base/x509_certificate.cc

Issue 6793041: net: add ability to distinguish user-added root CAs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ... Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698