| Index: net/base/x509_cert_types.cc
|
| diff --git a/net/base/x509_cert_types.cc b/net/base/x509_cert_types.cc
|
| index 5dfc57acfa529a45353ce991fc221c4f739c80f4..1f6f4a7e7473751bf6402b4e934443df5d54c211 100644
|
| --- a/net/base/x509_cert_types.cc
|
| +++ b/net/base/x509_cert_types.cc
|
| @@ -8,9 +8,27 @@
|
|
|
| #include "net/base/x509_certificate.h"
|
| #include "base/logging.h"
|
| +#include "base/string_number_conversions.h"
|
| +#include "base/string_piece.h"
|
| +#include "base/time.h"
|
|
|
| namespace net {
|
|
|
| +namespace {
|
| +
|
| +// Helper for ParseCertificateDate. |*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 match(const std::string &str, const std::string &against) {
|
| // TODO(snej): Use the full matching rules specified in RFC 5280 sec. 7.1
|
| // including trimming and case-folding: <http://www.ietf.org/rfc/rfc5280.txt>.
|
| @@ -135,4 +153,34 @@ bool CertPolicy::HasDeniedCert() const {
|
| return !denied_.empty();
|
| }
|
|
|
| +bool ParseCertificateDate(const base::StringPiece& raw_date,
|
| + CertificateDateFormat format,
|
| + base::Time* time) {
|
| + size_t year_length = format == CERT_DATE_FORMAT_UTC_TIME ? 2 : 4;
|
| +
|
| + if (raw_date.length() < 11 + year_length)
|
| + return false;
|
| +
|
| + const char* field = raw_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)
|
| + return false;
|
| +
|
| + *time = base::Time::FromUTCExploded(exploded);
|
| + return true;
|
| +}
|
| +
|
| } // namespace net
|
|
|