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

Side by Side Diff: net/der/parse_values.cc

Issue 2075783002: Adding additional comparison operators for GeneralizedTime. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add unittest. Created 4 years, 6 months 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 unified diff | Download patch
« no previous file with comments | « net/der/parse_values.h ('k') | net/der/parse_values_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 <tuple> 5 #include <tuple>
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/numerics/safe_math.h" 8 #include "base/numerics/safe_math.h"
9 #include "net/der/parse_values.h" 9 #include "net/der/parse_values.h"
10 10
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 *out = BitString(bytes, unused_bits); 277 *out = BitString(bytes, unused_bits);
278 return true; 278 return true;
279 } 279 }
280 280
281 bool operator<(const GeneralizedTime& lhs, const GeneralizedTime& rhs) { 281 bool operator<(const GeneralizedTime& lhs, const GeneralizedTime& rhs) {
282 return std::tie(lhs.year, lhs.month, lhs.day, lhs.hours, lhs.minutes, 282 return std::tie(lhs.year, lhs.month, lhs.day, lhs.hours, lhs.minutes,
283 lhs.seconds) < std::tie(rhs.year, rhs.month, rhs.day, 283 lhs.seconds) < std::tie(rhs.year, rhs.month, rhs.day,
284 rhs.hours, rhs.minutes, rhs.seconds); 284 rhs.hours, rhs.minutes, rhs.seconds);
285 } 285 }
286 286
287 bool operator>(const GeneralizedTime& lhs, const GeneralizedTime& rhs) {
288 return rhs < lhs;
289 }
290
291 bool operator<=(const GeneralizedTime& lhs, const GeneralizedTime& rhs) {
292 return !(lhs > rhs);
293 }
294
295 bool operator>=(const GeneralizedTime& lhs, const GeneralizedTime& rhs) {
296 return !(lhs < rhs);
297 }
298
287 // A UTC Time in DER encoding should be YYMMDDHHMMSSZ, but some CAs encode 299 // A UTC Time in DER encoding should be YYMMDDHHMMSSZ, but some CAs encode
288 // the time following BER rules, which allows for YYMMDDHHMMZ. If the length 300 // the time following BER rules, which allows for YYMMDDHHMMZ. If the length
289 // is 11, assume it's YYMMDDHHMMZ, and in converting it to a GeneralizedTime, 301 // is 11, assume it's YYMMDDHHMMZ, and in converting it to a GeneralizedTime,
290 // add in the seconds (set to 0). 302 // add in the seconds (set to 0).
291 bool ParseUTCTimeRelaxed(const Input& in, GeneralizedTime* value) { 303 bool ParseUTCTimeRelaxed(const Input& in, GeneralizedTime* value) {
292 ByteReader reader(in); 304 ByteReader reader(in);
293 GeneralizedTime time; 305 GeneralizedTime time;
294 if (!DecimalStringToUint(reader, 2, &time.year) || 306 if (!DecimalStringToUint(reader, 2, &time.year) ||
295 !DecimalStringToUint(reader, 2, &time.month) || 307 !DecimalStringToUint(reader, 2, &time.month) ||
296 !DecimalStringToUint(reader, 2, &time.day) || 308 !DecimalStringToUint(reader, 2, &time.day) ||
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 return false; 379 return false;
368 if (!ValidateGeneralizedTime(time)) 380 if (!ValidateGeneralizedTime(time))
369 return false; 381 return false;
370 *value = time; 382 *value = time;
371 return true; 383 return true;
372 } 384 }
373 385
374 } // namespace der 386 } // namespace der
375 387
376 } // namespace net 388 } // namespace net
OLDNEW
« no previous file with comments | « net/der/parse_values.h ('k') | net/der/parse_values_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698