Chromium Code Reviews| Index: net/base/x509_openssl_util.cc |
| diff --git a/net/base/x509_openssl_util.cc b/net/base/x509_openssl_util.cc |
| index 22ab59aab3ac3a6ff8bf19abb1f0f47517972cfb..be00bcd3d11d078a02cfa16e1da54a5d9c72be2d 100644 |
| --- a/net/base/x509_openssl_util.cc |
| +++ b/net/base/x509_openssl_util.cc |
| @@ -5,29 +5,13 @@ |
| #include "net/base/x509_openssl_util.h" |
| #include "base/logging.h" |
| -#include "base/string_number_conversions.h" |
| #include "base/string_piece.h" |
| -#include "base/time.h" |
| +#include "net/base/x509_cert_types.h" |
| namespace net { |
| namespace x509_openssl_util { |
| -namespace { |
| - |
| -// Helper for ParseDate. |*field| must contain at least |field_len| characters. |
| -// |*field| will be advanced by |field_len| on exit. |*ok| is set to false if |
| -// there is an error in parsing the number, but left untouched otherwise. |
| -// Returns the parsed integer. |
| -int ParseIntAndAdvance(const char** field, size_t field_len, bool* ok) { |
| - int result = 0; |
| - *ok &= base::StringToInt(*field, *field + field_len, &result); |
| - *field += field_len; |
| - return result; |
| -} |
| - |
| -} // namespace |
| - |
| bool ParsePrincipalKeyAndValueByIndex(X509_NAME* name, |
| int index, |
| std::string* key, |
| @@ -77,35 +61,11 @@ bool ParseDate(ASN1_TIME* x509_time, base::Time* time) { |
| base::StringPiece str_date(reinterpret_cast<const char*>(x509_time->data), |
| x509_time->length); |
| - // UTCTime: YYMMDDHHMMSSZ |
| - // GeneralizedTime: YYYYMMDDHHMMSSZ |
| - size_t year_length = x509_time->type == V_ASN1_UTCTIME ? 2 : 4; |
| - |
| - if (str_date.length() < 11 + year_length) |
| - return false; |
| - |
| - const char* field = str_date.data(); |
| - bool valid = true; |
| - base::Time::Exploded exploded = {0}; |
| - exploded.year = ParseIntAndAdvance(&field, year_length, &valid); |
| - exploded.month = ParseIntAndAdvance(&field, 2, &valid); |
| - exploded.day_of_month = ParseIntAndAdvance(&field, 2, &valid); |
| - exploded.hour = ParseIntAndAdvance(&field, 2, &valid); |
| - exploded.minute = ParseIntAndAdvance(&field, 2, &valid); |
| - exploded.second = ParseIntAndAdvance(&field, 2, &valid); |
| - if (valid && year_length == 2) |
| - exploded.year += exploded.year < 50 ? 2000 : 1900; |
| - |
| - valid &= exploded.HasValidValues(); |
| - |
| - if (!valid) { |
| - NOTREACHED() << "can't parse x509 date " << str_date; |
| - return false; |
| - } |
| - |
| - *time = base::Time::FromUTCExploded(exploded); |
| - return true; |
| + CertificateDateFormat format = |
| + x509_time->type == V_ASN1_UTCTIME ? CERT_DATE_FORMAT_UTC_TIME |
| + : CERT_DATE_FORMAT_GENERALIZED_TIME; |
|
wtc
2010/11/11 01:33:52
Nit: we have a convention to break an expression a
|
| + return ParseCertificateDate(str_date, format, time); |
| } |
| } // namespace x509_openssl_util |