--- a/src/lib/BasicASN1Reader.h Sun Jun 27 19:22:23 2021 +0200
+++ b/src/lib/BasicASN1Reader.h Mon Jun 28 22:48:04 2021 +0200
@@ -20,6 +20,7 @@
#include <vector>
#include <array>
#include <sstream>
+#include <regex>
#include "ASN1Reader.h"
@@ -174,6 +175,36 @@
s.resize(typeHeader.length);
read((uint8_t*) s.data(), typeHeader.length);
handlers.writeString(ASN1ContentHandler::StringType::PrintableString, s);
+ } else if (typeHeader.tag == 0x17 && typeHeader.tagClass == TagClass::Universal && typeHeader.definiteLength) {
+ // TODO: check available bytes before allocating buffer
+ std::string s;
+ s.resize(typeHeader.length);
+ read((uint8_t*) s.data(), typeHeader.length);
+
+ ASN1ContentHandler::DateTime dateTime;
+
+ std::smatch match;
+ if (std::regex_match(s, match, std::regex("([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})Z"))) {
+ int i = 1;
+ uint32_t year = std::stoi(match[i++]);
+ dateTime.year = year < 50 ? 2000 + year : 1900 + year;
+ dateTime.month = std::stoi(match[i++]);
+ dateTime.day = std::stoi(match[i++]);
+ dateTime.hour = std::stoi(match[i++]);
+ dateTime.minute = std::stoi(match[i++]);
+ dateTime.precision = ASN1ContentHandler::DateTime::Precision::Second;
+ handlers.writeDateTime(ASN1ContentHandler::DateTimeType::UTCTime, dateTime);
+ } else {
+ // FIXME: decode more UTCTime formats:
+ // YYMMDDhhmmZ
+ // YYMMDDhhmm+hh'mm'
+ // YYMMDDhhmm-hh'mm'
+ // YYMMDDhhmmssZ
+ // YYMMDDhhmmss+hh'mm'
+ // YYMMDDhhmmss-hh'mm'
+ handlers.writeString(ASN1ContentHandler::StringType::UTF8String, "FIXME: UTCTime format not yet supported: " + s);
+ }
+
} else {
// TODO: do not skip, parse
std::vector<uint8_t> temp(typeHeader.length, 0);