Unverified Commit e74487cd authored by Mouse's avatar Mouse Committed by GitHub

Merge pull request #150 from v0-e/jer-utf8-fix

jer: OCTET STRING UTF-8 add quotes
parents f766a858 aa2eb978
......@@ -79,6 +79,7 @@ BMPString_encode_jer(const asn_TYPE_descriptor_t *td, const void *sptr,
asn_app_consume_bytes_f *cb, void *app_key) {
const BMPString_t *st = (const BMPString_t *)sptr;
asn_enc_rval_t er = {0,0,0};
ssize_t ro_encoded = 0;
(void)ilevel;
(void)flags;
......@@ -86,8 +87,14 @@ BMPString_encode_jer(const asn_TYPE_descriptor_t *td, const void *sptr,
if(!st || !st->buf)
ASN__ENCODE_FAILED;
er.encoded = BMPString__dump(st, cb, app_key);
if(er.encoded < 0) ASN__ENCODE_FAILED;
ASN__CALLBACK("\"", 1);
ro_encoded = BMPString__dump(st, cb, app_key);
if(ro_encoded < 0) goto cb_failed;
er.encoded += ro_encoded;
ASN__CALLBACK("\"", 1);
ASN__ENCODED_OK(er);
cb_failed:
ASN__ENCODE_FAILED;
}
......@@ -160,6 +160,7 @@ OCTET_STRING_encode_jer_utf8(const asn_TYPE_descriptor_t *td, const void *sptr,
buf = st->buf;
end = buf + st->size;
ASN__CALLBACK("\"", 1);
for(ss = buf; buf < end; buf++) {
unsigned int ch = *buf;
int s_len; /* Special encoding sequence length */
......@@ -180,10 +181,15 @@ OCTET_STRING_encode_jer_utf8(const asn_TYPE_descriptor_t *td, const void *sptr,
encoded_len += (buf - ss);
if((buf - ss) && cb(ss, buf - ss, app_key) < 0)
ASN__ENCODE_FAILED;
goto cb_failed;
er.encoded += encoded_len;
er.encoded = encoded_len;
ASN__CALLBACK("\"", 1);
ASN__ENCODED_OK(er);
cb_failed:
ASN__ENCODE_FAILED;
}
#define CQUOTE 0x22
......@@ -333,8 +339,22 @@ OCTET_STRING__convert_entrefs(void *sptr, const void *chunk_buf,
const char *pend = p + chunk_size;
uint8_t *buf;
/* Strip quotes */
for(; p < pend; ++p) {
if (*p == CQUOTE) {
++p;
break;
}
}
for(; pend >= p; --pend) {
if (*pend == CQUOTE)
break;
}
if(pend - p < 0)
return -1;
/* Reallocate buffer */
size_t new_size = st->size + chunk_size;
size_t new_size = st->size + (pend - p);
void *nptr = REALLOC(st->buf, new_size + 1);
if(!nptr) return -1;
st->buf = (uint8_t *)nptr;
......
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