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

Side by Side Diff: net/quic/core/crypto/common_cert_set.cc

Issue 2740453006: Add QuicStringPiece which is actually StringPiece. (Closed)
Patch Set: fix compile error and rebase Created 3 years, 9 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 unified diff | Download patch
« no previous file with comments | « net/quic/core/crypto/common_cert_set.h ('k') | net/quic/core/crypto/common_cert_set_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/core/crypto/common_cert_set.h" 5 #include "net/quic/core/crypto/common_cert_set.h"
6 6
7 #include <cstddef> 7 #include <cstddef>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/singleton.h" 10 #include "base/memory/singleton.h"
11 #include "net/quic/core/quic_utils.h" 11 #include "net/quic/core/quic_utils.h"
12 12
13 using base::StringPiece;
14 13
15 namespace net { 14 namespace net {
16 15
17 namespace common_cert_set_2 { 16 namespace common_cert_set_2 {
18 #include "net/quic/core/crypto/common_cert_set_2.c" 17 #include "net/quic/core/crypto/common_cert_set_2.c"
19 } 18 }
20 19
21 namespace common_cert_set_3 { 20 namespace common_cert_set_3 {
22 #include "net/quic/core/crypto/common_cert_set_3.c" 21 #include "net/quic/core/crypto/common_cert_set_3.c"
23 } 22 }
(...skipping 22 matching lines...) Expand all
46 common_cert_set_3::kLens, common_cert_set_3::kHash, 45 common_cert_set_3::kLens, common_cert_set_3::kHash,
47 }, 46 },
48 }; 47 };
49 48
50 const uint64_t kSetHashes[] = { 49 const uint64_t kSetHashes[] = {
51 common_cert_set_2::kHash, common_cert_set_3::kHash, 50 common_cert_set_2::kHash, common_cert_set_3::kHash,
52 }; 51 };
53 52
54 // Compare returns a value less than, equal to or greater than zero if |a| is 53 // Compare returns a value less than, equal to or greater than zero if |a| is
55 // lexicographically less than, equal to or greater than |b|, respectively. 54 // lexicographically less than, equal to or greater than |b|, respectively.
56 int Compare(StringPiece a, const unsigned char* b, size_t b_len) { 55 int Compare(QuicStringPiece a, const unsigned char* b, size_t b_len) {
57 size_t len = a.size(); 56 size_t len = a.size();
58 if (len > b_len) { 57 if (len > b_len) {
59 len = b_len; 58 len = b_len;
60 } 59 }
61 int n = memcmp(a.data(), b, len); 60 int n = memcmp(a.data(), b, len);
62 if (n != 0) { 61 if (n != 0) {
63 return n; 62 return n;
64 } 63 }
65 64
66 if (a.size() < b_len) { 65 if (a.size() < b_len) {
67 return -1; 66 return -1;
68 } else if (a.size() > b_len) { 67 } else if (a.size() > b_len) {
69 return 1; 68 return 1;
70 } 69 }
71 return 0; 70 return 0;
72 } 71 }
73 72
74 // CommonCertSetsQUIC implements the CommonCertSets interface using the default 73 // CommonCertSetsQUIC implements the CommonCertSets interface using the default
75 // certificate sets. 74 // certificate sets.
76 class CommonCertSetsQUIC : public CommonCertSets { 75 class CommonCertSetsQUIC : public CommonCertSets {
77 public: 76 public:
78 // CommonCertSets interface. 77 // CommonCertSets interface.
79 StringPiece GetCommonHashes() const override { 78 QuicStringPiece GetCommonHashes() const override {
80 return StringPiece(reinterpret_cast<const char*>(kSetHashes), 79 return QuicStringPiece(reinterpret_cast<const char*>(kSetHashes),
81 sizeof(uint64_t) * arraysize(kSetHashes)); 80 sizeof(uint64_t) * arraysize(kSetHashes));
82 } 81 }
83 82
84 StringPiece GetCert(uint64_t hash, uint32_t index) const override { 83 QuicStringPiece GetCert(uint64_t hash, uint32_t index) const override {
85 for (size_t i = 0; i < arraysize(kSets); i++) { 84 for (size_t i = 0; i < arraysize(kSets); i++) {
86 if (kSets[i].hash == hash) { 85 if (kSets[i].hash == hash) {
87 if (index < kSets[i].num_certs) { 86 if (index < kSets[i].num_certs) {
88 return StringPiece( 87 return QuicStringPiece(
89 reinterpret_cast<const char*>(kSets[i].certs[index]), 88 reinterpret_cast<const char*>(kSets[i].certs[index]),
90 kSets[i].lens[index]); 89 kSets[i].lens[index]);
91 } 90 }
92 break; 91 break;
93 } 92 }
94 } 93 }
95 94
96 return StringPiece(); 95 return QuicStringPiece();
97 } 96 }
98 97
99 bool MatchCert(StringPiece cert, 98 bool MatchCert(QuicStringPiece cert,
100 StringPiece common_set_hashes, 99 QuicStringPiece common_set_hashes,
101 uint64_t* out_hash, 100 uint64_t* out_hash,
102 uint32_t* out_index) const override { 101 uint32_t* out_index) const override {
103 if (common_set_hashes.size() % sizeof(uint64_t) != 0) { 102 if (common_set_hashes.size() % sizeof(uint64_t) != 0) {
104 return false; 103 return false;
105 } 104 }
106 105
107 for (size_t i = 0; i < common_set_hashes.size() / sizeof(uint64_t); i++) { 106 for (size_t i = 0; i < common_set_hashes.size() / sizeof(uint64_t); i++) {
108 uint64_t hash; 107 uint64_t hash;
109 memcpy(&hash, common_set_hashes.data() + i * sizeof(uint64_t), 108 memcpy(&hash, common_set_hashes.data() + i * sizeof(uint64_t),
110 sizeof(uint64_t)); 109 sizeof(uint64_t));
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 } // anonymous namespace 157 } // anonymous namespace
159 158
160 CommonCertSets::~CommonCertSets() {} 159 CommonCertSets::~CommonCertSets() {}
161 160
162 // static 161 // static
163 const CommonCertSets* CommonCertSets::GetInstanceQUIC() { 162 const CommonCertSets* CommonCertSets::GetInstanceQUIC() {
164 return CommonCertSetsQUIC::GetInstance(); 163 return CommonCertSetsQUIC::GetInstance();
165 } 164 }
166 165
167 } // namespace net 166 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/core/crypto/common_cert_set.h ('k') | net/quic/core/crypto/common_cert_set_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698