src/lib/BasicASN1Reader.h
branchv_0
changeset 21 705036445672
parent 20 fac034e3e867
child 22 9b6f86760384
equal deleted inserted replaced
20:fac034e3e867 21:705036445672
    18 
    18 
    19 #include <memory>
    19 #include <memory>
    20 #include <vector>
    20 #include <vector>
    21 #include <array>
    21 #include <array>
    22 #include <sstream>
    22 #include <sstream>
       
    23 #include <regex>
    23 
    24 
    24 #include "ASN1Reader.h"
    25 #include "ASN1Reader.h"
    25 
    26 
    26 namespace relpipe {
    27 namespace relpipe {
    27 namespace in {
    28 namespace in {
   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?