diff options
| author | Carl Hetherington <cth@carlh.net> | 2022-02-12 21:15:03 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2022-02-12 23:13:49 +0100 |
| commit | d6b800e1c9a3cdb4f85a2308190afe9f0a856ed4 (patch) | |
| tree | 439b3c142ac392b9888585d51c463696cef6ff87 /src/local_time.cc | |
| parent | 0a5615c17edf6d9c51d9269c824d6caf71f710e5 (diff) | |
Cleanup: use dcp::LocalTime for certificate validity times.
Before we were using struct tm but not filling it all in, which
seems quite unpleasant.
Diffstat (limited to 'src/local_time.cc')
| -rw-r--r-- | src/local_time.cc | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/local_time.cc b/src/local_time.cc index 892ffba4..ad2291f9 100644 --- a/src/local_time.cc +++ b/src/local_time.cc @@ -307,3 +307,34 @@ dcp::operator<< (ostream& s, LocalTime const & t) s << t.as_string (); return s; } + + +LocalTime +LocalTime::from_asn1_utc_time (string time) +{ + LocalTime t; + sscanf(time.c_str(), "%2d%2d%2d%2d%2d%2d", &t._year, &t._month, &t._day, &t._hour, &t._minute, &t._second); + + if (t._year < 70) { + t._year += 100; + } + t._year += 1900; + + t._tz_hour = t._tz_minute = t._millisecond = 0; + + return t; +} + + +LocalTime +LocalTime::from_asn1_generalized_time (string time) +{ + LocalTime t; + sscanf(time.c_str(), "%4d%2d%2d%2d%2d%2d", &t._year, &t._month, &t._day, &t._hour, &t._minute, &t._second); + + t._tz_hour = t._tz_minute = t._millisecond = 0; + + return t; +} + + |
