예제 #1
0
int
GeneralizedTime_print(asn_TYPE_descriptor_t *td, const void *sptr, int ilevel,
	asn_app_consume_bytes_f *cb, void *app_key) {
	const GeneralizedTime_t *st = (const GeneralizedTime_t *)sptr;

	(void)td;	/* Unused argument */
	(void)ilevel;	/* Unused argument */

	if(st && st->buf) {
		char buf[32];
		struct tm tm;
		int ret;

		errno = EPERM;
		if(asn_GT2time(st, &tm, 1) == -1 && errno != EPERM)
			return (cb("<bad-value>", 11, app_key) < 0) ? -1 : 0;

		ret = snprintf(buf, sizeof(buf),
			"%04d-%02d-%02d %02d:%02d:%02d (GMT)",
			tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
			tm.tm_hour, tm.tm_min, tm.tm_sec);
		assert(ret > 0 && ret < (int)sizeof(buf));
		return (cb(buf, ret, app_key) < 0) ? -1 : 0;
	} else {
		return (cb("<absent>", 8, app_key) < 0) ? -1 : 0;
	}
}
예제 #2
0
파일: UTCTime.c 프로젝트: Arribas/gnss-sdr
time_t
asn_UT2time(const UTCTime_t *st, struct tm *_tm, int as_gmt) {
	char buf[24];	/* "AAMMJJhhmmss+hhmm" + cushion */
	GeneralizedTime_t gt;

	if(!st || !st->buf
	|| st->size < 11 || st->size >= ((int)sizeof(buf) - 2)) {
		errno = EINVAL;
		return -1;
	}

	gt.buf = (unsigned char *)buf;
	gt.size = st->size + 2;
	memcpy(gt.buf + 2, st->buf, st->size);
	if(st->buf[0] > 0x35) {
		/* 19xx */
		gt.buf[0] = 0x31;
		gt.buf[1] = 0x39;
	} else {
		/* 20xx */
		gt.buf[0] = 0x32;
		gt.buf[1] = 0x30;
	}

	return asn_GT2time(&gt, _tm, as_gmt);
}
예제 #3
0
/*
 * Check that the time looks like the time.
 */
int
GeneralizedTime_constraint(asn_TYPE_descriptor_t *td, const void *sptr,
		asn_app_constraint_failed_f *ctfailcb, void *app_key) {
	const GeneralizedTime_t *st = (const GeneralizedTime_t *)sptr;
	time_t tloc;

	errno = EPERM;			/* Just an unlikely error code */
	tloc = asn_GT2time(st, 0, 0);
	if(tloc == -1 && errno != EPERM) {
		_ASN_CTFAIL(app_key, td, sptr,
			"%s: Invalid time format: %s (%s:%d)",
			td->name, strerror(errno), __FILE__, __LINE__);
		return -1;
	}

	return 0;
}
예제 #4
0
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);
}