172 // TODO: check available bytes before allocating buffer |
173 // TODO: check available bytes before allocating buffer |
173 std::string s; |
174 std::string s; |
174 s.resize(typeHeader.length); |
175 s.resize(typeHeader.length); |
175 read((uint8_t*) s.data(), typeHeader.length); |
176 read((uint8_t*) s.data(), typeHeader.length); |
176 handlers.writeString(ASN1ContentHandler::StringType::PrintableString, s); |
177 handlers.writeString(ASN1ContentHandler::StringType::PrintableString, s); |
|
178 } else if (typeHeader.tag == 0x17 && typeHeader.tagClass == TagClass::Universal && typeHeader.definiteLength) { |
|
179 // TODO: check available bytes before allocating buffer |
|
180 std::string s; |
|
181 s.resize(typeHeader.length); |
|
182 read((uint8_t*) s.data(), typeHeader.length); |
|
183 |
|
184 ASN1ContentHandler::DateTime dateTime; |
|
185 |
|
186 std::smatch match; |
|
187 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"))) { |
|
188 int i = 1; |
|
189 uint32_t year = std::stoi(match[i++]); |
|
190 dateTime.year = year < 50 ? 2000 + year : 1900 + year; |
|
191 dateTime.month = std::stoi(match[i++]); |
|
192 dateTime.day = std::stoi(match[i++]); |
|
193 dateTime.hour = std::stoi(match[i++]); |
|
194 dateTime.minute = std::stoi(match[i++]); |
|
195 dateTime.precision = ASN1ContentHandler::DateTime::Precision::Second; |
|
196 handlers.writeDateTime(ASN1ContentHandler::DateTimeType::UTCTime, dateTime); |
|
197 } else { |
|
198 // FIXME: decode more UTCTime formats: |
|
199 // YYMMDDhhmmZ |
|
200 // YYMMDDhhmm+hh'mm' |
|
201 // YYMMDDhhmm-hh'mm' |
|
202 // YYMMDDhhmmssZ |
|
203 // YYMMDDhhmmss+hh'mm' |
|
204 // YYMMDDhhmmss-hh'mm' |
|
205 handlers.writeString(ASN1ContentHandler::StringType::UTF8String, "FIXME: UTCTime format not yet supported: " + s); |
|
206 } |
|
207 |
177 } else { |
208 } else { |
178 // TODO: do not skip, parse |
209 // TODO: do not skip, parse |
179 std::vector<uint8_t> temp(typeHeader.length, 0); |
210 std::vector<uint8_t> temp(typeHeader.length, 0); |
180 read(temp.data(), typeHeader.length); |
211 read(temp.data(), typeHeader.length); |
181 // TODO: recover transaction? |
212 // TODO: recover transaction? |