Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/base/x509_cert_types.h" | 5 #include "net/base/x509_cert_types.h" |
| 6 | 6 |
| 7 #include <cstdlib> | 7 #include <cstdlib> |
| 8 #include <cstring> | 8 #include <cstring> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 31 | 31 |
| 32 // CompareSHA1Hashes is a helper function for using bsearch() with an array of | 32 // CompareSHA1Hashes is a helper function for using bsearch() with an array of |
| 33 // SHA1 hashes. | 33 // SHA1 hashes. |
| 34 int CompareSHA1Hashes(const void* a, const void* b) { | 34 int CompareSHA1Hashes(const void* a, const void* b) { |
| 35 return memcmp(a, b, base::kSHA1Length); | 35 return memcmp(a, b, base::kSHA1Length); |
| 36 } | 36 } |
| 37 | 37 |
| 38 } // namespace | 38 } // namespace |
| 39 | 39 |
| 40 // static | 40 // static |
| 41 bool IsSHA1HashInSortedArray(const SHA1Fingerprint& hash, | 41 bool IsSHA1HashInSortedArray(const SHA1HashValue& hash, |
| 42 const uint8* array, | 42 const uint8* array, |
| 43 size_t array_byte_len) { | 43 size_t array_byte_len) { |
| 44 DCHECK_EQ(0u, array_byte_len % base::kSHA1Length); | 44 DCHECK_EQ(0u, array_byte_len % base::kSHA1Length); |
| 45 const size_t arraylen = array_byte_len / base::kSHA1Length; | 45 const size_t arraylen = array_byte_len / base::kSHA1Length; |
| 46 return NULL != bsearch(hash.data, array, arraylen, base::kSHA1Length, | 46 return NULL != bsearch(hash.data, array, arraylen, base::kSHA1Length, |
| 47 CompareSHA1Hashes); | 47 CompareSHA1Hashes); |
| 48 } | 48 } |
| 49 | 49 |
| 50 CertPrincipal::CertPrincipal() { | 50 CertPrincipal::CertPrincipal() { |
| 51 } | 51 } |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 136 | 136 |
| 137 valid &= exploded.HasValidValues(); | 137 valid &= exploded.HasValidValues(); |
| 138 | 138 |
| 139 if (!valid) | 139 if (!valid) |
| 140 return false; | 140 return false; |
| 141 | 141 |
| 142 *time = base::Time::FromUTCExploded(exploded); | 142 *time = base::Time::FromUTCExploded(exploded); |
| 143 return true; | 143 return true; |
| 144 } | 144 } |
| 145 | 145 |
| 146 bool HashValue::Equals(const HashValue& other) const { | |
| 147 if (tag != other.tag) | |
| 148 return false; | |
| 149 switch (tag) { | |
| 150 case HASH_VALUE_SHA1: | |
| 151 return fingerprint.sha1.Equals(other.fingerprint.sha1); | |
| 152 case HASH_VALUE_SHA256: | |
| 153 return fingerprint.sha256.Equals(other.fingerprint.sha256); | |
| 154 default: | |
| 155 NOTREACHED() << "Unknown HashValueTag " << tag; | |
| 156 return false; | |
| 157 } | |
| 158 } | |
| 159 | |
| 160 size_t HashValue::size() const { | |
| 161 switch (tag) { | |
| 162 case HASH_VALUE_SHA1: | |
| 163 return sizeof(fingerprint.sha1.data); | |
| 164 case HASH_VALUE_SHA256: | |
| 165 return sizeof(fingerprint.sha256.data); | |
| 166 default: | |
| 167 NOTREACHED() << "Unknown HashValueTag " << tag; | |
| 168 // Although this is NOTREACHED, this function might be inlined and its | |
| 169 // return value can be passed to memset as the length argument. If we | |
| 170 // returned 0 here, it might result in what appears (in some stages of | |
| 171 // compilation) to be a call to to memset with a length argument of 0, | |
| 172 // which results in a warning. Therefore, we return a dummy value | |
| 173 // here. | |
| 174 return sizeof(fingerprint.sha1.data); | |
| 175 } | |
| 176 } | |
| 177 | |
| 178 unsigned char* HashValue::data() { | |
| 179 return const_cast<unsigned char*>(const_cast<const HashValue*>(this)->data()); | |
| 180 } | |
| 181 | |
| 182 const unsigned char* HashValue::data() const { | |
| 183 switch (tag) { | |
| 184 case HASH_VALUE_SHA1: | |
| 185 return fingerprint.sha1.data; | |
| 186 case HASH_VALUE_SHA256: | |
| 187 return fingerprint.sha256.data; | |
| 188 default: | |
| 189 NOTREACHED() << "Unknown HashValueTag " << tag; | |
| 190 return NULL; | |
| 191 } | |
| 192 } | |
| 193 | |
| 194 const char* HashValue::label() const { | |
| 195 switch (tag) { | |
| 196 case HASH_VALUE_SHA1: | |
| 197 return "sha1/"; | |
| 198 case HASH_VALUE_SHA256: | |
| 199 return "sha256/"; | |
| 200 default: | |
| 201 NOTREACHED(); | |
| 202 LOG(WARNING) << "Invalid fingerprint of unknown type " << tag; | |
| 203 return "unknown/"; | |
| 204 } | |
| 205 } | |
|
Ryan Sleevi
2012/08/23 22:48:20
nit: This format for labels - is it intrinsic to a
palmer
2012/08/29 00:01:24
Yeah, you are right. Moved to a static method in T
| |
| 206 | |
| 146 } // namespace net | 207 } // namespace net |
| OLD | NEW |