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/cert/x509_cert_types.h" | 5 #include "net/cert/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" |
| 11 #include "base/strings/string_number_conversions.h" | |
| 12 #include "base/strings/string_piece.h" | 11 #include "base/strings/string_piece.h" |
| 13 #include "base/time/time.h" | 12 #include "base/time/time.h" |
| 13 #include "net/base/parse_number.h" | |
| 14 #include "net/cert/x509_certificate.h" | 14 #include "net/cert/x509_certificate.h" |
| 15 | 15 |
| 16 namespace net { | 16 namespace net { |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 // Helper for ParseCertificateDate. |*field| must contain at least | 20 // Helper for ParseCertificateDate. |*field| must contain at least |
| 21 // |field_len| characters. |*field| will be advanced by |field_len| on exit. | 21 // |field_len| characters. |*field| will be advanced by |field_len| on exit. |
| 22 // |*ok| is set to false if there is an error in parsing the number, but left | 22 // |*ok| is set to false if there is an error in parsing the number, but left |
| 23 // untouched otherwise. Returns the parsed integer. | 23 // untouched otherwise. Returns the parsed integer. |
| 24 int ParseIntAndAdvance(const char** field, size_t field_len, bool* ok) { | 24 int ParseIntAndAdvance(const char** field, size_t field_len, bool* ok) { |
| 25 int result = 0; | 25 int result = 0; |
| 26 *ok &= base::StringToInt(base::StringPiece(*field, field_len), &result); | 26 *ok &= |
| 27 ParseNonNegativeDecimalInt(base::StringPiece(*field, field_len), &result); | |
| 27 *field += field_len; | 28 *field += field_len; |
| 28 return result; | 29 return result; |
| 29 } | 30 } |
| 30 | 31 |
| 31 } | 32 } |
| 32 | 33 |
| 33 CertPrincipal::CertPrincipal() { | 34 CertPrincipal::CertPrincipal() { |
| 34 } | 35 } |
| 35 | 36 |
| 36 CertPrincipal::CertPrincipal(const std::string& name) : common_name(name) {} | 37 CertPrincipal::CertPrincipal(const std::string& name) : common_name(name) {} |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 60 const char* field = raw_date.data(); | 61 const char* field = raw_date.data(); |
| 61 bool valid = true; | 62 bool valid = true; |
| 62 base::Time::Exploded exploded = {0}; | 63 base::Time::Exploded exploded = {0}; |
| 63 | 64 |
| 64 exploded.year = ParseIntAndAdvance(&field, year_length, &valid); | 65 exploded.year = ParseIntAndAdvance(&field, year_length, &valid); |
| 65 exploded.month = ParseIntAndAdvance(&field, 2, &valid); | 66 exploded.month = ParseIntAndAdvance(&field, 2, &valid); |
| 66 exploded.day_of_month = ParseIntAndAdvance(&field, 2, &valid); | 67 exploded.day_of_month = ParseIntAndAdvance(&field, 2, &valid); |
| 67 exploded.hour = ParseIntAndAdvance(&field, 2, &valid); | 68 exploded.hour = ParseIntAndAdvance(&field, 2, &valid); |
| 68 exploded.minute = ParseIntAndAdvance(&field, 2, &valid); | 69 exploded.minute = ParseIntAndAdvance(&field, 2, &valid); |
| 69 exploded.second = ParseIntAndAdvance(&field, 2, &valid); | 70 exploded.second = ParseIntAndAdvance(&field, 2, &valid); |
| 70 if (valid && year_length == 2) | 71 if (valid && year_length == 2) |
|
eroman
2016/03/23 19:39:10
Because of this line, negative years were not caug
| |
| 71 exploded.year += exploded.year < 50 ? 2000 : 1900; | 72 exploded.year += exploded.year < 50 ? 2000 : 1900; |
| 72 | 73 |
| 73 valid &= exploded.HasValidValues(); | 74 valid &= exploded.HasValidValues(); |
| 74 | 75 |
| 75 if (!valid) | 76 if (!valid) |
| 76 return false; | 77 return false; |
| 77 | 78 |
| 78 *time = base::Time::FromUTCExploded(exploded); | 79 *time = base::Time::FromUTCExploded(exploded); |
| 79 return true; | 80 return true; |
| 80 } | 81 } |
| 81 | 82 |
| 82 } // namespace net | 83 } // namespace net |
| OLD | NEW |