Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(153)

Unified Diff: net/base/x509_openssl_util.cc

Issue 4653002: Cleanup X509CertificateMac style nits (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase before commit Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/base/x509_certificate_mac.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/x509_openssl_util.cc
diff --git a/net/base/x509_openssl_util.cc b/net/base/x509_openssl_util.cc
index 0bb40023d29ee98de092911e990d63ecfe7e06df..81424cccaab40d81b660e200b3b82bc0754adab8 100644
--- a/net/base/x509_openssl_util.cc
+++ b/net/base/x509_openssl_util.cc
@@ -5,30 +5,14 @@
#include "net/base/x509_openssl_util.h"
#include "base/logging.h"
-#include "base/string_number_conversions.h"
#include "base/string_piece.h"
#include "base/string_util.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,
@@ -78,35 +62,10 @@ 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;
+ CertDateFormat format = x509_time->type == V_ASN1_UTCTIME ?
+ CERT_DATE_FORMAT_UTC_TIME : CERT_DATE_FORMAT_GENERALIZED_TIME;
+ return ParseCertificateDate(str_date, format, time);
}
// TODO(joth): Investigate if we can upstream this into the OpenSSL library,
@@ -225,6 +184,6 @@ bool VerifyHostname(const std::string& hostname,
return false;
}
-} // namespace x509_openssl_util
+} // namespace x509_openssl_util
-} // namespace net
+} // namespace net
« no previous file with comments | « net/base/x509_certificate_mac.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698