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

Unified Diff: net/base/x509_cert_types.cc

Issue 10826257: Implement SHA-256 fingerprint support (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 4 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_cert_types.cc
===================================================================
--- net/base/x509_cert_types.cc (revision 152095)
+++ net/base/x509_cert_types.cc (working copy)
@@ -38,7 +38,7 @@
} // namespace
// static
-bool IsSHA1HashInSortedArray(const SHA1Fingerprint& hash,
+bool IsSHA1HashInSortedArray(const SHA1HashValue& hash,
const uint8* array,
size_t array_byte_len) {
DCHECK_EQ(0u, array_byte_len % base::kSHA1Length);
@@ -143,4 +143,65 @@
return true;
}
+bool HashValue::Equals(const HashValue& other) const {
+ if (tag != other.tag)
+ return false;
+ switch (tag) {
+ case HASH_VALUE_SHA1:
+ return fingerprint.sha1.Equals(other.fingerprint.sha1);
+ case HASH_VALUE_SHA256:
+ return fingerprint.sha256.Equals(other.fingerprint.sha256);
+ default:
+ NOTREACHED() << "Unknown HashValueTag " << tag;
+ return false;
+ }
+}
+
+size_t HashValue::size() const {
+ switch (tag) {
+ case HASH_VALUE_SHA1:
+ return sizeof(fingerprint.sha1.data);
+ case HASH_VALUE_SHA256:
+ return sizeof(fingerprint.sha256.data);
+ default:
+ NOTREACHED() << "Unknown HashValueTag " << tag;
+ // Although this is NOTREACHED, this function might be inlined and its
+ // return value can be passed to memset as the length argument. If we
+ // returned 0 here, it might result in what appears (in some stages of
+ // compilation) to be a call to to memset with a length argument of 0,
+ // which results in a warning. Therefore, we return a dummy value
+ // here.
+ return sizeof(fingerprint.sha1.data);
+ }
+}
+
+unsigned char* HashValue::data() {
+ return const_cast<unsigned char*>(const_cast<const HashValue*>(this)->data());
+}
+
+const unsigned char* HashValue::data() const {
+ switch (tag) {
+ case HASH_VALUE_SHA1:
+ return fingerprint.sha1.data;
+ case HASH_VALUE_SHA256:
+ return fingerprint.sha256.data;
+ default:
+ NOTREACHED() << "Unknown HashValueTag " << tag;
+ return NULL;
+ }
+}
+
+const char* HashValue::label() const {
+ switch (tag) {
+ case HASH_VALUE_SHA1:
+ return "sha1/";
+ case HASH_VALUE_SHA256:
+ return "sha256/";
+ default:
+ NOTREACHED();
+ LOG(WARNING) << "Invalid fingerprint of unknown type " << tag;
+ return "unknown/";
+ }
+}
+
} // namespace net

Powered by Google App Engine
This is Rietveld 408576698