asn_enc_rval_t UTCTime_encode_xer(asn_TYPE_descriptor_t *td, void *sptr, int ilevel, enum xer_encoder_flags_e flags, asn_app_consume_bytes_f *cb, void *app_key) { if(flags & XER_F_CANONICAL) { asn_enc_rval_t rv; UTCTime_t *ut; struct tm tm; errno = EPERM; if(asn_UT2time((UTCTime_t *)sptr, &tm, 1) == -1 && errno != EPERM) _ASN_ENCODE_FAILED; /* Fractions are not allowed in UTCTime */ ut = asn_time2GT(0, 0, 1); if(!ut) _ASN_ENCODE_FAILED; rv = OCTET_STRING_encode_xer_utf8(td, sptr, ilevel, flags, cb, app_key); OCTET_STRING_free(&asn_DEF_UTCTime, ut, 0); return rv; } else { return OCTET_STRING_encode_xer_utf8(td, sptr, ilevel, flags, cb, app_key); } }
UTCTime_t * asn_time2UT(UTCTime_t *opt_ut, const struct tm *tm, int force_gmt) { GeneralizedTime_t *gt = (GeneralizedTime_t *)opt_ut; gt = asn_time2GT(gt, tm, force_gmt); if(gt == 0) return 0; assert(gt->size >= 2); gt->size -= 2; memmove(gt->buf, gt->buf + 2, gt->size + 1); return (UTCTime_t *)gt; }
std::vector<uint8_t> Buf1() { struct tm time1; memset(&time1, 0, sizeof(time1)); time1.tm_year = 110; time1.tm_mon = 2; time1.tm_mday = 10; time1.tm_hour = 16; time1.tm_min = 40; time1.tm_sec = 12; struct tm time3; memset(&time3, 0, sizeof(time3)); time3.tm_year = 130; time3.tm_mon = 2; time3.tm_mday = 10; time3.tm_hour = 16; time3.tm_min = 40; time3.tm_sec = 12; std::vector<uint8_t> buf(DEFAULT_BUF_SIZE); SequenceRecord_IS_GT_GTO_GTRefWithTag_GTRefWithTagO_t rec; memset(&rec, 0, sizeof(rec)); if (!asn_time2GT(&rec.seq.time1, &time1, 0)) throw std::runtime_error("error"); rec.seq.time2 = 0; if (!asn_time2GT(&rec.seq.time3, &time3, 0)) throw std::runtime_error("error"); rec.seq.time4 = 0; asn_enc_rval_t rval; rval = der_encode_to_buffer(&asn_DEF_SequenceRecord_IS_GT_GTO_GTRefWithTag_GTRefWithTagO, &rec, (void*)buf.data(), buf.size()); if (rval.encoded >= 0) { buf.resize(rval.encoded); } else { printf("cannot encode record in Buf1"); exit(0); } return std::move(buf); }
std::vector<uint8_t> Buf2() { std::vector<uint8_t> buf(DEFAULT_BUF_SIZE); SequenceRecord_IS_GT_GTO_GTRefWithTag_GTRefWithTagO_t rec; memset(&rec, 0, sizeof(rec)); struct tm time1; memset(&time1, 0, sizeof(time1)); time1.tm_year = 110; time1.tm_mon = 2; time1.tm_mday = 10; time1.tm_hour = 16; time1.tm_min = 40; time1.tm_sec = 12; struct tm time2; memset(&time2, 0, sizeof(time2)); time2.tm_year = 120; time2.tm_mon = 2; time2.tm_mday = 10; time2.tm_hour = 16; time2.tm_min = 40; time2.tm_sec = 12; struct tm time3; memset(&time3, 0, sizeof(time3)); time3.tm_year = 130; time3.tm_mon = 2; time3.tm_mday = 10; time3.tm_hour = 16; time3.tm_min = 40; time3.tm_sec = 12; struct tm time4; memset(&time4, 0, sizeof(time4)); time4.tm_year = 137; time4.tm_mon = 2; time4.tm_mday = 10; time4.tm_hour = 16; time4.tm_min = 40; time4.tm_sec = 12; if (!asn_time2GT(&rec.seq.time1, &time1, 0)) throw std::runtime_error("error"); rec.seq.time2 = (GeneralizedTime_t*)malloc(sizeof(GeneralizedTime_t)); memset(rec.seq.time2, 0, sizeof(*rec.seq.time2)); if (!asn_time2GT(rec.seq.time2, &time2, 0)) throw std::runtime_error("error"); if (!asn_time2GT(&rec.seq.time3, &time3, 0)) throw std::runtime_error("error"); rec.seq.time4 = (GeneralizedTime_t*)malloc(sizeof(GeneralizedTime_t)); memset(rec.seq.time4, 0, sizeof(*rec.seq.time4)); if (!asn_time2GT(rec.seq.time4, &time4, 0)) throw std::runtime_error("error"); printf("std::vector<uint8_t> mustBe1 = "); PrintLn(rec.seq.time1); printf("std::vector<uint8_t> mustBe2 = "); PrintLn(*rec.seq.time2); printf("std::vector<uint8_t> mustBe3 = "); PrintLn(rec.seq.time3); printf("std::vector<uint8_t> mustBe4 = "); PrintLn(*rec.seq.time4); printf("time1: %u\n", asn_GT2time(&rec.seq.time1, 0, 0)); printf("time2: %u\n", asn_GT2time(rec.seq.time2, 0, 0)); printf("time3: %u\n", asn_GT2time(&rec.seq.time3, 0, 0)); printf("time4: %u\n", asn_GT2time(rec.seq.time4, 0, 0)); asn_enc_rval_t rval; rval = der_encode_to_buffer(&asn_DEF_SequenceRecord_IS_GT_GTO_GTRefWithTag_GTRefWithTagO, &rec, (void*)buf.data(), buf.size()); if (rval.encoded >= 0) { buf.resize(rval.encoded); } else { printf("cannot encode record in Buf2"); exit(0); } return std::move(buf); }