OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/quic/crypto/common_cert_set.h" | 5 #include "net/quic/crypto/common_cert_set.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "net/quic/quic_utils.h" | 9 #include "net/quic/quic_utils.h" |
10 | 10 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 | 46 |
47 CommonCertSetsQUIC::CommonCertSetsQUIC() { | 47 CommonCertSetsQUIC::CommonCertSetsQUIC() { |
48 } | 48 } |
49 | 49 |
50 StringPiece CommonCertSetsQUIC::GetCommonHashes() const { | 50 StringPiece CommonCertSetsQUIC::GetCommonHashes() const { |
51 return StringPiece(reinterpret_cast<const char*>(kSetHashes), | 51 return StringPiece(reinterpret_cast<const char*>(kSetHashes), |
52 sizeof(uint64) * arraysize(kSetHashes)); | 52 sizeof(uint64) * arraysize(kSetHashes)); |
53 } | 53 } |
54 | 54 |
55 StringPiece CommonCertSetsQUIC::GetCert(uint64 hash, uint32 index) const { | 55 StringPiece CommonCertSetsQUIC::GetCert(uint64 hash, uint32 index) const { |
| 56 StringPiece cert; |
56 for (size_t i = 0; i < arraysize(kSets); i++) { | 57 for (size_t i = 0; i < arraysize(kSets); i++) { |
57 if (kSets[i].hash == hash) { | 58 if (kSets[i].hash == hash) { |
58 if (index >= kSets[i].num_certs) { | 59 if (index < kSets[i].num_certs) { |
59 return StringPiece(); | 60 cert.set(kSets[i].certs[index], kSets[i].lens[index]); |
60 } | 61 } |
61 return StringPiece(reinterpret_cast<const char*>(kSets[i].certs[index]), | 62 break; |
62 kSets[i].lens[index]); | |
63 } | 63 } |
64 } | 64 } |
65 | 65 |
66 return StringPiece(); | 66 return cert; |
67 } | 67 } |
68 | 68 |
69 // Compare returns a value less than, equal to or greater than zero if |a| is | 69 // Compare returns a value less than, equal to or greater than zero if |a| is |
70 // lexicographically less than, equal to or greater than |b|, respectively. | 70 // lexicographically less than, equal to or greater than |b|, respectively. |
71 static int Compare(StringPiece a, const unsigned char* b, size_t b_len) { | 71 static int Compare(StringPiece a, const unsigned char* b, size_t b_len) { |
72 size_t len = a.size(); | 72 size_t len = a.size(); |
73 if (len > b_len) { | 73 if (len > b_len) { |
74 len = b_len; | 74 len = b_len; |
75 } | 75 } |
76 int n = memcmp(a.data(), b, len); | 76 int n = memcmp(a.data(), b, len); |
(...skipping 26 matching lines...) Expand all Loading... |
103 continue; | 103 continue; |
104 } | 104 } |
105 | 105 |
106 if (kSets[j].num_certs == 0) { | 106 if (kSets[j].num_certs == 0) { |
107 continue; | 107 continue; |
108 } | 108 } |
109 | 109 |
110 // Binary search for a matching certificate. | 110 // Binary search for a matching certificate. |
111 size_t min = 0; | 111 size_t min = 0; |
112 size_t max = kSets[j].num_certs - 1; | 112 size_t max = kSets[j].num_certs - 1; |
113 for (;;) { | 113 while (max >= min) { |
114 if (max < min) { | |
115 break; | |
116 } | |
117 | |
118 size_t mid = min + ((max - min) / 2); | 114 size_t mid = min + ((max - min) / 2); |
119 int n = Compare(cert, kSets[j].certs[mid], kSets[j].lens[mid]); | 115 int n = Compare(cert, kSets[j].certs[mid], kSets[j].lens[mid]); |
120 if (n < 0) { | 116 if (n < 0) { |
121 if (mid == 0) { | 117 if (mid == 0) { |
122 break; | 118 break; |
123 } | 119 } |
124 max = mid - 1; | 120 max = mid - 1; |
125 } else if (n > 0) { | 121 } else if (n > 0) { |
126 min = mid + 1; | 122 min = mid + 1; |
127 } else { | 123 } else { |
128 *out_hash = hash; | 124 *out_hash = hash; |
129 *out_index = mid; | 125 *out_index = mid; |
130 return true; | 126 return true; |
131 } | 127 } |
132 } | 128 } |
133 } | 129 } |
134 } | 130 } |
135 | 131 |
136 return false; | 132 return false; |
137 } | 133 } |
138 | 134 |
139 } // namespace net | 135 } // namespace net |
OLD | NEW |