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 "base/base64.h" | 5 #include "base/base64.h" |
6 #include "base/basictypes.h" | 6 #include "base/basictypes.h" |
7 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
8 #include "base/strings/string_tokenizer.h" | 8 #include "base/strings/string_tokenizer.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "net/http/http_security_headers.h" | 10 #include "net/http/http_security_headers.h" |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 pair.first = source.substr(0, point); | 111 pair.first = source.substr(0, point); |
112 if (std::string::npos != point) | 112 if (std::string::npos != point) |
113 pair.second = source.substr(point + 1); | 113 pair.second = source.substr(point + 1); |
114 | 114 |
115 return pair; | 115 return pair; |
116 } | 116 } |
117 | 117 |
118 bool ParseAndAppendPin(const std::string& value, | 118 bool ParseAndAppendPin(const std::string& value, |
119 HashValueTag tag, | 119 HashValueTag tag, |
120 HashValueVector* hashes) { | 120 HashValueVector* hashes) { |
| 121 // Pins are always quoted. |
| 122 if (value.empty() || !HttpUtil::IsQuote(value[0])) |
| 123 return false; |
| 124 |
121 std::string unquoted = HttpUtil::Unquote(value); | 125 std::string unquoted = HttpUtil::Unquote(value); |
122 std::string decoded; | |
123 | |
124 if (unquoted.empty()) | 126 if (unquoted.empty()) |
125 return false; | 127 return false; |
126 | 128 |
| 129 std::string decoded; |
127 if (!base::Base64Decode(unquoted, &decoded)) | 130 if (!base::Base64Decode(unquoted, &decoded)) |
128 return false; | 131 return false; |
129 | 132 |
130 HashValue hash(tag); | 133 HashValue hash(tag); |
131 if (decoded.size() != hash.size()) | 134 if (decoded.size() != hash.size()) |
132 return false; | 135 return false; |
133 | 136 |
134 memcpy(hash.data(), decoded.data(), hash.size()); | 137 memcpy(hash.data(), decoded.data(), hash.size()); |
135 hashes->push_back(hash); | 138 hashes->push_back(hash); |
136 return true; | 139 return true; |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 } | 339 } |
337 | 340 |
338 if (!found) | 341 if (!found) |
339 hashes->push_back(*i); | 342 hashes->push_back(*i); |
340 } | 343 } |
341 | 344 |
342 return true; | 345 return true; |
343 } | 346 } |
344 | 347 |
345 } // namespace net | 348 } // namespace net |
OLD | NEW |