| 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 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 tokenizer.set_options(base::StringTokenizer::RETURN_DELIMS); | 189 tokenizer.set_options(base::StringTokenizer::RETURN_DELIMS); |
| 190 tokenizer.set_quote_chars("\""); | 190 tokenizer.set_quote_chars("\""); |
| 191 std::string unquoted; | 191 std::string unquoted; |
| 192 while (tokenizer.GetNext()) { | 192 while (tokenizer.GetNext()) { |
| 193 DCHECK(!tokenizer.token_is_delim() || tokenizer.token().length() == 1); | 193 DCHECK(!tokenizer.token_is_delim() || tokenizer.token().length() == 1); |
| 194 switch (state) { | 194 switch (state) { |
| 195 case START: | 195 case START: |
| 196 case DIRECTIVE_END: | 196 case DIRECTIVE_END: |
| 197 if (IsAsciiWhitespace(*tokenizer.token_begin())) | 197 if (IsAsciiWhitespace(*tokenizer.token_begin())) |
| 198 continue; | 198 continue; |
| 199 if (LowerCaseEqualsASCII(tokenizer.token(), "max-age")) { | 199 if (base::LowerCaseEqualsASCII(tokenizer.token(), "max-age")) { |
| 200 state = AFTER_MAX_AGE_LABEL; | 200 state = AFTER_MAX_AGE_LABEL; |
| 201 max_age_observed++; | 201 max_age_observed++; |
| 202 } else if (LowerCaseEqualsASCII(tokenizer.token(), | 202 } else if (base::LowerCaseEqualsASCII(tokenizer.token(), |
| 203 "includesubdomains")) { | 203 "includesubdomains")) { |
| 204 state = AFTER_INCLUDE_SUBDOMAINS; | 204 state = AFTER_INCLUDE_SUBDOMAINS; |
| 205 include_subdomains_observed++; | 205 include_subdomains_observed++; |
| 206 include_subdomains_candidate = true; | 206 include_subdomains_candidate = true; |
| 207 } else { | 207 } else { |
| 208 state = AFTER_UNKNOWN_LABEL; | 208 state = AFTER_UNKNOWN_LABEL; |
| 209 } | 209 } |
| 210 break; | 210 break; |
| 211 | 211 |
| 212 case AFTER_MAX_AGE_LABEL: | 212 case AFTER_MAX_AGE_LABEL: |
| 213 if (IsAsciiWhitespace(*tokenizer.token_begin())) | 213 if (IsAsciiWhitespace(*tokenizer.token_begin())) |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 std::string source = value; | 286 std::string source = value; |
| 287 | 287 |
| 288 while (!source.empty()) { | 288 while (!source.empty()) { |
| 289 StringPair semicolon = Split(source, ';'); | 289 StringPair semicolon = Split(source, ';'); |
| 290 semicolon.first = Strip(semicolon.first); | 290 semicolon.first = Strip(semicolon.first); |
| 291 semicolon.second = Strip(semicolon.second); | 291 semicolon.second = Strip(semicolon.second); |
| 292 StringPair equals = Split(semicolon.first, '='); | 292 StringPair equals = Split(semicolon.first, '='); |
| 293 equals.first = Strip(equals.first); | 293 equals.first = Strip(equals.first); |
| 294 equals.second = Strip(equals.second); | 294 equals.second = Strip(equals.second); |
| 295 | 295 |
| 296 if (LowerCaseEqualsASCII(equals.first, "max-age")) { | 296 if (base::LowerCaseEqualsASCII(equals.first, "max-age")) { |
| 297 if (equals.second.empty() || | 297 if (equals.second.empty() || |
| 298 !MaxAgeToInt(equals.second.begin(), equals.second.end(), | 298 !MaxAgeToInt(equals.second.begin(), equals.second.end(), |
| 299 &max_age_candidate)) { | 299 &max_age_candidate)) { |
| 300 return false; | 300 return false; |
| 301 } | 301 } |
| 302 parsed_max_age = true; | 302 parsed_max_age = true; |
| 303 } else if (LowerCaseEqualsASCII(equals.first, "pin-sha1")) { | 303 } else if (base::LowerCaseEqualsASCII(equals.first, "pin-sha1")) { |
| 304 if (!ParseAndAppendPin(equals.second, HASH_VALUE_SHA1, &pins)) | 304 if (!ParseAndAppendPin(equals.second, HASH_VALUE_SHA1, &pins)) |
| 305 return false; | 305 return false; |
| 306 } else if (LowerCaseEqualsASCII(equals.first, "pin-sha256")) { | 306 } else if (base::LowerCaseEqualsASCII(equals.first, "pin-sha256")) { |
| 307 if (!ParseAndAppendPin(equals.second, HASH_VALUE_SHA256, &pins)) | 307 if (!ParseAndAppendPin(equals.second, HASH_VALUE_SHA256, &pins)) |
| 308 return false; | 308 return false; |
| 309 } else if (LowerCaseEqualsASCII(equals.first, "includesubdomains")) { | 309 } else if (base::LowerCaseEqualsASCII(equals.first, "includesubdomains")) { |
| 310 include_subdomains_candidate = true; | 310 include_subdomains_candidate = true; |
| 311 } else { | 311 } else { |
| 312 // Silently ignore unknown directives for forward compatibility. | 312 // Silently ignore unknown directives for forward compatibility. |
| 313 } | 313 } |
| 314 | 314 |
| 315 source = semicolon.second; | 315 source = semicolon.second; |
| 316 } | 316 } |
| 317 | 317 |
| 318 if (!parsed_max_age) | 318 if (!parsed_max_age) |
| 319 return false; | 319 return false; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 336 } | 336 } |
| 337 | 337 |
| 338 if (!found) | 338 if (!found) |
| 339 hashes->push_back(*i); | 339 hashes->push_back(*i); |
| 340 } | 340 } |
| 341 | 341 |
| 342 return true; | 342 return true; |
| 343 } | 343 } |
| 344 | 344 |
| 345 } // namespace net | 345 } // namespace net |
| OLD | NEW |