Example #1
0
time_t
asn_GT2time_prec(const GeneralizedTime_t *st, int *frac_value, int frac_digits, struct tm *ret_tm, int as_gmt) {
	time_t tloc;
	int fv, fd = 0;

	if(frac_value)
		tloc = asn_GT2time_frac(st, &fv, &fd, ret_tm, as_gmt);
	else
		return asn_GT2time_frac(st, 0, 0, ret_tm, as_gmt);
	if(fd == 0 || frac_digits <= 0) {
		*frac_value = 0;
	} else {
		while(fd > frac_digits)
			fv /= 10, fd--;
		while(fd < frac_digits) {
			int volatile new_fv = fv * 10;
			/* GCC 4.x is being too smart without volatile */
			if(new_fv / 10 != fv) {
				/* Too long precision request */
				fv = 0;
				break;
			}
			fv = new_fv, fd++;
		}

		*frac_value = fv;
	}

	return tloc;
}
Example #2
0
time_t
asn_GT2time_prec(const GeneralizedTime_t *st, int *frac_value, int frac_digits, struct tm *ret_tm, int as_gmt) {
    time_t tloc;
    int fv, fd = 0;

    if(frac_value)
        tloc = asn_GT2time_frac(st, &fv, &fd, ret_tm, as_gmt);
    else
        return asn_GT2time_frac(st, 0, 0, ret_tm, as_gmt);
    if(fd == 0 || frac_digits <= 0) {
        *frac_value = 0;
    } else {
        while(fd > frac_digits)
            fv /= 10, fd--;
        while(fd < frac_digits) {
            if(fv < INT_MAX / 10) {
                fv *= 10;
                fd++;
            } else {
                /* Too long precision request */
                fv = 0;
                break;
            }
        }

        *frac_value = fv;
    }

    return tloc;
}
Example #3
0
asn_enc_rval_t
GeneralizedTime_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) {
		GeneralizedTime_t *gt;
		asn_enc_rval_t rv;
		int fv, fd;		/* fractional parts */
		struct tm tm;

		errno = EPERM;
		if(asn_GT2time_frac((GeneralizedTime_t *)sptr,
					&fv, &fd, &tm, 1) == -1
				&& errno != EPERM)
			_ASN_ENCODE_FAILED;

		gt = asn_time2GT_frac(0, &tm, fv, fd, 1);
		if(!gt) _ASN_ENCODE_FAILED;
	
		rv = OCTET_STRING_encode_xer_utf8(td, sptr, ilevel, flags,
			cb, app_key);
		ASN_STRUCT_FREE(asn_DEF_GeneralizedTime, gt);
		return rv;
	} else {
		return OCTET_STRING_encode_xer_utf8(td, sptr, ilevel, flags,
			cb, app_key);
	}
}
Example #4
0
asn_enc_rval_t
GeneralizedTime_encode_der(asn_TYPE_descriptor_t *td, void *sptr,
	int tag_mode, ber_tlv_tag_t tag,
	asn_app_consume_bytes_f *cb, void *app_key) {
	GeneralizedTime_t *st = (GeneralizedTime_t *)sptr;
	asn_enc_rval_t erval;
	int fv, fd;	/* seconds fraction value and number of digits */
	struct tm tm;
	time_t tloc;

	/*
	 * Encode as a canonical DER.
	 */
	errno = EPERM;
	tloc = asn_GT2time_frac(st, &fv, &fd, &tm, 1);	/* Recognize time */
	if(tloc == -1 && errno != EPERM)
		/* Failed to recognize time. Fail completely. */
		_ASN_ENCODE_FAILED;

	st = asn_time2GT_frac(0, &tm, fv, fd, 1); /* Save time canonically */
	if(!st) _ASN_ENCODE_FAILED;	/* Memory allocation failure. */

	erval = OCTET_STRING_encode_der(td, st, tag_mode, tag, cb, app_key);

	FREEMEM(st->buf);
	FREEMEM(st);

	return erval;
}
Example #5
0
time_t
asn_GT2time(const GeneralizedTime_t *st, struct tm *ret_tm, int as_gmt) {
	return asn_GT2time_frac(st, 0, 0, ret_tm, as_gmt);
}