Commit 7b3713a8 authored by Lev Walkin's avatar Lev Walkin

stricter encoding

parent 82d80390
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#include <time.h> #include <time.h>
#include <errno.h> #include <errno.h>
#ifndef __NO_ASN_TABLE__ #ifndef __ASN_INTERNAL_TEST_MODE__
/* /*
* UTCTime basic type description. * UTCTime basic type description.
...@@ -39,7 +39,7 @@ asn_TYPE_descriptor_t asn_DEF_UTCTime = { ...@@ -39,7 +39,7 @@ asn_TYPE_descriptor_t asn_DEF_UTCTime = {
0 /* No specifics */ 0 /* No specifics */
}; };
#endif /* __NO_ASN_TABLE__ */ #endif /* __ASN_INTERNAL_TEST_MODE__ */
/* /*
* Check that the time looks like the time. * Check that the time looks like the time.
...@@ -62,36 +62,39 @@ UTCTime_constraint(asn_TYPE_descriptor_t *td, const void *sptr, ...@@ -62,36 +62,39 @@ UTCTime_constraint(asn_TYPE_descriptor_t *td, const void *sptr,
return 0; return 0;
} }
#ifndef __ASN_INTERNAL_TEST_MODE__
asn_enc_rval_t asn_enc_rval_t
UTCTime_encode_xer(asn_TYPE_descriptor_t *td, void *sptr, UTCTime_encode_xer(asn_TYPE_descriptor_t *td, void *sptr,
int ilevel, enum xer_encoder_flags_e flags, int ilevel, enum xer_encoder_flags_e flags,
asn_app_consume_bytes_f *cb, void *app_key) { asn_app_consume_bytes_f *cb, void *app_key) {
OCTET_STRING_t st;
if(flags & XER_F_CANONICAL) { if(flags & XER_F_CANONICAL) {
char buf[32]; asn_enc_rval_t rv;
UTCTime_t *ut;
struct tm tm; struct tm tm;
ssize_t ret;
errno = EPERM; errno = EPERM;
if(asn_UT2time((UTCTime_t *)sptr, &tm, 1) == -1 if(asn_UT2time((UTCTime_t *)sptr, &tm, 1) == -1
&& errno != EPERM) && errno != EPERM)
_ASN_ENCODE_FAILED; _ASN_ENCODE_FAILED;
ret = snprintf(buf, sizeof(buf), "%02d%02d%02d%02d%02d%02dZ", /* Fractions are not allowed in UTCTime */
tm.tm_year % 100, tm.tm_mon + 1, tm.tm_mday, ut = asn_time2GT(0, 0, 1);
tm.tm_hour, tm.tm_min, tm.tm_sec); if(!ut) _ASN_ENCODE_FAILED;
assert(ret > 0 && ret < (int)sizeof(buf));
st.buf = (uint8_t *)buf;
st.size = ret;
sptr = &st;
}
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, return OCTET_STRING_encode_xer_utf8(td, sptr, ilevel, flags,
cb, app_key); cb, app_key);
}
} }
#endif /* __ASN_INTERNAL_TEST_MODE__ */
int int
UTCTime_print(asn_TYPE_descriptor_t *td, const void *sptr, int ilevel, UTCTime_print(asn_TYPE_descriptor_t *td, const void *sptr, int ilevel,
asn_app_consume_bytes_f *cb, void *app_key) { asn_app_consume_bytes_f *cb, void *app_key) {
...@@ -110,7 +113,7 @@ UTCTime_print(asn_TYPE_descriptor_t *td, const void *sptr, int ilevel, ...@@ -110,7 +113,7 @@ UTCTime_print(asn_TYPE_descriptor_t *td, const void *sptr, int ilevel,
return (cb("<bad-value>", 11, app_key) < 0) ? -1 : 0; return (cb("<bad-value>", 11, app_key) < 0) ? -1 : 0;
ret = snprintf(buf, sizeof(buf), ret = snprintf(buf, sizeof(buf),
"%04d-%02d-%02d %02d:%02d%02d (GMT)", "%04d-%02d-%02d %02d:%02d:%02d (GMT)",
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec); tm.tm_hour, tm.tm_min, tm.tm_sec);
assert(ret > 0 && ret < (int)sizeof(buf)); assert(ret > 0 && ret < (int)sizeof(buf));
...@@ -122,11 +125,11 @@ UTCTime_print(asn_TYPE_descriptor_t *td, const void *sptr, int ilevel, ...@@ -122,11 +125,11 @@ UTCTime_print(asn_TYPE_descriptor_t *td, const void *sptr, int ilevel,
time_t time_t
asn_UT2time(const UTCTime_t *st, struct tm *_tm, int as_gmt) { asn_UT2time(const UTCTime_t *st, struct tm *_tm, int as_gmt) {
char buf[17+2]; /* "AAMMJJhhmmss+hhmm" = 17, + 2 = 19 */ char buf[24]; /* "AAMMJJhhmmss+hhmm" + cushion */
GeneralizedTime_t gt; GeneralizedTime_t gt;
if(!st || !st->buf if(!st || !st->buf
|| st->size < 11 || st->size > ((int)sizeof(buf) - 2)) { || st->size < 11 || st->size >= ((int)sizeof(buf) - 2)) {
errno = EINVAL; errno = EINVAL;
return -1; return -1;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment