Commit a9cc46e3 authored by Lev Walkin's avatar Lev Walkin

XER support

parent e4d6ab83
...@@ -48,7 +48,8 @@ static void ...@@ -48,7 +48,8 @@ static void
check(int is_ok, uint8_t *buf, int size, size_t consumed) { check(int is_ok, uint8_t *buf, int size, size_t consumed) {
T1_t t, *tp; T1_t t, *tp;
ber_dec_rval_t rval; ber_dec_rval_t rval;
der_enc_rval_t erval; asn_enc_rval_t erval;
int ret;
int i; int i;
tp = memset(&t, 0, sizeof(t)); tp = memset(&t, 0, sizeof(t));
...@@ -104,8 +105,12 @@ check(int is_ok, uint8_t *buf, int size, size_t consumed) { ...@@ -104,8 +105,12 @@ check(int is_ok, uint8_t *buf, int size, size_t consumed) {
assert(buf1[i] == buf2[i]); assert(buf1[i] == buf2[i]);
} }
fprintf(stderr, "=== PRINT ===\n"); fprintf(stderr, "=== asn_fprint() ===\n");
asn_fprint(stderr, &asn1_DEF_T1, tp); ret = asn_fprint(stderr, &asn1_DEF_T1, tp);
assert(ret == 0);
fprintf(stderr, "=== xer_fprint() ===\n");
ret = xer_fprint(stderr, &asn1_DEF_T1, tp);
assert(ret == 0);
fprintf(stderr, "=== EOF ===\n"); fprintf(stderr, "=== EOF ===\n");
} }
......
...@@ -136,6 +136,7 @@ check(int is_ok, uint8_t *buf, int size, size_t consumed) { ...@@ -136,6 +136,7 @@ check(int is_ok, uint8_t *buf, int size, size_t consumed) {
assert(buf_pos == sizeof(buf1_reconstr)); assert(buf_pos == sizeof(buf1_reconstr));
asn_fprint(stderr, &asn1_DEF_Forest, &t); asn_fprint(stderr, &asn1_DEF_Forest, &t);
xer_fprint(stderr, &asn1_DEF_Forest, &t);
asn1_DEF_Forest.free_struct(&asn1_DEF_Forest, &t, 1); asn1_DEF_Forest.free_struct(&asn1_DEF_Forest, &t, 1);
} }
......
...@@ -131,6 +131,9 @@ check(T_t *tp, uint8_t *buf, int size, size_t consumed) { ...@@ -131,6 +131,9 @@ check(T_t *tp, uint8_t *buf, int size, size_t consumed) {
assert(strcmp(tp->a.buf, "ns") == 0); assert(strcmp(tp->a.buf, "ns") == 0);
assert(strcmp(tp->b.choice.b1.buf, "z") == 0 assert(strcmp(tp->b.choice.b1.buf, "z") == 0
&& strcmp(tp->b.choice.b2.buf, "z") == 0); && strcmp(tp->b.choice.b2.buf, "z") == 0);
asn_fprint(stderr, &asn1_DEF_T, tp);
xer_fprint(stderr, &asn1_DEF_T, tp);
} }
size_t buf_pos; size_t buf_pos;
...@@ -157,7 +160,7 @@ buf_fill(const void *buffer, size_t size, void *app_key) { ...@@ -157,7 +160,7 @@ buf_fill(const void *buffer, size_t size, void *app_key) {
static void static void
compare(T_t *tp, uint8_t *cmp_buf, int cmp_buf_size) { compare(T_t *tp, uint8_t *cmp_buf, int cmp_buf_size) {
der_enc_rval_t erval; asn_enc_rval_t erval;
int i; int i;
buf_size = cmp_buf_size + 100; buf_size = cmp_buf_size + 100;
...@@ -268,12 +271,10 @@ main(int ac, char **av) { ...@@ -268,12 +271,10 @@ main(int ac, char **av) {
check(&t, buf1, sizeof(buf1) + 10, sizeof(buf1)); check(&t, buf1, sizeof(buf1) + 10, sizeof(buf1));
compare(&t, buf1_reconstr, sizeof(buf1_reconstr)); compare(&t, buf1_reconstr, sizeof(buf1_reconstr));
asn_fprint(stderr, &asn1_DEF_T, &t);
asn1_DEF_T.free_struct(&asn1_DEF_T, &t, 1); asn1_DEF_T.free_struct(&asn1_DEF_T, &t, 1);
check(&t, buf2, sizeof(buf2) + 10, sizeof(buf2)); check(&t, buf2, sizeof(buf2) + 10, sizeof(buf2));
compare(&t, buf2_reconstr, sizeof(buf2_reconstr)); compare(&t, buf2_reconstr, sizeof(buf2_reconstr));
asn_fprint(stderr, &asn1_DEF_T, &t);
asn1_DEF_T.free_struct(&asn1_DEF_T, &t, 1); asn1_DEF_T.free_struct(&asn1_DEF_T, &t, 1);
/* Split the buffer in parts and check decoder restartability */ /* Split the buffer in parts and check decoder restartability */
......
...@@ -132,10 +132,11 @@ uint8_t buf2_reconstr[] = { ...@@ -132,10 +132,11 @@ uint8_t buf2_reconstr[] = {
static void static void
check(T_t *tp, uint8_t *buf, int size, size_t consumed) { check(T_t *tp, uint8_t *buf, int size, size_t consumed) {
ber_dec_rval_t rval; ber_dec_rval_t rval;
int ret;
tp = memset(tp, 0, sizeof(*tp)); tp = memset(tp, 0, sizeof(*tp));
fprintf(stderr, "Buf %p (%d)\n", buf, size); fprintf(stderr, "Buf %p (%d)\n", (int)buf, (int)size);
rval = ber_decode(&asn1_DEF_T, (void **)&tp, buf, size); rval = ber_decode(&asn1_DEF_T, (void **)&tp, buf, size);
fprintf(stderr, "Returned code %d, consumed %d\n", fprintf(stderr, "Returned code %d, consumed %d\n",
(int)rval.code, (int)rval.consumed); (int)rval.code, (int)rval.consumed);
...@@ -143,6 +144,14 @@ check(T_t *tp, uint8_t *buf, int size, size_t consumed) { ...@@ -143,6 +144,14 @@ check(T_t *tp, uint8_t *buf, int size, size_t consumed) {
assert(rval.code == RC_OK); assert(rval.code == RC_OK);
assert(rval.consumed == consumed); assert(rval.consumed == consumed);
fprintf(stderr, "=== asn_fprint() ===\n");
ret = asn_fprint(stderr, &asn1_DEF_T, tp);
assert(ret == 0);
fprintf(stderr, "=== xer_fprint() ===\n");
ret = xer_fprint(stderr, &asn1_DEF_T, tp);
fprintf(stderr, "=== END ===\n");
assert(ret == 0);
/* /*
assert(tp->string.size == 128); assert(tp->string.size == 128);
assert(strncmp(tp->string.buf, "zz") == 0); assert(strncmp(tp->string.buf, "zz") == 0);
...@@ -153,32 +162,33 @@ check(T_t *tp, uint8_t *buf, int size, size_t consumed) { ...@@ -153,32 +162,33 @@ check(T_t *tp, uint8_t *buf, int size, size_t consumed) {
size_t buf_pos; size_t buf_pos;
size_t buf_size; size_t buf_size;
uint8_t *buf; uint8_t *buffer;
static int static int
buf_fill(const void *buffer, size_t size, void *app_key) { buf_fill(const void *bufp, size_t size, void *app_key) {
(void)app_key; /* Unused argument */ (void)app_key; /* Unused argument */
if(buf_pos + size > buf_size) { if(buf_pos + size > buf_size) {
fprintf(stderr, "%d + %d > %d\n", buf_pos, (int)size, buf_size); fprintf(stderr, "%d + %d > %d\n",
(int)buf_pos, (int)size, (int)buf_size);
return -1; return -1;
} }
memcpy(buf + buf_pos, buffer, size); memcpy(buffer + buf_pos, bufp, size);
buf_pos += size; buf_pos += size;
fprintf(stderr, " written %d (%d)\n", (int)size, buf_pos); fprintf(stderr, " written %d (%d)\n", (int)size, (int)buf_pos);
return 0; return 0;
} }
static void static void
compare(T_t *tp, uint8_t *cmp_buf, int cmp_buf_size) { compare(T_t *tp, uint8_t *cmp_buf, int cmp_buf_size) {
der_enc_rval_t erval; asn_enc_rval_t erval;
int i; int i;
buf_size = cmp_buf_size + 100; buf_size = cmp_buf_size + 100;
buf = alloca(buf_size); buffer = alloca(buf_size);
buf_pos = 0; buf_pos = 0;
/* /*
...@@ -187,19 +197,19 @@ compare(T_t *tp, uint8_t *cmp_buf, int cmp_buf_size) { ...@@ -187,19 +197,19 @@ compare(T_t *tp, uint8_t *cmp_buf, int cmp_buf_size) {
erval = der_encode(&asn1_DEF_T, tp, buf_fill, 0); erval = der_encode(&asn1_DEF_T, tp, buf_fill, 0);
assert(erval.encoded != -1); assert(erval.encoded != -1);
if(erval.encoded != cmp_buf_size) { if(erval.encoded != cmp_buf_size) {
printf("%d != %d\n", erval.encoded, cmp_buf_size); printf("%d != %d\n", (int)erval.encoded, (int)cmp_buf_size);
} }
assert(erval.encoded == cmp_buf_size); assert(erval.encoded == cmp_buf_size);
for(i = 0; i < cmp_buf_size; i++) { for(i = 0; i < cmp_buf_size; i++) {
if(buf[i] != cmp_buf[i]) { if(buffer[i] != cmp_buf[i]) {
fprintf(stderr, "Recreated buffer content mismatch:\n"); fprintf(stderr, "Recreated buffer content mismatch:\n");
fprintf(stderr, "Byte %d, %x != %x (%d != %d)\n", fprintf(stderr, "Byte %d, %x != %x (%d != %d)\n",
i, i,
buf[i], cmp_buf[i], buffer[i], cmp_buf[i],
buf[i], cmp_buf[i] buffer[i], cmp_buf[i]
); );
} }
assert(buf[i] == cmp_buf[i]); assert(buffer[i] == cmp_buf[i]);
} }
} }
...@@ -230,7 +240,7 @@ partial_read(uint8_t *buf, size_t size) { ...@@ -230,7 +240,7 @@ partial_read(uint8_t *buf, size_t size) {
size_t size3 = size - size1 - size2; size_t size3 = size - size1 - size2;
fprintf(stderr, "\n%d:{%d, %d, %d}...\n", fprintf(stderr, "\n%d:{%d, %d, %d}...\n",
size, size1, size2, size3); (int)size, (int)size1, (int)size2, (int)size3);
memset(buf1, 0, size); memset(buf1, 0, size);
memset(buf2, 0, size); memset(buf2, 0, size);
...@@ -241,7 +251,7 @@ partial_read(uint8_t *buf, size_t size) { ...@@ -241,7 +251,7 @@ partial_read(uint8_t *buf, size_t size) {
tp = memset(&t, 0, sizeof(t)); tp = memset(&t, 0, sizeof(t));
fprintf(stderr, "=> Chunk 1 (%d):\n", size1); fprintf(stderr, "=> Chunk 1 (%d):\n", (int)size1);
rval = ber_decode(&asn1_DEF_T, (void **)&tp, rval = ber_decode(&asn1_DEF_T, (void **)&tp,
buf1, size1); buf1, size1);
assert(rval.code == RC_WMORE); assert(rval.code == RC_WMORE);
...@@ -253,7 +263,7 @@ partial_read(uint8_t *buf, size_t size) { ...@@ -253,7 +263,7 @@ partial_read(uint8_t *buf, size_t size) {
size2 += leftover; size2 += leftover;
} }
fprintf(stderr, "=> Chunk 2 (%d):\n", size2); fprintf(stderr, "=> Chunk 2 (%d):\n", (int)size2);
rval = ber_decode(&asn1_DEF_T, (void **)&tp, rval = ber_decode(&asn1_DEF_T, (void **)&tp,
buf2, size2); buf2, size2);
assert(rval.code == RC_WMORE); assert(rval.code == RC_WMORE);
...@@ -265,7 +275,7 @@ partial_read(uint8_t *buf, size_t size) { ...@@ -265,7 +275,7 @@ partial_read(uint8_t *buf, size_t size) {
size3 += leftover; size3 += leftover;
} }
fprintf(stderr, "=> Chunk 3 (%d):\n", size3); fprintf(stderr, "=> Chunk 3 (%d):\n", (int)size3);
rval = ber_decode(&asn1_DEF_T, (void **)&tp, rval = ber_decode(&asn1_DEF_T, (void **)&tp,
buf3, size3); buf3, size3);
assert(rval.code == RC_OK); assert(rval.code == RC_OK);
...@@ -283,31 +293,26 @@ main() { ...@@ -283,31 +293,26 @@ main() {
/* Check exact buf0 */ /* Check exact buf0 */
check(&t, buf0, sizeof(buf0), sizeof(buf0)); check(&t, buf0, sizeof(buf0), sizeof(buf0));
compare(&t, buf0_reconstr, sizeof(buf0_reconstr)); compare(&t, buf0_reconstr, sizeof(buf0_reconstr));
asn_fprint(stderr, &asn1_DEF_T, &t);
asn1_DEF_T.free_struct(&asn1_DEF_T, &t, 1); asn1_DEF_T.free_struct(&asn1_DEF_T, &t, 1);
/* Check exact buf1 */ /* Check exact buf1 */
check(&t, buf1, sizeof(buf1), sizeof(buf1)); check(&t, buf1, sizeof(buf1), sizeof(buf1));
compare(&t, buf1_reconstr, sizeof(buf1_reconstr)); compare(&t, buf1_reconstr, sizeof(buf1_reconstr));
asn_fprint(stderr, &asn1_DEF_T, &t);
asn1_DEF_T.free_struct(&asn1_DEF_T, &t, 1); asn1_DEF_T.free_struct(&asn1_DEF_T, &t, 1);
/* Check slightly more than buf1 */ /* Check slightly more than buf1 */
check(&t, buf1, sizeof(buf1) + 10, sizeof(buf1)); check(&t, buf1, sizeof(buf1) + 10, sizeof(buf1));
compare(&t, buf1_reconstr, sizeof(buf1_reconstr)); compare(&t, buf1_reconstr, sizeof(buf1_reconstr));
asn_fprint(stderr, &asn1_DEF_T, &t);
asn1_DEF_T.free_struct(&asn1_DEF_T, &t, 1); asn1_DEF_T.free_struct(&asn1_DEF_T, &t, 1);
/* Check exact buf2 */ /* Check exact buf2 */
check(&t, buf2, sizeof(buf2), sizeof(buf2)); check(&t, buf2, sizeof(buf2), sizeof(buf2));
compare(&t, buf2_reconstr, sizeof(buf2_reconstr)); compare(&t, buf2_reconstr, sizeof(buf2_reconstr));
asn_fprint(stderr, &asn1_DEF_T, &t);
asn1_DEF_T.free_struct(&asn1_DEF_T, &t, 1); asn1_DEF_T.free_struct(&asn1_DEF_T, &t, 1);
/* Check slightly more than buf2 */ /* Check slightly more than buf2 */
check(&t, buf2, sizeof(buf2) + 10, sizeof(buf2)); check(&t, buf2, sizeof(buf2) + 10, sizeof(buf2));
compare(&t, buf2_reconstr, sizeof(buf2_reconstr)); compare(&t, buf2_reconstr, sizeof(buf2_reconstr));
asn_fprint(stderr, &asn1_DEF_T, &t);
asn1_DEF_T.free_struct(&asn1_DEF_T, &t, 1); asn1_DEF_T.free_struct(&asn1_DEF_T, &t, 1);
/* Split the buffer in parts and check decoder restartability */ /* Split the buffer in parts and check decoder restartability */
......
...@@ -29,7 +29,7 @@ _buf_writer(const void *buffer, size_t size, void *app_key) { ...@@ -29,7 +29,7 @@ _buf_writer(const void *buffer, size_t size, void *app_key) {
static int static int
save_object(void *bs, asn1_TYPE_descriptor_t *td) { save_object(void *bs, asn1_TYPE_descriptor_t *td) {
der_enc_rval_t rval; /* Return value */ asn_enc_rval_t rval; /* Return value */
int i; int i;
rval = der_encode(td, bs, _buf_writer, 0); rval = der_encode(td, bs, _buf_writer, 0);
...@@ -44,6 +44,7 @@ save_object(void *bs, asn1_TYPE_descriptor_t *td) { ...@@ -44,6 +44,7 @@ save_object(void *bs, asn1_TYPE_descriptor_t *td) {
buf[buf_offset++] = 123; /* Finalize with garbage */ buf[buf_offset++] = 123; /* Finalize with garbage */
asn_fprint(stderr, td, bs); asn_fprint(stderr, td, bs);
xer_fprint(stderr, td, bs);
printf("OUT: ["); printf("OUT: [");
for(i = 0; i < buf_offset; i++) for(i = 0; i < buf_offset; i++)
...@@ -63,6 +64,7 @@ load_object(void *bs, asn1_TYPE_descriptor_t *td) { ...@@ -63,6 +64,7 @@ load_object(void *bs, asn1_TYPE_descriptor_t *td) {
assert(rval.code == RC_OK); assert(rval.code == RC_OK);
asn_fprint(stderr, td, bs); asn_fprint(stderr, td, bs);
xer_fprint(stderr, td, bs);
return (rval.code == RC_OK)?0:-1; return (rval.code == RC_OK)?0:-1;
} }
......
This diff is collapsed.
...@@ -2,17 +2,20 @@ ...@@ -2,17 +2,20 @@
* Copyright (c) 2004 Lev Walkin <vlm@lionet.info>. All rights reserved. * Copyright (c) 2004 Lev Walkin <vlm@lionet.info>. All rights reserved.
* Redistribution and modifications are permitted subject to BSD license. * Redistribution and modifications are permitted subject to BSD license.
*/ */
#include <asn_internal.h>
#include <ANY.h> #include <ANY.h>
#include <assert.h> #include <assert.h>
#include <errno.h> #include <errno.h>
asn1_TYPE_descriptor_t asn1_DEF_ANY = { asn1_TYPE_descriptor_t asn1_DEF_ANY = {
"ANY", "ANY",
OCTET_STRING_free,
OCTET_STRING_print,
asn_generic_no_constraint, asn_generic_no_constraint,
OCTET_STRING_decode_ber, OCTET_STRING_decode_ber,
OCTET_STRING_encode_der, OCTET_STRING_encode_der,
OCTET_STRING_print, 0, /* Not implemented yet */
OCTET_STRING_free, ANY_encode_xer,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
0, 0, 0, 0, 0, 0, 0, 0,
-1, /* Both ways are fine (primitive and constructed) */ -1, /* Both ways are fine (primitive and constructed) */
...@@ -21,6 +24,23 @@ asn1_TYPE_descriptor_t asn1_DEF_ANY = { ...@@ -21,6 +24,23 @@ asn1_TYPE_descriptor_t asn1_DEF_ANY = {
}; };
asn_enc_rval_t
ANY_encode_xer(asn1_TYPE_descriptor_t *td, void *sptr,
int ilevel, enum xer_encoder_flags_e flags,
asn_app_consume_bytes_f *cb, void *app_key) {
(void)ilevel;
(void)flags;
(void)cb;
(void)app_key;
/*
* XER-encoding of ANY type is not supported.
*/
_ASN_ENCODE_FAILED;
}
struct _callback_arg { struct _callback_arg {
uint8_t *buffer; uint8_t *buffer;
size_t offset; size_t offset;
...@@ -32,7 +52,7 @@ static int ANY__consume_bytes(const void *buffer, size_t size, void *key); ...@@ -32,7 +52,7 @@ static int ANY__consume_bytes(const void *buffer, size_t size, void *key);
int int
ANY_fromType(ANY_t *st, asn1_TYPE_descriptor_t *td, void *sptr) { ANY_fromType(ANY_t *st, asn1_TYPE_descriptor_t *td, void *sptr) {
struct _callback_arg arg; struct _callback_arg arg;
der_enc_rval_t erval; asn_enc_rval_t erval;
if(!st || !td) { if(!st || !td) {
errno = EINVAL; errno = EINVAL;
...@@ -53,7 +73,7 @@ ANY_fromType(ANY_t *st, asn1_TYPE_descriptor_t *td, void *sptr) { ...@@ -53,7 +73,7 @@ ANY_fromType(ANY_t *st, asn1_TYPE_descriptor_t *td, void *sptr) {
if(arg.buffer) FREEMEM(arg.buffer); if(arg.buffer) FREEMEM(arg.buffer);
return -1; return -1;
} }
assert(erval.encoded == arg.offset); assert((size_t)erval.encoded == arg.offset);
if(st->buf) FREEMEM(st->buf); if(st->buf) FREEMEM(st->buf);
st->buf = arg.buffer; st->buf = arg.buffer;
......
...@@ -17,10 +17,11 @@ typedef struct ANY { ...@@ -17,10 +17,11 @@ typedef struct ANY {
extern asn1_TYPE_descriptor_t asn1_DEF_ANY; extern asn1_TYPE_descriptor_t asn1_DEF_ANY;
asn_struct_free_f ANY_free;
asn_struct_print_f ANY_print;
ber_type_decoder_f ANY_decode_ber; ber_type_decoder_f ANY_decode_ber;
der_type_encoder_f ANY_encode_der; der_type_encoder_f ANY_encode_der;
asn_struct_print_f ANY_print; xer_type_encoder_f ANY_encode_xer;
asn_struct_free_f ANY_free;
/****************************** /******************************
* Handy conversion routines. * * Handy conversion routines. *
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
* Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved. * Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved.
* Redistribution and modifications are permitted subject to BSD license. * Redistribution and modifications are permitted subject to BSD license.
*/ */
#include <asn_internal.h>
#include <BIT_STRING.h> #include <BIT_STRING.h>
/* /*
...@@ -12,11 +13,13 @@ static ber_tlv_tag_t asn1_DEF_BIT_STRING_tags[] = { ...@@ -12,11 +13,13 @@ static ber_tlv_tag_t asn1_DEF_BIT_STRING_tags[] = {
}; };
asn1_TYPE_descriptor_t asn1_DEF_BIT_STRING = { asn1_TYPE_descriptor_t asn1_DEF_BIT_STRING = {
"BIT STRING", "BIT STRING",
OCTET_STRING_free, /* Implemented in terms of OCTET STRING */
BIT_STRING_print,
BIT_STRING_constraint, BIT_STRING_constraint,
OCTET_STRING_decode_ber, /* Implemented in terms of OCTET STRING */ OCTET_STRING_decode_ber, /* Implemented in terms of OCTET STRING */
OCTET_STRING_encode_der, /* Implemented in terms of OCTET STRING */ OCTET_STRING_encode_der, /* Implemented in terms of OCTET STRING */
BIT_STRING_print, 0, /* Not implemented yet */
OCTET_STRING_free, /* Implemented in terms of OCTET STRING */ BIT_STRING_encode_xer,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn1_DEF_BIT_STRING_tags, asn1_DEF_BIT_STRING_tags,
sizeof(asn1_DEF_BIT_STRING_tags) sizeof(asn1_DEF_BIT_STRING_tags)
...@@ -61,6 +64,66 @@ BIT_STRING_constraint(asn1_TYPE_descriptor_t *td, const void *sptr, ...@@ -61,6 +64,66 @@ BIT_STRING_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
return 0; return 0;
} }
static char *_bit_pattern[16] = {
"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111",
"1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"
};
asn_enc_rval_t
BIT_STRING_encode_xer(asn1_TYPE_descriptor_t *td, void *sptr,
int ilevel, enum xer_encoder_flags_e flags,
asn_app_consume_bytes_f *cb, void *app_key) {
asn_enc_rval_t er;
char scratch[128];
char *p = scratch;
char *scend = scratch + (sizeof(scratch) - 10);
const BIT_STRING_t *st = (const BIT_STRING_t *)sptr;
uint8_t *buf;
uint8_t *end;
if(!st || !st->buf)
_ASN_ENCODE_FAILED;
er.encoded = 0;
buf = st->buf;
end = buf + st->size - 1; /* Last byte is special */
/*
* Binary dump
*/
for(buf++; buf < end; buf++) {
int v = *buf;
int nline = (flags & XER_F_CANONICAL)
?0:((((buf - st->buf) - 1) % 16) == 0);
if(p >= scend || nline) {
er.encoded += p - scratch;
_ASN_CALLBACK(scratch, p - scratch);
p = scratch;
if(nline) _i_ASN_TEXT_INDENT(1, ilevel);
}
memcpy(p + 0, _bit_pattern[v >> 4], 4);
memcpy(p + 4, _bit_pattern[v & 0x0f], 4);
p += 8;
}
er.encoded += p - scratch;
_ASN_CALLBACK(scratch, p - scratch);
if(buf < end + 1) {
int v = *buf;
int mbit = st->buf[0]; /* bits to skip from the right */
int i;
for(i = 7; i >= mbit; i--)
*p++ = (v & (1 << i)) ? '1' : '0';
er.encoded += p - scratch;
_ASN_CALLBACK(scratch, p - scratch);
}
return er;
}
/* /*
* BIT STRING specific contents printer. * BIT STRING specific contents printer.
*/ */
...@@ -99,6 +162,7 @@ BIT_STRING_print(asn1_TYPE_descriptor_t *td, const void *sptr, int ilevel, ...@@ -99,6 +162,7 @@ BIT_STRING_print(asn1_TYPE_descriptor_t *td, const void *sptr, int ilevel,
*p++ = h2c[*buf & 0x0F]; *p++ = h2c[*buf & 0x0F];
*p++ = 0x20; *p++ = 0x20;
} }
if(p > scratch) p--; /* Eat the tailing space */
/* Dump the incomplete 16-bytes row */ /* Dump the incomplete 16-bytes row */
return cb(scratch, p - scratch, app_key); return cb(scratch, p - scratch, app_key);
......
...@@ -14,5 +14,6 @@ extern asn1_TYPE_descriptor_t asn1_DEF_BIT_STRING; ...@@ -14,5 +14,6 @@ extern asn1_TYPE_descriptor_t asn1_DEF_BIT_STRING;
asn_struct_print_f BIT_STRING_print; /* Human-readable output */ asn_struct_print_f BIT_STRING_print; /* Human-readable output */
asn_constr_check_f BIT_STRING_constraint; asn_constr_check_f BIT_STRING_constraint;
xer_type_encoder_f BIT_STRING_encode_xer;
#endif /* _BIT_STRING_H_ */ #endif /* _BIT_STRING_H_ */
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
* Copyright (c) 2003 Lev Walkin <vlm@lionet.info>. All rights reserved. * Copyright (c) 2003 Lev Walkin <vlm@lionet.info>. All rights reserved.
* Redistribution and modifications are permitted subject to BSD license. * Redistribution and modifications are permitted subject to BSD license.
*/ */
#include <asn_internal.h>
#include <BMPString.h> #include <BMPString.h>
/* /*
...@@ -13,11 +14,13 @@ static ber_tlv_tag_t asn1_DEF_BMPString_tags[] = { ...@@ -13,11 +14,13 @@ static ber_tlv_tag_t asn1_DEF_BMPString_tags[] = {
}; };
asn1_TYPE_descriptor_t asn1_DEF_BMPString = { asn1_TYPE_descriptor_t asn1_DEF_BMPString = {
"BMPString", "BMPString",
OCTET_STRING_free, /* Implemented in terms of OCTET STRING */
BMPString_print,
asn_generic_no_constraint, /* No constraint by default */ asn_generic_no_constraint, /* No constraint by default */
OCTET_STRING_decode_ber, /* Implemented in terms of OCTET STRING */ OCTET_STRING_decode_ber, /* Implemented in terms of OCTET STRING */
OCTET_STRING_encode_der, /* Implemented in terms of OCTET STRING */ OCTET_STRING_encode_der, /* Implemented in terms of OCTET STRING */
BMPString_print, 0, /* Not implemented yet */
OCTET_STRING_free, /* -//- */ BMPString_encode_xer, /* Conver to UTF8 */
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn1_DEF_BMPString_tags, asn1_DEF_BMPString_tags,
sizeof(asn1_DEF_BMPString_tags) sizeof(asn1_DEF_BMPString_tags)
...@@ -33,27 +36,22 @@ asn1_TYPE_descriptor_t asn1_DEF_BMPString = { ...@@ -33,27 +36,22 @@ asn1_TYPE_descriptor_t asn1_DEF_BMPString = {
/* /*
* BMPString specific contents printer. * BMPString specific contents printer.
*/ */
int static ssize_t
BMPString_print(asn1_TYPE_descriptor_t *td, const void *sptr, int ilevel, BMPString__dump(const BMPString_t *st,
asn_app_consume_bytes_f *cb, void *app_key) { asn_app_consume_bytes_f *cb, void *app_key) {
const BMPString_t *st = (const BMPString_t *)sptr;
uint16_t *wchar;
uint16_t *wend;
char scratch[128]; /* Scratchpad buffer */ char scratch[128]; /* Scratchpad buffer */
char *p; char *p = scratch;
ssize_t wrote = 0;
(void)td; /* Unused argument */ uint8_t *ch;
(void)ilevel; /* Unused argument */ uint8_t *end;
if(!st || !st->buf) return cb("<absent>", 8, app_key);
wchar = (uint16_t *)st->buf; ch = st->buf;
wend = (uint16_t *)(st->buf + st->size); end = (st->buf + st->size);
for(p = scratch; wchar < wend; wchar++) { for(end--; ch < end; ch += 2) {
uint16_t wc = (((uint8_t *)wchar)[0] << 8) uint16_t wc = (ch[0] << 8) | ch[1]; /* 2 bytes */
| ((uint8_t *)wchar)[1]; /* 2 bytes */
if(sizeof(scratch) - (p - scratch) < 3) { if(sizeof(scratch) - (p - scratch) < 3) {
if(cb(scratch, p - scratch, app_key)) wrote += p - scratch;
if(cb(scratch, p - scratch, app_key) < 0)
return -1; return -1;
p = scratch; p = scratch;
} }
...@@ -69,5 +67,45 @@ BMPString_print(asn1_TYPE_descriptor_t *td, const void *sptr, int ilevel, ...@@ -69,5 +67,45 @@ BMPString_print(asn1_TYPE_descriptor_t *td, const void *sptr, int ilevel,
} }
} }
return cb(scratch, p - scratch, app_key); wrote += p - scratch;
if(cb(scratch, p - scratch, app_key) < 0)
return -1;
return wrote;
} }
asn_enc_rval_t
BMPString_encode_xer(asn1_TYPE_descriptor_t *td, void *sptr,
int ilevel, enum xer_encoder_flags_e flags,
asn_app_consume_bytes_f *cb, void *app_key) {
const BMPString_t *st = (const BMPString_t *)sptr;
asn_enc_rval_t er;
(void)ilevel;
(void)flags;
if(!st || !st->buf)
_ASN_ENCODE_FAILED;
er.encoded = BMPString__dump(st, cb, app_key);
if(er.encoded < 0) _ASN_ENCODE_FAILED;
return er;
}
int
BMPString_print(asn1_TYPE_descriptor_t *td, const void *sptr, int ilevel,
asn_app_consume_bytes_f *cb, void *app_key) {
const BMPString_t *st = (const BMPString_t *)sptr;
(void)td; /* Unused argument */
(void)ilevel; /* Unused argument */
if(!st || !st->buf) return cb("<absent>", 8, app_key);
if(BMPString__dump(st, cb, app_key) < 0)
return -1;
return 0;
}
/*- /*-
* Copyright (c) 2003 Lev Walkin <vlm@lionet.info>. All rights reserved. * Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved.
* Redistribution and modifications are permitted subject to BSD license. * Redistribution and modifications are permitted subject to BSD license.
*/ */
#ifndef _BMPString_H_ #ifndef _BMPString_H_
...@@ -13,5 +13,6 @@ typedef OCTET_STRING_t BMPString_t; /* Implemented in terms of OCTET STRING */ ...@@ -13,5 +13,6 @@ typedef OCTET_STRING_t BMPString_t; /* Implemented in terms of OCTET STRING */
extern asn1_TYPE_descriptor_t asn1_DEF_BMPString; extern asn1_TYPE_descriptor_t asn1_DEF_BMPString;
asn_struct_print_f BMPString_print; /* Human-readable output */ asn_struct_print_f BMPString_print; /* Human-readable output */
xer_type_encoder_f BMPString_encode_xer;
#endif /* _BMPString_H_ */ #endif /* _BMPString_H_ */
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
* Copyright (c) 2003 Lev Walkin <vlm@lionet.info>. All rights reserved. * Copyright (c) 2003 Lev Walkin <vlm@lionet.info>. All rights reserved.
* Redistribution and modifications are permitted subject to BSD license. * Redistribution and modifications are permitted subject to BSD license.
*/ */
#include <asn_internal.h>
#include <BOOLEAN.h> #include <BOOLEAN.h>
/* /*
...@@ -12,11 +13,13 @@ static ber_tlv_tag_t asn1_DEF_BOOLEAN_tags[] = { ...@@ -12,11 +13,13 @@ static ber_tlv_tag_t asn1_DEF_BOOLEAN_tags[] = {
}; };
asn1_TYPE_descriptor_t asn1_DEF_BOOLEAN = { asn1_TYPE_descriptor_t asn1_DEF_BOOLEAN = {
"BOOLEAN", "BOOLEAN",
BOOLEAN_free,
BOOLEAN_print,
asn_generic_no_constraint, asn_generic_no_constraint,
BOOLEAN_decode_ber, BOOLEAN_decode_ber,
BOOLEAN_encode_der, BOOLEAN_encode_der,
BOOLEAN_print, 0, /* Not implemented yet */
BOOLEAN_free, BOOLEAN_encode_xer,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn1_DEF_BOOLEAN_tags, asn1_DEF_BOOLEAN_tags,
sizeof(asn1_DEF_BOOLEAN_tags) / sizeof(asn1_DEF_BOOLEAN_tags[0]), sizeof(asn1_DEF_BOOLEAN_tags) / sizeof(asn1_DEF_BOOLEAN_tags[0]),
...@@ -93,11 +96,11 @@ BOOLEAN_decode_ber(asn1_TYPE_descriptor_t *td, ...@@ -93,11 +96,11 @@ BOOLEAN_decode_ber(asn1_TYPE_descriptor_t *td,
return rval; return rval;
} }
der_enc_rval_t asn_enc_rval_t
BOOLEAN_encode_der(asn1_TYPE_descriptor_t *td, void *sptr, BOOLEAN_encode_der(asn1_TYPE_descriptor_t *td, void *sptr,
int tag_mode, ber_tlv_tag_t tag, int tag_mode, ber_tlv_tag_t tag,
asn_app_consume_bytes_f *cb, void *app_key) { asn_app_consume_bytes_f *cb, void *app_key) {
der_enc_rval_t erval; asn_enc_rval_t erval;
BOOLEAN_t *st = (BOOLEAN_t *)sptr; BOOLEAN_t *st = (BOOLEAN_t *)sptr;
erval.encoded = der_write_tags(td, 1, tag_mode, tag, cb, app_key); erval.encoded = der_write_tags(td, 1, tag_mode, tag, cb, app_key);
...@@ -126,6 +129,29 @@ BOOLEAN_encode_der(asn1_TYPE_descriptor_t *td, void *sptr, ...@@ -126,6 +129,29 @@ BOOLEAN_encode_der(asn1_TYPE_descriptor_t *td, void *sptr,
return erval; return erval;
} }
asn_enc_rval_t
BOOLEAN_encode_xer(asn1_TYPE_descriptor_t *td, void *sptr,
int ilevel, enum xer_encoder_flags_e flags,
asn_app_consume_bytes_f *cb, void *app_key) {
const BOOLEAN_t *st = (const BOOLEAN_t *)sptr;
asn_enc_rval_t er;
(void)ilevel;
(void)flags;
if(!st) _ASN_ENCODE_FAILED;
if(*st) {
_ASN_CALLBACK("<true/>", 7);
er.encoded = 7;
} else {
_ASN_CALLBACK("<false/>", 8);
er.encoded = 8;
}
return er;
}
int int
BOOLEAN_print(asn1_TYPE_descriptor_t *td, const void *sptr, int ilevel, BOOLEAN_print(asn1_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) {
......
...@@ -16,9 +16,10 @@ typedef int BOOLEAN_t; ...@@ -16,9 +16,10 @@ typedef int BOOLEAN_t;
extern asn1_TYPE_descriptor_t asn1_DEF_BOOLEAN; extern asn1_TYPE_descriptor_t asn1_DEF_BOOLEAN;
asn_struct_free_f BOOLEAN_free;
asn_struct_print_f BOOLEAN_print;
ber_type_decoder_f BOOLEAN_decode_ber; ber_type_decoder_f BOOLEAN_decode_ber;
der_type_encoder_f BOOLEAN_encode_der; der_type_encoder_f BOOLEAN_encode_der;
asn_struct_print_f BOOLEAN_print; xer_type_encoder_f BOOLEAN_encode_xer;
asn_struct_free_f BOOLEAN_free;
#endif /* _BOOLEAN_H_ */ #endif /* _BOOLEAN_H_ */
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
* Copyright (c) 2003 Lev Walkin <vlm@lionet.info>. All rights reserved. * Copyright (c) 2003 Lev Walkin <vlm@lionet.info>. All rights reserved.
* Redistribution and modifications are permitted subject to BSD license. * Redistribution and modifications are permitted subject to BSD license.
*/ */
#include <asn_internal.h>
#include <ENUMERATED.h> #include <ENUMERATED.h>
/* /*
...@@ -12,11 +13,13 @@ static ber_tlv_tag_t asn1_DEF_ENUMERATED_tags[] = { ...@@ -12,11 +13,13 @@ static ber_tlv_tag_t asn1_DEF_ENUMERATED_tags[] = {
}; };
asn1_TYPE_descriptor_t asn1_DEF_ENUMERATED = { asn1_TYPE_descriptor_t asn1_DEF_ENUMERATED = {
"ENUMERATED", "ENUMERATED",
INTEGER_free, /* Implemented in terms of INTEGER */
INTEGER_print, /* Implemented in terms of INTEGER */
asn_generic_no_constraint, asn_generic_no_constraint,
INTEGER_decode_ber, /* Implemented in terms of INTEGER */ INTEGER_decode_ber, /* Implemented in terms of INTEGER */
INTEGER_encode_der, /* Implemented in terms of INTEGER */ INTEGER_encode_der, /* Implemented in terms of INTEGER */
INTEGER_print, /* Implemented in terms of INTEGER */ 0, /* Not implemented yet */
INTEGER_free, /* Implemented in terms of INTEGER */ INTEGER_encode_xer, /* Implemented in terms of INTEGER */
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn1_DEF_ENUMERATED_tags, asn1_DEF_ENUMERATED_tags,
sizeof(asn1_DEF_ENUMERATED_tags) / sizeof(asn1_DEF_ENUMERATED_tags[0]), sizeof(asn1_DEF_ENUMERATED_tags) / sizeof(asn1_DEF_ENUMERATED_tags[0]),
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
* Copyright (c) 2003 Lev Walkin <vlm@lionet.info>. All rights reserved. * Copyright (c) 2003 Lev Walkin <vlm@lionet.info>. All rights reserved.
* Redistribution and modifications are permitted subject to BSD license. * Redistribution and modifications are permitted subject to BSD license.
*/ */
#include <asn_internal.h>
#include <GeneralString.h> #include <GeneralString.h>
/* /*
...@@ -13,11 +14,13 @@ static ber_tlv_tag_t asn1_DEF_GeneralString_tags[] = { ...@@ -13,11 +14,13 @@ static ber_tlv_tag_t asn1_DEF_GeneralString_tags[] = {
}; };
asn1_TYPE_descriptor_t asn1_DEF_GeneralString = { asn1_TYPE_descriptor_t asn1_DEF_GeneralString = {
"GeneralString", "GeneralString",
OCTET_STRING_free,
OCTET_STRING_print, /* non-ascii string */
asn_generic_unknown_constraint, asn_generic_unknown_constraint,
OCTET_STRING_decode_ber, /* Implemented in terms of OCTET STRING */ OCTET_STRING_decode_ber, /* Implemented in terms of OCTET STRING */
OCTET_STRING_encode_der, /* Implemented in terms of OCTET STRING */ OCTET_STRING_encode_der, /* Implemented in terms of OCTET STRING */
OCTET_STRING_print, /* non-ascii string */ 0, /* Not implemented yet */
OCTET_STRING_free, OCTET_STRING_encode_xer, /* Implemented in terms of OCTET STRING */
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn1_DEF_GeneralString_tags, asn1_DEF_GeneralString_tags,
sizeof(asn1_DEF_GeneralString_tags) sizeof(asn1_DEF_GeneralString_tags)
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
* Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved. * Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved.
* Redistribution and modifications are permitted subject to BSD license. * Redistribution and modifications are permitted subject to BSD license.
*/ */
#include <asn_internal.h>
#include <GeneralizedTime.h> #include <GeneralizedTime.h>
#include <time.h> #include <time.h>
#include <errno.h> #include <errno.h>
...@@ -113,11 +114,13 @@ static ber_tlv_tag_t asn1_DEF_GeneralizedTime_tags[] = { ...@@ -113,11 +114,13 @@ static ber_tlv_tag_t asn1_DEF_GeneralizedTime_tags[] = {
}; };
asn1_TYPE_descriptor_t asn1_DEF_GeneralizedTime = { asn1_TYPE_descriptor_t asn1_DEF_GeneralizedTime = {
"GeneralizedTime", "GeneralizedTime",
OCTET_STRING_free,
GeneralizedTime_print,
GeneralizedTime_constraint, /* Check validity of time */ GeneralizedTime_constraint, /* Check validity of time */
OCTET_STRING_decode_ber, /* Implemented in terms of OCTET STRING */ OCTET_STRING_decode_ber, /* Implemented in terms of OCTET STRING */
GeneralizedTime_encode_der, /* Implemented in terms of OCTET STRING */ GeneralizedTime_encode_der, /* Implemented in terms of OCTET STRING */
GeneralizedTime_print, 0, /* Not implemented yet */
OCTET_STRING_free, GeneralizedTime_encode_xer,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn1_DEF_GeneralizedTime_tags, asn1_DEF_GeneralizedTime_tags,
sizeof(asn1_DEF_GeneralizedTime_tags) sizeof(asn1_DEF_GeneralizedTime_tags)
...@@ -153,12 +156,12 @@ GeneralizedTime_constraint(asn1_TYPE_descriptor_t *td, const void *sptr, ...@@ -153,12 +156,12 @@ GeneralizedTime_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
return 0; return 0;
} }
der_enc_rval_t asn_enc_rval_t
GeneralizedTime_encode_der(asn1_TYPE_descriptor_t *td, void *ptr, GeneralizedTime_encode_der(asn1_TYPE_descriptor_t *td, void *ptr,
int tag_mode, ber_tlv_tag_t tag, int tag_mode, ber_tlv_tag_t tag,
asn_app_consume_bytes_f *cb, void *app_key) { asn_app_consume_bytes_f *cb, void *app_key) {
GeneralizedTime_t *st = (GeneralizedTime_t *)ptr; GeneralizedTime_t *st = (GeneralizedTime_t *)ptr;
der_enc_rval_t erval; asn_enc_rval_t erval;
/* If not canonical DER, re-encode into canonical DER. */ /* If not canonical DER, re-encode into canonical DER. */
if(st->size && st->buf[st->size-1] != 'Z') { if(st->size && st->buf[st->size-1] != 'Z') {
...@@ -194,6 +197,36 @@ GeneralizedTime_encode_der(asn1_TYPE_descriptor_t *td, void *ptr, ...@@ -194,6 +197,36 @@ GeneralizedTime_encode_der(asn1_TYPE_descriptor_t *td, void *ptr,
return erval; return erval;
} }
asn_enc_rval_t
GeneralizedTime_encode_xer(asn1_TYPE_descriptor_t *td, void *sptr,
int ilevel, enum xer_encoder_flags_e flags,
asn_app_consume_bytes_f *cb, void *app_key) {
OCTET_STRING_t st;
if(flags & XER_F_CANONICAL) {
char buf[32];
struct tm tm;
ssize_t ret;
errno = EPERM;
if(asn_GT2time((GeneralizedTime_t *)sptr, &tm, 1) == -1
&& errno != EPERM)
_ASN_ENCODE_FAILED;
ret = snprintf(buf, sizeof(buf), "%04d%02d%02d%02d%02d%02dZ",
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));
st.buf = (uint8_t *)buf;
st.size = ret;
sptr = &st;
}
return OCTET_STRING_encode_xer_ascii(td, sptr, ilevel, flags,
cb, app_key);
}
int int
GeneralizedTime_print(asn1_TYPE_descriptor_t *td, const void *sptr, int ilevel, GeneralizedTime_print(asn1_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) {
......
...@@ -12,9 +12,10 @@ typedef OCTET_STRING_t GeneralizedTime_t; /* Implemented using OCTET STRING */ ...@@ -12,9 +12,10 @@ typedef OCTET_STRING_t GeneralizedTime_t; /* Implemented using OCTET STRING */
extern asn1_TYPE_descriptor_t asn1_DEF_GeneralizedTime; extern asn1_TYPE_descriptor_t asn1_DEF_GeneralizedTime;
asn_struct_print_f GeneralizedTime_print;
asn_constr_check_f GeneralizedTime_constraint; asn_constr_check_f GeneralizedTime_constraint;
der_type_encoder_f GeneralizedTime_encode_der; der_type_encoder_f GeneralizedTime_encode_der;
asn_struct_print_f GeneralizedTime_print; xer_type_encoder_f GeneralizedTime_encode_xer;
/*********************** /***********************
* Some handy helpers. * * Some handy helpers. *
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
* Copyright (c) 2003 Lev Walkin <vlm@lionet.info>. All rights reserved. * Copyright (c) 2003 Lev Walkin <vlm@lionet.info>. All rights reserved.
* Redistribution and modifications are permitted subject to BSD license. * Redistribution and modifications are permitted subject to BSD license.
*/ */
#include <asn_internal.h>
#include <GraphicString.h> #include <GraphicString.h>
/* /*
...@@ -13,11 +14,13 @@ static ber_tlv_tag_t asn1_DEF_GraphicString_tags[] = { ...@@ -13,11 +14,13 @@ static ber_tlv_tag_t asn1_DEF_GraphicString_tags[] = {
}; };
asn1_TYPE_descriptor_t asn1_DEF_GraphicString = { asn1_TYPE_descriptor_t asn1_DEF_GraphicString = {
"GraphicString", "GraphicString",
OCTET_STRING_free,
OCTET_STRING_print, /* non-ascii string */
asn_generic_unknown_constraint, asn_generic_unknown_constraint,
OCTET_STRING_decode_ber, /* Implemented in terms of OCTET STRING */ OCTET_STRING_decode_ber, /* Implemented in terms of OCTET STRING */
OCTET_STRING_encode_der, /* Implemented in terms of OCTET STRING */ OCTET_STRING_encode_der, /* Implemented in terms of OCTET STRING */
OCTET_STRING_print, /* non-ascii string */ 0, /* Not implemented yet */
OCTET_STRING_free, OCTET_STRING_encode_xer, /* Implemented in terms of OCTET STRING */
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn1_DEF_GraphicString_tags, asn1_DEF_GraphicString_tags,
sizeof(asn1_DEF_GraphicString_tags) sizeof(asn1_DEF_GraphicString_tags)
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
* Copyright (c) 2003 Lev Walkin <vlm@lionet.info>. All rights reserved. * Copyright (c) 2003 Lev Walkin <vlm@lionet.info>. All rights reserved.
* Redistribution and modifications are permitted subject to BSD license. * Redistribution and modifications are permitted subject to BSD license.
*/ */
#include <asn_internal.h>
#include <IA5String.h> #include <IA5String.h>
/* /*
...@@ -13,11 +14,13 @@ static ber_tlv_tag_t asn1_DEF_IA5String_tags[] = { ...@@ -13,11 +14,13 @@ static ber_tlv_tag_t asn1_DEF_IA5String_tags[] = {
}; };
asn1_TYPE_descriptor_t asn1_DEF_IA5String = { asn1_TYPE_descriptor_t asn1_DEF_IA5String = {
"IA5String", "IA5String",
OCTET_STRING_free,
OCTET_STRING_print_ascii, /* ASCII subset */
IA5String_constraint, /* Constraint on the alphabet */ IA5String_constraint, /* Constraint on the alphabet */
OCTET_STRING_decode_ber, /* Implemented in terms of OCTET STRING */ OCTET_STRING_decode_ber, /* Implemented in terms of OCTET STRING */
OCTET_STRING_encode_der, /* Implemented in terms of OCTET STRING */ OCTET_STRING_encode_der, /* Implemented in terms of OCTET STRING */
OCTET_STRING_print_ascii, /* ASCII subset */ 0, /* Not implemented yet */
OCTET_STRING_free, OCTET_STRING_encode_xer_ascii,/* Implemented in terms of OCTET STRING */
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn1_DEF_IA5String_tags, asn1_DEF_IA5String_tags,
sizeof(asn1_DEF_IA5String_tags) sizeof(asn1_DEF_IA5String_tags)
...@@ -63,3 +66,4 @@ IA5String_constraint(asn1_TYPE_descriptor_t *td, const void *sptr, ...@@ -63,3 +66,4 @@ IA5String_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
return 0; return 0;
} }
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
* Copyright (c) 2003 Lev Walkin <vlm@lionet.info>. All rights reserved. * Copyright (c) 2003 Lev Walkin <vlm@lionet.info>. All rights reserved.
* Redistribution and modifications are permitted subject to BSD license. * Redistribution and modifications are permitted subject to BSD license.
*/ */
#include <asn_internal.h>
#include <INTEGER.h> #include <INTEGER.h>
#include <assert.h> #include <assert.h>
#include <errno.h> #include <errno.h>
...@@ -14,11 +15,13 @@ static ber_tlv_tag_t asn1_DEF_INTEGER_tags[] = { ...@@ -14,11 +15,13 @@ static ber_tlv_tag_t asn1_DEF_INTEGER_tags[] = {
}; };
asn1_TYPE_descriptor_t asn1_DEF_INTEGER = { asn1_TYPE_descriptor_t asn1_DEF_INTEGER = {
"INTEGER", "INTEGER",
INTEGER_free,
INTEGER_print,
asn_generic_no_constraint, asn_generic_no_constraint,
INTEGER_decode_ber, INTEGER_decode_ber,
INTEGER_encode_der, INTEGER_encode_der,
INTEGER_print, 0, /* Not implemented yet */
INTEGER_free, INTEGER_encode_xer,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn1_DEF_INTEGER_tags, asn1_DEF_INTEGER_tags,
sizeof(asn1_DEF_INTEGER_tags) / sizeof(asn1_DEF_INTEGER_tags[0]), sizeof(asn1_DEF_INTEGER_tags) / sizeof(asn1_DEF_INTEGER_tags[0]),
...@@ -100,11 +103,11 @@ INTEGER_decode_ber(asn1_TYPE_descriptor_t *td, ...@@ -100,11 +103,11 @@ INTEGER_decode_ber(asn1_TYPE_descriptor_t *td,
/* /*
* Encode INTEGER type using DER. * Encode INTEGER type using DER.
*/ */
der_enc_rval_t asn_enc_rval_t
INTEGER_encode_der(asn1_TYPE_descriptor_t *sd, void *ptr, INTEGER_encode_der(asn1_TYPE_descriptor_t *sd, void *ptr,
int tag_mode, ber_tlv_tag_t tag, int tag_mode, ber_tlv_tag_t tag,
asn_app_consume_bytes_f *cb, void *app_key) { asn_app_consume_bytes_f *cb, void *app_key) {
der_enc_rval_t erval; asn_enc_rval_t erval;
INTEGER_t *st = (INTEGER_t *)ptr; INTEGER_t *st = (INTEGER_t *)ptr;
ASN_DEBUG("%s %s as INTEGER (tm=%d)", ASN_DEBUG("%s %s as INTEGER (tm=%d)",
...@@ -185,24 +188,19 @@ INTEGER_encode_der(asn1_TYPE_descriptor_t *sd, void *ptr, ...@@ -185,24 +188,19 @@ INTEGER_encode_der(asn1_TYPE_descriptor_t *sd, void *ptr,
/* /*
* INTEGER specific human-readable output. * INTEGER specific human-readable output.
*/ */
int static ssize_t
INTEGER_print(asn1_TYPE_descriptor_t *td, const void *sptr, int ilevel, INTEGER__dump(const INTEGER_t *st, asn_app_consume_bytes_f *cb, void *app_key) {
asn_app_consume_bytes_f *cb, void *app_key) {
char scratch[32]; /* Enough for 64-bit integer */ char scratch[32]; /* Enough for 64-bit integer */
const INTEGER_t *st = (const INTEGER_t *)sptr;
uint8_t *buf = st->buf; uint8_t *buf = st->buf;
uint8_t *buf_end = st->buf + st->size; uint8_t *buf_end = st->buf + st->size;
signed long accum; signed long accum;
ssize_t wrote = 0;
char *p; char *p;
int ret; int ret;
(void)td; /* Unused argument */ if(st->size == 0) {
(void)ilevel; /* Unused argument */ return (cb("0", 1, app_key) < 0) ? -1 : 1;
}
if(!st && !st->buf) return cb("<absent>", 8, app_key);
if(st->size == 0)
return cb("0", 1, app_key);
/* /*
* Advance buf pointer until the start of the value's body. * Advance buf pointer until the start of the value's body.
...@@ -226,7 +224,7 @@ INTEGER_print(asn1_TYPE_descriptor_t *td, const void *sptr, int ilevel, ...@@ -226,7 +224,7 @@ INTEGER_print(asn1_TYPE_descriptor_t *td, const void *sptr, int ilevel,
accum = (accum << 8) | *buf; accum = (accum << 8) | *buf;
ret = snprintf(scratch, sizeof(scratch), "%ld", accum); ret = snprintf(scratch, sizeof(scratch), "%ld", accum);
assert(ret > 0 && ret < (int)sizeof(scratch)); assert(ret > 0 && ret < (int)sizeof(scratch));
return cb(scratch, ret, app_key); return (cb(scratch, ret, app_key) < 0) ? -1 : ret;
} }
/* Output in the long xx:yy:zz... format */ /* Output in the long xx:yy:zz... format */
...@@ -235,8 +233,9 @@ INTEGER_print(asn1_TYPE_descriptor_t *td, const void *sptr, int ilevel, ...@@ -235,8 +233,9 @@ INTEGER_print(asn1_TYPE_descriptor_t *td, const void *sptr, int ilevel,
static const char *h2c = "0123456789ABCDEF"; static const char *h2c = "0123456789ABCDEF";
if((p - scratch) >= (ssize_t)(sizeof(scratch) - 4)) { if((p - scratch) >= (ssize_t)(sizeof(scratch) - 4)) {
/* Flush buffer */ /* Flush buffer */
if(cb(scratch, p - scratch, app_key)) if(cb(scratch, p - scratch, app_key) < 0)
return -1; return -1;
wrote += p - scratch;
p = scratch; p = scratch;
} }
*p++ = h2c[*buf >> 4]; *p++ = h2c[*buf >> 4];
...@@ -246,7 +245,43 @@ INTEGER_print(asn1_TYPE_descriptor_t *td, const void *sptr, int ilevel, ...@@ -246,7 +245,43 @@ INTEGER_print(asn1_TYPE_descriptor_t *td, const void *sptr, int ilevel,
if(p != scratch) if(p != scratch)
p--; /* Remove the last ':' */ p--; /* Remove the last ':' */
return cb(scratch, p - scratch, app_key); wrote += p - scratch;
return (cb(scratch, p - scratch, app_key) < 0) ? -1 : wrote;
}
/*
* INTEGER specific human-readable output.
*/
int
INTEGER_print(asn1_TYPE_descriptor_t *td, const void *sptr, int ilevel,
asn_app_consume_bytes_f *cb, void *app_key) {
const INTEGER_t *st = (const INTEGER_t *)sptr;
(void)td;
(void)ilevel;
if(!st && !st->buf) return cb("<absent>", 8, app_key);
return (INTEGER__dump(st, cb, app_key) < 0) ? -1 : 0;
}
asn_enc_rval_t
INTEGER_encode_xer(asn1_TYPE_descriptor_t *td, void *sptr,
int ilevel, enum xer_encoder_flags_e flags,
asn_app_consume_bytes_f *cb, void *app_key) {
const INTEGER_t *st = (const INTEGER_t *)sptr;
asn_enc_rval_t er;
(void)ilevel;
(void)flags;
if(!st && !st->buf)
_ASN_ENCODE_FAILED;
er.encoded = INTEGER__dump(st, cb, app_key);
if(er.encoded < 0) _ASN_ENCODE_FAILED;
return er;
} }
void void
......
...@@ -14,10 +14,11 @@ typedef struct INTEGER { ...@@ -14,10 +14,11 @@ typedef struct INTEGER {
extern asn1_TYPE_descriptor_t asn1_DEF_INTEGER; extern asn1_TYPE_descriptor_t asn1_DEF_INTEGER;
asn_struct_free_f INTEGER_free;
asn_struct_print_f INTEGER_print;
ber_type_decoder_f INTEGER_decode_ber; ber_type_decoder_f INTEGER_decode_ber;
der_type_encoder_f INTEGER_encode_der; der_type_encoder_f INTEGER_encode_der;
asn_struct_print_f INTEGER_print; xer_type_encoder_f INTEGER_encode_xer;
asn_struct_free_f INTEGER_free;
/*********************************** /***********************************
* Some handy conversion routines. * * Some handy conversion routines. *
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
* Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved. * Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved.
* Redistribution and modifications are permitted subject to BSD license. * Redistribution and modifications are permitted subject to BSD license.
*/ */
#include <asn_internal.h>
#include <ISO646String.h> #include <ISO646String.h>
/* /*
...@@ -13,11 +14,13 @@ static ber_tlv_tag_t asn1_DEF_ISO646String_tags[] = { ...@@ -13,11 +14,13 @@ static ber_tlv_tag_t asn1_DEF_ISO646String_tags[] = {
}; };
asn1_TYPE_descriptor_t asn1_DEF_ISO646String = { asn1_TYPE_descriptor_t asn1_DEF_ISO646String = {
"ISO646String", "ISO646String",
OCTET_STRING_free,
OCTET_STRING_print_ascii, /* ASCII subset */
VisibleString_constraint, VisibleString_constraint,
OCTET_STRING_decode_ber, /* Implemented in terms of OCTET STRING */ OCTET_STRING_decode_ber, /* Implemented in terms of OCTET STRING */
OCTET_STRING_encode_der, /* Implemented in terms of OCTET STRING */ OCTET_STRING_encode_der, /* Implemented in terms of OCTET STRING */
OCTET_STRING_print_ascii, /* ASCII subset */ 0, /* Not implemented yet */
OCTET_STRING_free, OCTET_STRING_encode_xer_ascii,/* Implemented in terms of OCTET STRING */
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn1_DEF_ISO646String_tags, asn1_DEF_ISO646String_tags,
sizeof(asn1_DEF_ISO646String_tags) sizeof(asn1_DEF_ISO646String_tags)
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
* Copyright (c) 2003 Lev Walkin <vlm@lionet.info>. All rights reserved. * Copyright (c) 2003 Lev Walkin <vlm@lionet.info>. All rights reserved.
* Redistribution and modifications are permitted subject to BSD license. * Redistribution and modifications are permitted subject to BSD license.
*/ */
#include <asn_internal.h>
#include <NULL.h> #include <NULL.h>
#include <BOOLEAN.h> /* Implemented in terms of BOOLEAN type */ #include <BOOLEAN.h> /* Implemented in terms of BOOLEAN type */
...@@ -13,11 +14,13 @@ static ber_tlv_tag_t asn1_DEF_NULL_tags[] = { ...@@ -13,11 +14,13 @@ static ber_tlv_tag_t asn1_DEF_NULL_tags[] = {
}; };
asn1_TYPE_descriptor_t asn1_DEF_NULL = { asn1_TYPE_descriptor_t asn1_DEF_NULL = {
"NULL", "NULL",
BOOLEAN_free,
NULL_print,
asn_generic_no_constraint, asn_generic_no_constraint,
BOOLEAN_decode_ber, /* Implemented in terms of BOOLEAN */ BOOLEAN_decode_ber, /* Implemented in terms of BOOLEAN */
NULL_encode_der, /* Special handling of DER encoding */ NULL_encode_der, /* Special handling of DER encoding */
NULL_print, 0, /* Not implemented yet */
BOOLEAN_free, NULL_encode_xer, /* Special handling of DER encoding */
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn1_DEF_NULL_tags, asn1_DEF_NULL_tags,
sizeof(asn1_DEF_NULL_tags) / sizeof(asn1_DEF_NULL_tags[0]), sizeof(asn1_DEF_NULL_tags) / sizeof(asn1_DEF_NULL_tags[0]),
...@@ -28,21 +31,40 @@ asn1_TYPE_descriptor_t asn1_DEF_NULL = { ...@@ -28,21 +31,40 @@ asn1_TYPE_descriptor_t asn1_DEF_NULL = {
0 /* No specifics */ 0 /* No specifics */
}; };
der_enc_rval_t asn_enc_rval_t
NULL_encode_der(asn1_TYPE_descriptor_t *sd, void *ptr, NULL_encode_der(asn1_TYPE_descriptor_t *td, void *ptr,
int tag_mode, ber_tlv_tag_t tag, int tag_mode, ber_tlv_tag_t tag,
asn_app_consume_bytes_f *cb, void *app_key) { asn_app_consume_bytes_f *cb, void *app_key) {
der_enc_rval_t erval; asn_enc_rval_t erval;
erval.encoded = der_write_tags(sd, 0, tag_mode, tag, cb, app_key); erval.encoded = der_write_tags(td, 0, tag_mode, tag, cb, app_key);
if(erval.encoded == -1) { if(erval.encoded == -1) {
erval.failed_type = sd; erval.failed_type = td;
erval.structure_ptr = ptr; erval.structure_ptr = ptr;
} }
return erval; return erval;
} }
asn_enc_rval_t
NULL_encode_xer(asn1_TYPE_descriptor_t *td, void *sptr,
int ilevel, enum xer_encoder_flags_e flags,
asn_app_consume_bytes_f *cb, void *app_key) {
asn_enc_rval_t er;
(void)td;
(void)sptr;
(void)ilevel;
(void)flags;
(void)cb;
(void)app_key;
/* XMLNullValue is empty */
er.encoded = 0;
return er;
}
int int
NULL_print(asn1_TYPE_descriptor_t *td, const void *sptr, int ilevel, NULL_print(asn1_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) {
......
...@@ -15,7 +15,8 @@ typedef int NULL_t; ...@@ -15,7 +15,8 @@ typedef int NULL_t;
extern asn1_TYPE_descriptor_t asn1_DEF_NULL; extern asn1_TYPE_descriptor_t asn1_DEF_NULL;
der_type_encoder_f NULL_encode_der;
asn_struct_print_f NULL_print; asn_struct_print_f NULL_print;
der_type_encoder_f NULL_encode_der;
xer_type_encoder_f NULL_encode_xer;
#endif /* NULL_H */ #endif /* NULL_H */
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
* implementation deals with the standard (machine-specific) representation * implementation deals with the standard (machine-specific) representation
* of them instead of using the platform-independent buffer. * of them instead of using the platform-independent buffer.
*/ */
#include <asn_internal.h>
#include <NativeEnumerated.h> #include <NativeEnumerated.h>
/* /*
...@@ -19,11 +20,13 @@ static ber_tlv_tag_t asn1_DEF_NativeEnumerated_tags[] = { ...@@ -19,11 +20,13 @@ static ber_tlv_tag_t asn1_DEF_NativeEnumerated_tags[] = {
}; };
asn1_TYPE_descriptor_t asn1_DEF_NativeEnumerated = { asn1_TYPE_descriptor_t asn1_DEF_NativeEnumerated = {
"ENUMERATED", /* The ASN.1 type is still ENUMERATED */ "ENUMERATED", /* The ASN.1 type is still ENUMERATED */
NativeInteger_free,
NativeInteger_print,
asn_generic_no_constraint, asn_generic_no_constraint,
NativeInteger_decode_ber, NativeInteger_decode_ber,
NativeInteger_encode_der, NativeInteger_encode_der,
NativeInteger_print, 0, /* Not implemented yet */
NativeInteger_free, NativeInteger_encode_xer,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn1_DEF_NativeEnumerated_tags, asn1_DEF_NativeEnumerated_tags,
sizeof(asn1_DEF_NativeEnumerated_tags) / sizeof(asn1_DEF_NativeEnumerated_tags[0]), sizeof(asn1_DEF_NativeEnumerated_tags) / sizeof(asn1_DEF_NativeEnumerated_tags[0]),
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
* implementation deals with the standard (machine-specific) representation * implementation deals with the standard (machine-specific) representation
* of them instead of using the platform-independent buffer. * of them instead of using the platform-independent buffer.
*/ */
#include <asn_internal.h>
#include <NativeInteger.h> #include <NativeInteger.h>
#include <INTEGER.h> #include <INTEGER.h>
#include <assert.h> #include <assert.h>
...@@ -21,11 +22,13 @@ static ber_tlv_tag_t asn1_DEF_NativeInteger_tags[] = { ...@@ -21,11 +22,13 @@ static ber_tlv_tag_t asn1_DEF_NativeInteger_tags[] = {
}; };
asn1_TYPE_descriptor_t asn1_DEF_NativeInteger = { asn1_TYPE_descriptor_t asn1_DEF_NativeInteger = {
"INTEGER", /* The ASN.1 type is still INTEGER */ "INTEGER", /* The ASN.1 type is still INTEGER */
NativeInteger_free,
NativeInteger_print,
asn_generic_no_constraint, asn_generic_no_constraint,
NativeInteger_decode_ber, NativeInteger_decode_ber,
NativeInteger_encode_der, NativeInteger_encode_der,
NativeInteger_print, 0, /* Not implemented yet */
NativeInteger_free, NativeInteger_encode_xer,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn1_DEF_NativeInteger_tags, asn1_DEF_NativeInteger_tags,
sizeof(asn1_DEF_NativeInteger_tags) / sizeof(asn1_DEF_NativeInteger_tags[0]), sizeof(asn1_DEF_NativeInteger_tags) / sizeof(asn1_DEF_NativeInteger_tags[0]),
...@@ -127,17 +130,17 @@ NativeInteger_decode_ber(asn1_TYPE_descriptor_t *td, ...@@ -127,17 +130,17 @@ NativeInteger_decode_ber(asn1_TYPE_descriptor_t *td,
/* /*
* Encode the NativeInteger using the standard INTEGER type DER encoder. * Encode the NativeInteger using the standard INTEGER type DER encoder.
*/ */
der_enc_rval_t asn_enc_rval_t
NativeInteger_encode_der(asn1_TYPE_descriptor_t *sd, void *ptr, NativeInteger_encode_der(asn1_TYPE_descriptor_t *sd, void *ptr,
int tag_mode, ber_tlv_tag_t tag, int tag_mode, ber_tlv_tag_t tag,
asn_app_consume_bytes_f *cb, void *app_key) { asn_app_consume_bytes_f *cb, void *app_key) {
unsigned int Int = *(unsigned int *)ptr; /* Disable sign ext. */ unsigned int Int = *(unsigned int *)ptr; /* Disable sign ext. */
der_enc_rval_t erval; asn_enc_rval_t erval;
INTEGER_t tmp; INTEGER_t tmp;
#ifdef WORDS_BIGENDIAN /* Opportunistic optimization */ #ifdef WORDS_BIGENDIAN /* Opportunistic optimization */
tmp.buf = &Int; tmp.buf = (uint8_t *)&Int;
tmp.size = sizeof(Int); tmp.size = sizeof(Int);
#else /* Works even if WORDS_BIGENDIAN is not set where should've been */ #else /* Works even if WORDS_BIGENDIAN is not set where should've been */
...@@ -161,6 +164,27 @@ NativeInteger_encode_der(asn1_TYPE_descriptor_t *sd, void *ptr, ...@@ -161,6 +164,27 @@ NativeInteger_encode_der(asn1_TYPE_descriptor_t *sd, void *ptr,
return erval; return erval;
} }
asn_enc_rval_t
NativeInteger_encode_xer(asn1_TYPE_descriptor_t *td, void *sptr,
int ilevel, enum xer_encoder_flags_e flags,
asn_app_consume_bytes_f *cb, void *app_key) {
char scratch[32]; /* Enough for 64-bit int */
asn_enc_rval_t er;
const int *Int = (const int *)sptr;
(void)ilevel;
(void)flags;
if(!Int) _ASN_ENCODE_FAILED;
er.encoded = snprintf(scratch, sizeof(scratch), "%d", *Int);
if(er.encoded <= 0 || (size_t)er.encoded >= sizeof(scratch)
|| cb(scratch, er.encoded, app_key) < 0)
_ASN_ENCODE_FAILED;
return er;
}
/* /*
* INTEGER specific human-readable output. * INTEGER specific human-readable output.
*/ */
......
...@@ -16,9 +16,10 @@ ...@@ -16,9 +16,10 @@
extern asn1_TYPE_descriptor_t asn1_DEF_NativeInteger; extern asn1_TYPE_descriptor_t asn1_DEF_NativeInteger;
asn_struct_free_f NativeInteger_free;
asn_struct_print_f NativeInteger_print;
ber_type_decoder_f NativeInteger_decode_ber; ber_type_decoder_f NativeInteger_decode_ber;
der_type_encoder_f NativeInteger_encode_der; der_type_encoder_f NativeInteger_encode_der;
asn_struct_print_f NativeInteger_print; xer_type_encoder_f NativeInteger_encode_xer;
asn_struct_free_f NativeInteger_free;
#endif /* _NativeInteger_H_ */ #endif /* _NativeInteger_H_ */
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
* implementation deals with the standard (machine-specific) representation * implementation deals with the standard (machine-specific) representation
* of them instead of using the platform-independent buffer. * of them instead of using the platform-independent buffer.
*/ */
#include <asn_internal.h>
#include <NativeReal.h> #include <NativeReal.h>
#include <INTEGER.h> #include <INTEGER.h>
#include <REAL.h> #include <REAL.h>
...@@ -22,11 +23,13 @@ static ber_tlv_tag_t asn1_DEF_NativeReal_tags[] = { ...@@ -22,11 +23,13 @@ static ber_tlv_tag_t asn1_DEF_NativeReal_tags[] = {
}; };
asn1_TYPE_descriptor_t asn1_DEF_NativeReal = { asn1_TYPE_descriptor_t asn1_DEF_NativeReal = {
"REAL", /* The ASN.1 type is still REAL */ "REAL", /* The ASN.1 type is still REAL */
NativeReal_free,
NativeReal_print,
asn_generic_no_constraint, asn_generic_no_constraint,
NativeReal_decode_ber, NativeReal_decode_ber,
NativeReal_encode_der, NativeReal_encode_der,
NativeReal_print, 0, /* Not implemented yet */
NativeReal_free, NativeReal_encode_xer,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn1_DEF_NativeReal_tags, asn1_DEF_NativeReal_tags,
sizeof(asn1_DEF_NativeReal_tags) / sizeof(asn1_DEF_NativeReal_tags[0]), sizeof(asn1_DEF_NativeReal_tags) / sizeof(asn1_DEF_NativeReal_tags[0]),
...@@ -116,12 +119,12 @@ NativeReal_decode_ber(asn1_TYPE_descriptor_t *td, ...@@ -116,12 +119,12 @@ NativeReal_decode_ber(asn1_TYPE_descriptor_t *td,
/* /*
* Encode the NativeReal using the standard REAL type DER encoder. * Encode the NativeReal using the standard REAL type DER encoder.
*/ */
der_enc_rval_t asn_enc_rval_t
NativeReal_encode_der(asn1_TYPE_descriptor_t *td, void *ptr, NativeReal_encode_der(asn1_TYPE_descriptor_t *td, void *ptr,
int tag_mode, ber_tlv_tag_t tag, int tag_mode, ber_tlv_tag_t tag,
asn_app_consume_bytes_f *cb, void *app_key) { asn_app_consume_bytes_f *cb, void *app_key) {
double Dbl = *(const double *)ptr; double Dbl = *(const double *)ptr;
der_enc_rval_t erval; asn_enc_rval_t erval;
REAL_t tmp; REAL_t tmp;
if(asn1_double2REAL(&tmp, Dbl)) { if(asn1_double2REAL(&tmp, Dbl)) {
...@@ -140,6 +143,25 @@ NativeReal_encode_der(asn1_TYPE_descriptor_t *td, void *ptr, ...@@ -140,6 +143,25 @@ NativeReal_encode_der(asn1_TYPE_descriptor_t *td, void *ptr,
return erval; return erval;
} }
asn_enc_rval_t
NativeReal_encode_xer(asn1_TYPE_descriptor_t *td, void *sptr,
int ilevel, enum xer_encoder_flags_e flags,
asn_app_consume_bytes_f *cb, void *app_key) {
const double *Dbl = (const double *)sptr;
asn_enc_rval_t er;
double d;
(void)ilevel;
if(!Dbl) _ASN_ENCODE_FAILED;
er.encoded = REAL__dump(d, flags & XER_F_CANONICAL, cb, app_key);
if(er.encoded < 0) _ASN_ENCODE_FAILED;
return er;
}
/* /*
* REAL specific human-readable output. * REAL specific human-readable output.
*/ */
...@@ -147,32 +169,13 @@ int ...@@ -147,32 +169,13 @@ int
NativeReal_print(asn1_TYPE_descriptor_t *td, const void *sptr, int ilevel, NativeReal_print(asn1_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) {
const double *Dbl = (const double *)sptr; const double *Dbl = (const double *)sptr;
char scratch[64];
int ret;
(void)td; /* Unused argument */ (void)td; /* Unused argument */
(void)ilevel; /* Unused argument */ (void)ilevel; /* Unused argument */
if(Dbl) { if(!Dbl) return cb("<absent>", 8, app_key);
char *p = scratch;
int buf_size = sizeof(scratch); return (REAL__dump(*Dbl, 0, cb, app_key) < 0) ? -1 : 0;
for(;;) {
ret = snprintf(p, buf_size, "%f", *Dbl);
if(ret >= 0 && ret < buf_size) {
ret = cb(p, ret, app_key);
if(p != scratch) free(p);
return ret;
} else {
if(p != scratch) free(p);
}
if(ret < 0) buf_size <<= 2; /* Old libc. */
else buf_size = ret + 1;
(void *)p = MALLOC(ret);
if(!p) return -1;
}
} else {
return cb("<absent>", 8, app_key);
}
} }
void void
......
...@@ -15,9 +15,10 @@ ...@@ -15,9 +15,10 @@
extern asn1_TYPE_descriptor_t asn1_DEF_NativeReal; extern asn1_TYPE_descriptor_t asn1_DEF_NativeReal;
asn_struct_free_f NativeReal_free;
asn_struct_print_f NativeReal_print;
ber_type_decoder_f NativeReal_decode_ber; ber_type_decoder_f NativeReal_decode_ber;
der_type_encoder_f NativeReal_encode_der; der_type_encoder_f NativeReal_encode_der;
asn_struct_print_f NativeReal_print; xer_type_encoder_f NativeReal_encode_xer;
asn_struct_free_f NativeReal_free;
#endif /* ASN_TYPE_NativeReal_H */ #endif /* ASN_TYPE_NativeReal_H */
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
* Copyright (c) 2003 Lev Walkin <vlm@lionet.info>. All rights reserved. * Copyright (c) 2003 Lev Walkin <vlm@lionet.info>. All rights reserved.
* Redistribution and modifications are permitted subject to BSD license. * Redistribution and modifications are permitted subject to BSD license.
*/ */
#include <asn_internal.h>
#include <NumericString.h> #include <NumericString.h>
/* /*
...@@ -13,11 +14,13 @@ static ber_tlv_tag_t asn1_DEF_NumericString_tags[] = { ...@@ -13,11 +14,13 @@ static ber_tlv_tag_t asn1_DEF_NumericString_tags[] = {
}; };
asn1_TYPE_descriptor_t asn1_DEF_NumericString = { asn1_TYPE_descriptor_t asn1_DEF_NumericString = {
"NumericString", "NumericString",
OCTET_STRING_free,
OCTET_STRING_print_ascii, /* ASCII subset */
NumericString_constraint, NumericString_constraint,
OCTET_STRING_decode_ber, /* Implemented in terms of OCTET STRING */ OCTET_STRING_decode_ber, /* Implemented in terms of OCTET STRING */
OCTET_STRING_encode_der, /* Implemented in terms of OCTET STRING */ OCTET_STRING_encode_der, /* Implemented in terms of OCTET STRING */
OCTET_STRING_print_ascii, /* ASCII subset */ 0, /* Not implemented yet */
OCTET_STRING_free, OCTET_STRING_encode_xer_ascii,/* Implemented in terms of OCTET STRING */
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn1_DEF_NumericString_tags, asn1_DEF_NumericString_tags,
sizeof(asn1_DEF_NumericString_tags) sizeof(asn1_DEF_NumericString_tags)
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
* Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved. * Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved.
* Redistribution and modifications are permitted subject to BSD license. * Redistribution and modifications are permitted subject to BSD license.
*/ */
#include <asn_internal.h>
#include <OBJECT_IDENTIFIER.h> #include <OBJECT_IDENTIFIER.h>
#include <limits.h> /* for CHAR_BIT */ #include <limits.h> /* for CHAR_BIT */
#include <assert.h> #include <assert.h>
...@@ -15,11 +16,13 @@ static ber_tlv_tag_t asn1_DEF_OBJECT_IDENTIFIER_tags[] = { ...@@ -15,11 +16,13 @@ static ber_tlv_tag_t asn1_DEF_OBJECT_IDENTIFIER_tags[] = {
}; };
asn1_TYPE_descriptor_t asn1_DEF_OBJECT_IDENTIFIER = { asn1_TYPE_descriptor_t asn1_DEF_OBJECT_IDENTIFIER = {
"OBJECT IDENTIFIER", "OBJECT IDENTIFIER",
INTEGER_free,
OBJECT_IDENTIFIER_print,
OBJECT_IDENTIFIER_constraint, OBJECT_IDENTIFIER_constraint,
INTEGER_decode_ber, /* Implemented in terms of INTEGER type */ INTEGER_decode_ber, /* Implemented in terms of INTEGER type */
OBJECT_IDENTIFIER_encode_der, OBJECT_IDENTIFIER_encode_der,
OBJECT_IDENTIFIER_print, 0, /* Not implemented yet */
INTEGER_free, OBJECT_IDENTIFIER_encode_xer,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn1_DEF_OBJECT_IDENTIFIER_tags, asn1_DEF_OBJECT_IDENTIFIER_tags,
sizeof(asn1_DEF_OBJECT_IDENTIFIER_tags) sizeof(asn1_DEF_OBJECT_IDENTIFIER_tags)
...@@ -36,11 +39,11 @@ asn1_TYPE_descriptor_t asn1_DEF_OBJECT_IDENTIFIER = { ...@@ -36,11 +39,11 @@ asn1_TYPE_descriptor_t asn1_DEF_OBJECT_IDENTIFIER = {
/* /*
* Encode OBJECT IDENTIFIER type using DER. * Encode OBJECT IDENTIFIER type using DER.
*/ */
der_enc_rval_t asn_enc_rval_t
OBJECT_IDENTIFIER_encode_der(asn1_TYPE_descriptor_t *sd, void *ptr, OBJECT_IDENTIFIER_encode_der(asn1_TYPE_descriptor_t *sd, void *ptr,
int tag_mode, ber_tlv_tag_t tag, int tag_mode, ber_tlv_tag_t tag,
asn_app_consume_bytes_f *cb, void *app_key) { asn_app_consume_bytes_f *cb, void *app_key) {
der_enc_rval_t erval; asn_enc_rval_t erval;
OBJECT_IDENTIFIER_t *st = (OBJECT_IDENTIFIER_t *)ptr; OBJECT_IDENTIFIER_t *st = (OBJECT_IDENTIFIER_t *)ptr;
ASN_DEBUG("%s %s as OBJECT IDENTIFIER (tm=%d)", ASN_DEBUG("%s %s as OBJECT IDENTIFIER (tm=%d)",
...@@ -57,10 +60,8 @@ OBJECT_IDENTIFIER_encode_der(asn1_TYPE_descriptor_t *sd, void *ptr, ...@@ -57,10 +60,8 @@ OBJECT_IDENTIFIER_encode_der(asn1_TYPE_descriptor_t *sd, void *ptr,
} }
if(cb && st->buf) { if(cb && st->buf) {
ssize_t ret; int ret = cb(st->buf, st->size, app_key);
if(ret < 0) {
ret = cb(st->buf, st->size, app_key);
if(ret == -1) {
erval.encoded = -1; erval.encoded = -1;
erval.failed_type = sd; erval.failed_type = sd;
erval.structure_ptr = ptr; erval.structure_ptr = ptr;
...@@ -215,9 +216,8 @@ OBJECT_IDENTIFIER_get_single_arc(uint8_t *arcbuf, unsigned int arclen, signed in ...@@ -215,9 +216,8 @@ OBJECT_IDENTIFIER_get_single_arc(uint8_t *arcbuf, unsigned int arclen, signed in
return 0; return 0;
} }
ssize_t
int OBJECT_IDENTIFIER__dump_arc(uint8_t *arcbuf, int arclen, int add,
OBJECT_IDENTIFIER_print_arc(uint8_t *arcbuf, int arclen, int add,
asn_app_consume_bytes_f *cb, void *app_key) { asn_app_consume_bytes_f *cb, void *app_key) {
char scratch[64]; /* Conservative estimate */ char scratch[64]; /* Conservative estimate */
unsigned long accum; /* Bits accumulator */ unsigned long accum; /* Bits accumulator */
...@@ -228,35 +228,41 @@ OBJECT_IDENTIFIER_print_arc(uint8_t *arcbuf, int arclen, int add, ...@@ -228,35 +228,41 @@ OBJECT_IDENTIFIER_print_arc(uint8_t *arcbuf, int arclen, int add,
return -1; return -1;
if(accum) { if(accum) {
ssize_t len;
/* Fill the scratch buffer in reverse. */ /* Fill the scratch buffer in reverse. */
p = scratch + sizeof(scratch); p = scratch + sizeof(scratch);
for(; accum; accum /= 10) for(; accum; accum /= 10)
*(--p) = (char)(accum % 10) + 0x30; *(--p) = (char)(accum % 10) + 0x30; /* Put a digit */
return cb(p, sizeof(scratch) - (p - scratch), app_key); len = sizeof(scratch) - (p - scratch);
if(cb(p, len, app_key) < 0)
return -1;
return len;
} else { } else {
*scratch = 0x30; *scratch = 0x30;
return cb(scratch, 1, app_key); if(cb(scratch, 1, app_key) < 0)
return -1;
return 1;
} }
} }
int int
OBJECT_IDENTIFIER_print(asn1_TYPE_descriptor_t *td, const void *sptr, OBJECT_IDENTIFIER_print_arc(uint8_t *arcbuf, int arclen, int add,
int ilevel, asn_app_consume_bytes_f *cb, void *app_key) { asn_app_consume_bytes_f *cb, void *app_key) {
const OBJECT_IDENTIFIER_t *st = (const OBJECT_IDENTIFIER_t *)sptr;
int startn;
int add = 0;
int i;
(void)td; /* Unused argument */ if(OBJECT_IDENTIFIER__dump_arc(arcbuf, arclen, add, cb, app_key) < 0)
(void)ilevel; /* Unused argument */ return -1;
if(!st || !st->buf) return 0;
return cb("<absent>", 8, app_key); }
/* Dump preamble */ static ssize_t
if(cb("{ ", 2, app_key)) OBJECT_IDENTIFIER__dump_body(const OBJECT_IDENTIFIER_t *st, asn_app_consume_bytes_f *cb, void *app_key) {
return -1; ssize_t wrote_len = 0;
int startn;
int add = 0;
int i;
for(i = 0, startn = 0; i < st->size; i++) { for(i = 0, startn = 0; i < st->size; i++) {
uint8_t b = st->buf[i]; uint8_t b = st->buf[i];
...@@ -269,30 +275,71 @@ OBJECT_IDENTIFIER_print(asn1_TYPE_descriptor_t *td, const void *sptr, ...@@ -269,30 +275,71 @@ OBJECT_IDENTIFIER_print(asn1_TYPE_descriptor_t *td, const void *sptr,
*/ */
if(i) { if(i) {
add = -80; add = -80;
if(cb("2", 1, app_key)) return -1; if(cb("2", 1, app_key) < 0) return -1;
} else if(b <= 39) { } else if(b <= 39) {
add = 0; add = 0;
if(cb("0", 1, app_key)) return -1; if(cb("0", 1, app_key) < 0) return -1;
} else if(b < 79) { } else if(b < 79) {
add = -40; add = -40;
if(cb("1", 1, app_key)) return -1; if(cb("1", 1, app_key) < 0) return -1;
} else { } else {
add = -80; add = -80;
if(cb("2", 1, app_key)) return -1; if(cb("2", 1, app_key) < 0) return -1;
} }
wrote_len += 1;
} }
if(cb(" ", 1, app_key)) /* Separate arcs */ if(cb(".", 1, app_key) < 0) /* Separate arcs */
return -1; return -1;
if(OBJECT_IDENTIFIER_print_arc(&st->buf[startn], add = OBJECT_IDENTIFIER__dump_arc(&st->buf[startn],
i - startn + 1, add, i - startn + 1, add, cb, app_key);
cb, app_key)) if(add < 0) return -1;
return -1; wrote_len += 1 + add;
startn = i + 1; startn = i + 1;
add = 0; add = 0;
} }
return wrote_len;
}
asn_enc_rval_t
OBJECT_IDENTIFIER_encode_xer(asn1_TYPE_descriptor_t *td, void *sptr,
int ilevel, enum xer_encoder_flags_e flags,
asn_app_consume_bytes_f *cb, void *app_key) {
const OBJECT_IDENTIFIER_t *st = (const OBJECT_IDENTIFIER_t *)sptr;
asn_enc_rval_t er;
(void)ilevel;
(void)flags;
if(!st || !st->buf)
_ASN_ENCODE_FAILED;
er.encoded = OBJECT_IDENTIFIER__dump_body(st, cb, app_key);
if(er.encoded < 0) _ASN_ENCODE_FAILED;
return er;
}
int
OBJECT_IDENTIFIER_print(asn1_TYPE_descriptor_t *td, const void *sptr,
int ilevel, asn_app_consume_bytes_f *cb, void *app_key) {
const OBJECT_IDENTIFIER_t *st = (const OBJECT_IDENTIFIER_t *)sptr;
(void)td; /* Unused argument */
(void)ilevel; /* Unused argument */
if(!st || !st->buf)
return cb("<absent>", 8, app_key);
/* Dump preamble */
if(cb("{ ", 2, app_key))
return -1;
if(OBJECT_IDENTIFIER__dump_body(st, cb, app_key) < 0)
return -1;
return cb(" }", 2, app_key); return cb(" }", 2, app_key);
} }
......
...@@ -12,9 +12,10 @@ typedef INTEGER_t OBJECT_IDENTIFIER_t; /* Implemented in terms of INTEGER */ ...@@ -12,9 +12,10 @@ typedef INTEGER_t OBJECT_IDENTIFIER_t; /* Implemented in terms of INTEGER */
extern asn1_TYPE_descriptor_t asn1_DEF_OBJECT_IDENTIFIER; extern asn1_TYPE_descriptor_t asn1_DEF_OBJECT_IDENTIFIER;
der_type_encoder_f OBJECT_IDENTIFIER_encode_der;
asn_constr_check_f OBJECT_IDENTIFIER_constraint;
asn_struct_print_f OBJECT_IDENTIFIER_print; asn_struct_print_f OBJECT_IDENTIFIER_print;
asn_constr_check_f OBJECT_IDENTIFIER_constraint;
der_type_encoder_f OBJECT_IDENTIFIER_encode_der;
xer_type_encoder_f OBJECT_IDENTIFIER_encode_xer;
/********************************** /**********************************
* Some handy conversion routines * * Some handy conversion routines *
...@@ -27,6 +28,10 @@ int OBJECT_IDENTIFIER_print_arc(uint8_t *arcbuf, int arclen, ...@@ -27,6 +28,10 @@ int OBJECT_IDENTIFIER_print_arc(uint8_t *arcbuf, int arclen,
int add, /* Arbitrary offset, required to process the first two arcs */ int add, /* Arbitrary offset, required to process the first two arcs */
asn_app_consume_bytes_f *cb, void *app_key); asn_app_consume_bytes_f *cb, void *app_key);
/* Same as above, but returns the number of written digits, instead of 0 */
ssize_t OBJECT_IDENTIFIER__dump_arc(uint8_t *arcbuf, int arclen, int add,
asn_app_consume_bytes_f *cb, void *app_key);
/* /*
* This function fills an (_arcs) array with OBJECT IDENTIFIER arcs * This function fills an (_arcs) array with OBJECT IDENTIFIER arcs
* up to specified (_arc_slots) elements. * up to specified (_arc_slots) elements.
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
* Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved. * Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved.
* Redistribution and modifications are permitted subject to BSD license. * Redistribution and modifications are permitted subject to BSD license.
*/ */
#include <asn_internal.h>
#include <OCTET_STRING.h> #include <OCTET_STRING.h>
#include <assert.h> #include <assert.h>
#include <errno.h> #include <errno.h>
...@@ -14,11 +15,13 @@ static ber_tlv_tag_t asn1_DEF_OCTET_STRING_tags[] = { ...@@ -14,11 +15,13 @@ static ber_tlv_tag_t asn1_DEF_OCTET_STRING_tags[] = {
}; };
asn1_TYPE_descriptor_t asn1_DEF_OCTET_STRING = { asn1_TYPE_descriptor_t asn1_DEF_OCTET_STRING = {
"OCTET STRING", "OCTET STRING",
OCTET_STRING_free,
OCTET_STRING_print, /* non-ascii stuff, generally */
asn_generic_no_constraint, asn_generic_no_constraint,
OCTET_STRING_decode_ber, OCTET_STRING_decode_ber,
OCTET_STRING_encode_der, OCTET_STRING_encode_der,
OCTET_STRING_print, /* non-ascii stuff, generally */ 0, /* Not implemented yet */
OCTET_STRING_free, OCTET_STRING_encode_xer,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn1_DEF_OCTET_STRING_tags, asn1_DEF_OCTET_STRING_tags,
sizeof(asn1_DEF_OCTET_STRING_tags) sizeof(asn1_DEF_OCTET_STRING_tags)
...@@ -440,11 +443,11 @@ OCTET_STRING_decode_ber(asn1_TYPE_descriptor_t *td, ...@@ -440,11 +443,11 @@ OCTET_STRING_decode_ber(asn1_TYPE_descriptor_t *td,
/* /*
* Encode OCTET STRING type using DER. * Encode OCTET STRING type using DER.
*/ */
der_enc_rval_t asn_enc_rval_t
OCTET_STRING_encode_der(asn1_TYPE_descriptor_t *td, void *ptr, OCTET_STRING_encode_der(asn1_TYPE_descriptor_t *td, void *ptr,
int tag_mode, ber_tlv_tag_t tag, int tag_mode, ber_tlv_tag_t tag,
asn_app_consume_bytes_f *cb, void *app_key) { asn_app_consume_bytes_f *cb, void *app_key) {
der_enc_rval_t erval; asn_enc_rval_t erval;
OCTET_STRING_t *st = (OCTET_STRING_t *)ptr; OCTET_STRING_t *st = (OCTET_STRING_t *)ptr;
int add_byte = 0; int add_byte = 0;
int is_bit_str = (td->specifics == (void *)-1); int is_bit_str = (td->specifics == (void *)-1);
...@@ -514,6 +517,84 @@ OCTET_STRING_encode_der(asn1_TYPE_descriptor_t *td, void *ptr, ...@@ -514,6 +517,84 @@ OCTET_STRING_encode_der(asn1_TYPE_descriptor_t *td, void *ptr,
return erval; return erval;
} }
asn_enc_rval_t
OCTET_STRING_encode_xer(asn1_TYPE_descriptor_t *td, void *sptr,
int ilevel, enum xer_encoder_flags_e flags,
asn_app_consume_bytes_f *cb, void *app_key) {
static const char *h2c = "0123456789ABCDEF";
const OCTET_STRING_t *st = (const OCTET_STRING_t *)sptr;
asn_enc_rval_t er;
char scratch[16 * 3 + 4];
char *p = scratch;
uint8_t *buf;
uint8_t *end;
size_t i;
if(!st || !st->buf) {
er.encoded = -1;
er.failed_type = td;
er.structure_ptr = sptr;
return er;
}
er.encoded = 0;
/*
* Dump the contents of the buffer in hexadecimal.
*/
buf = st->buf;
end = buf + st->size;
if(flags & XER_F_CANONICAL) {
char *scend = scratch + (sizeof(scratch) - 2);
for(; buf < end; buf++) {
if(p >= scend) {
_ASN_CALLBACK(scratch, p - scratch);
er.encoded += p - scratch;
p = scratch;
}
*p++ = h2c[(*buf >> 4) & 0x0F];
*p++ = h2c[*buf & 0x0F];
}
} else {
for(i = 0; buf < end; buf++, i++) {
if(!(i % 16) && (i || st->size > 16)) {
_ASN_CALLBACK(scratch, p-scratch);
er.encoded += (p-scratch);
p = scratch;
_i_ASN_TEXT_INDENT(1, ilevel);
}
*p++ = h2c[(*buf >> 4) & 0x0F];
*p++ = h2c[*buf & 0x0F];
*p++ = 0x20;
}
if(i) p--; /* Remove the tail space */
}
_ASN_CALLBACK(scratch, p-scratch); /* Dump the rest */
er.encoded += p - scratch;
return er;
}
asn_enc_rval_t
OCTET_STRING_encode_xer_ascii(asn1_TYPE_descriptor_t *td, void *sptr,
int ilevel, enum xer_encoder_flags_e flags,
asn_app_consume_bytes_f *cb, void *app_key) {
const OCTET_STRING_t *st = (const OCTET_STRING_t *)sptr;
asn_enc_rval_t er;
(void)ilevel; /* Unused argument */
(void)flags; /* Unused argument */
if(!st || !st->buf)
_ASN_ENCODE_FAILED;
_ASN_CALLBACK(st->buf, st->size);
er.encoded = st->size;
return er;
}
int int
OCTET_STRING_print(asn1_TYPE_descriptor_t *td, const void *sptr, int ilevel, OCTET_STRING_print(asn1_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) {
...@@ -524,7 +605,7 @@ OCTET_STRING_print(asn1_TYPE_descriptor_t *td, const void *sptr, int ilevel, ...@@ -524,7 +605,7 @@ OCTET_STRING_print(asn1_TYPE_descriptor_t *td, const void *sptr, int ilevel,
uint8_t *buf; uint8_t *buf;
uint8_t *end; uint8_t *end;
size_t i; size_t i;
int ret; int lvl;
(void)td; /* Unused argument */ (void)td; /* Unused argument */
...@@ -540,14 +621,15 @@ OCTET_STRING_print(asn1_TYPE_descriptor_t *td, const void *sptr, int ilevel, ...@@ -540,14 +621,15 @@ OCTET_STRING_print(asn1_TYPE_descriptor_t *td, const void *sptr, int ilevel,
if(cb(scratch, p - scratch, app_key) if(cb(scratch, p - scratch, app_key)
|| cb("\n", 1, app_key)) || cb("\n", 1, app_key))
return -1; return -1;
for(ret = 0; ret < ilevel; ret++) for(lvl = 0; lvl < ilevel; lvl++)
cb(" ", 1, app_key); cb(" ", 1, app_key);
p = scratch; p = scratch;
} }
*p++ = h2c[(*buf >> 4) & 0x0F]; *p++ = h2c[(*buf >> 4) & 0x0F];
*p++ = h2c[*buf & 0x0F]; *p++ = h2c[*buf & 0x0F];
*p++ = ' '; *p++ = 0x20;
} }
if(i) p--; /* Remove the tail space */
return cb(scratch, p - scratch, app_key); return cb(scratch, p - scratch, app_key);
} }
......
...@@ -16,11 +16,13 @@ typedef struct OCTET_STRING { ...@@ -16,11 +16,13 @@ typedef struct OCTET_STRING {
extern asn1_TYPE_descriptor_t asn1_DEF_OCTET_STRING; extern asn1_TYPE_descriptor_t asn1_DEF_OCTET_STRING;
ber_type_decoder_f OCTET_STRING_decode_ber; asn_struct_free_f OCTET_STRING_free;
der_type_encoder_f OCTET_STRING_encode_der;
asn_struct_print_f OCTET_STRING_print; asn_struct_print_f OCTET_STRING_print;
asn_struct_print_f OCTET_STRING_print_ascii; asn_struct_print_f OCTET_STRING_print_ascii;
asn_struct_free_f OCTET_STRING_free; ber_type_decoder_f OCTET_STRING_decode_ber;
der_type_encoder_f OCTET_STRING_encode_der;
xer_type_encoder_f OCTET_STRING_encode_xer;
xer_type_encoder_f OCTET_STRING_encode_xer_ascii;
/*********************************** /***********************************
* Some handy conversion routines. * * Some handy conversion routines. *
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
* Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved. * Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved.
* Redistribution and modifications are permitted subject to BSD license. * Redistribution and modifications are permitted subject to BSD license.
*/ */
#include <asn_internal.h>
#include <ObjectDescriptor.h> #include <ObjectDescriptor.h>
/* /*
...@@ -13,11 +14,13 @@ static ber_tlv_tag_t asn1_DEF_ObjectDescriptor_tags[] = { ...@@ -13,11 +14,13 @@ static ber_tlv_tag_t asn1_DEF_ObjectDescriptor_tags[] = {
}; };
asn1_TYPE_descriptor_t asn1_DEF_ObjectDescriptor = { asn1_TYPE_descriptor_t asn1_DEF_ObjectDescriptor = {
"ObjectDescriptor", "ObjectDescriptor",
OCTET_STRING_free,
OCTET_STRING_print_ascii, /* Treat as ASCII subset (it's not) */
asn_generic_unknown_constraint, asn_generic_unknown_constraint,
OCTET_STRING_decode_ber, /* Implemented in terms of OCTET STRING */ OCTET_STRING_decode_ber, /* Implemented in terms of OCTET STRING */
OCTET_STRING_encode_der, /* Implemented in terms of OCTET STRING */ OCTET_STRING_encode_der, /* Implemented in terms of OCTET STRING */
OCTET_STRING_print_ascii, /* Treat as ASCII subset (it's not) */ 0, /* Not implemented yet */
OCTET_STRING_free, OCTET_STRING_encode_xer_ascii,/* Implemented in terms of OCTET STRING */
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn1_DEF_ObjectDescriptor_tags, asn1_DEF_ObjectDescriptor_tags,
sizeof(asn1_DEF_ObjectDescriptor_tags) sizeof(asn1_DEF_ObjectDescriptor_tags)
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
* Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved. * Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved.
* Redistribution and modifications are permitted subject to BSD license. * Redistribution and modifications are permitted subject to BSD license.
*/ */
#include <asn_internal.h>
#include <PrintableString.h> #include <PrintableString.h>
/* /*
...@@ -13,11 +14,13 @@ static ber_tlv_tag_t asn1_DEF_PrintableString_tags[] = { ...@@ -13,11 +14,13 @@ static ber_tlv_tag_t asn1_DEF_PrintableString_tags[] = {
}; };
asn1_TYPE_descriptor_t asn1_DEF_PrintableString = { asn1_TYPE_descriptor_t asn1_DEF_PrintableString = {
"PrintableString", "PrintableString",
OCTET_STRING_free,
OCTET_STRING_print_ascii, /* ASCII subset */
PrintableString_constraint, PrintableString_constraint,
OCTET_STRING_decode_ber, /* Implemented in terms of OCTET STRING */ OCTET_STRING_decode_ber, /* Implemented in terms of OCTET STRING */
OCTET_STRING_encode_der, /* Implemented in terms of OCTET STRING */ OCTET_STRING_encode_der, /* Implemented in terms of OCTET STRING */
OCTET_STRING_print_ascii, /* ASCII subset */ 0, /* Not implemented yet */
OCTET_STRING_free, OCTET_STRING_encode_xer_ascii,/* Implemented in terms of OCTET STRING */
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn1_DEF_PrintableString_tags, asn1_DEF_PrintableString_tags,
sizeof(asn1_DEF_PrintableString_tags) sizeof(asn1_DEF_PrintableString_tags)
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
* Copyright (c) 2004 Lev Walkin <vlm@lionet.info>. All rights reserved. * Copyright (c) 2004 Lev Walkin <vlm@lionet.info>. All rights reserved.
* Redistribution and modifications are permitted subject to BSD license. * Redistribution and modifications are permitted subject to BSD license.
*/ */
#include <asn_internal.h>
#include <REAL.h> #include <REAL.h>
#include <INTEGER.h> #include <INTEGER.h>
#include <stdlib.h> /* for strtod(3) */ #include <stdlib.h> /* for strtod(3) */
...@@ -29,11 +30,13 @@ static ber_tlv_tag_t asn1_DEF_REAL_tags[] = { ...@@ -29,11 +30,13 @@ static ber_tlv_tag_t asn1_DEF_REAL_tags[] = {
}; };
asn1_TYPE_descriptor_t asn1_DEF_REAL = { asn1_TYPE_descriptor_t asn1_DEF_REAL = {
"REAL", "REAL",
INTEGER_free,
REAL_print,
asn_generic_no_constraint, asn_generic_no_constraint,
INTEGER_decode_ber, /* Implemented in terms of INTEGER type */ INTEGER_decode_ber, /* Implemented in terms of INTEGER type */
INTEGER_encode_der, INTEGER_encode_der,
REAL_print, 0, /* Not implemented yet */
INTEGER_free, REAL_encode_xer,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn1_DEF_REAL_tags, asn1_DEF_REAL_tags,
sizeof(asn1_DEF_REAL_tags) / sizeof(asn1_DEF_REAL_tags[0]), sizeof(asn1_DEF_REAL_tags) / sizeof(asn1_DEF_REAL_tags[0]),
...@@ -44,33 +47,113 @@ asn1_TYPE_descriptor_t asn1_DEF_REAL = { ...@@ -44,33 +47,113 @@ asn1_TYPE_descriptor_t asn1_DEF_REAL = {
0 /* No specifics */ 0 /* No specifics */
}; };
ssize_t
REAL__dump(double d, int canonical, asn_app_consume_bytes_f *cb, void *app_key) {
char local_buf[32];
char *buf = local_buf;
ssize_t buflen = sizeof(local_buf);
const char *fmt = canonical?"%15E":"f";
ssize_t ret;
do {
ret = snprintf(buf, buflen, fmt, d);
if(ret < 0) {
buflen <<= 1;
} else if(ret >= buflen) {
buflen = ret + 1;
} else {
buflen = ret;
break;
}
if(buf != local_buf) free(buf);
(void *)buf = MALLOC(buflen);
if(!buf) return -1;
} while(1);
/*
* Transform the "[-]d.dddE+-dd" output into "[-]d.dddE[-]d"
*/
if(canonical) {
char *dot, *E;
char *end = buf + buflen;
dot = (buf[0] == '-') ? (buf + 2) : (buf + 1);
if(*dot >= 0x30) {
errno = EINVAL;
return -1; /* Not a dot, really */
}
*dot = '.'; /* Replace possible comma */
for(E = dot; dot < end; E++) {
if(*E == 'E') {
char *s = ++E;
if(*E == '+') {
/* Skip the "+" too */
buflen -= 2;
} else {
buflen -= 1;
s++;
}
E += 2;
if(E[-1] != '0' || E > end) {
errno = EINVAL;
return -1;
}
for(; E <= end; s++, E++)
*s = *E;
}
}
if(E == end) {
errno = EINVAL;
return -1; /* No promised E */
}
}
ret = cb(buf, buflen, app_key);
if(buf != local_buf) free(buf);
return (ret < 0) ? -1 : buflen;
}
int int
REAL_print(asn1_TYPE_descriptor_t *td, const void *sptr, int ilevel, REAL_print(asn1_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) {
const REAL_t *st = (const REAL_t *)sptr; const REAL_t *st = (const REAL_t *)sptr;
char buf[128];
double d; double d;
int ret;
(void)td; /* Unused argument */ (void)td; /* Unused argument */
(void)ilevel; /* Unused argument */ (void)ilevel; /* Unused argument */
if(!st) if(!st || !st->buf)
return cb("<absent>", 8, app_key); return cb("<absent>", 8, app_key);
if(asn1_REAL2double(st, &d)) if(asn1_REAL2double(st, &d))
return cb("<error>", 7, app_key); return cb("<error>", 7, app_key);
ret = snprintf(buf, sizeof(buf), "%f", d); return (REAL__dump(d, 0, cb, app_key) < 0) ? -1 : 0;
if(ret < 0 || ret >= sizeof(buf)) }
return cb("<error>", 7, app_key);
asn_enc_rval_t
REAL_encode_xer(asn1_TYPE_descriptor_t *td, void *sptr,
int ilevel, enum xer_encoder_flags_e flags,
asn_app_consume_bytes_f *cb, void *app_key) {
REAL_t *st = (REAL_t *)sptr;
asn_enc_rval_t er;
double d;
(void)ilevel;
if(!st || !st->buf || asn1_REAL2double(st, &d))
_ASN_ENCODE_FAILED;
er.encoded = REAL__dump(d, flags & XER_F_CANONICAL, cb, app_key);
if(er.encoded < 0) _ASN_ENCODE_FAILED;
return cb(buf, ret, app_key); return er;
} }
int int
asn1_REAL2double(const REAL_t *st, double *dbl_value) { asn1_REAL2double(const REAL_t *st, double *dbl_value) {
unsigned long octv; unsigned int octv;
if(!st || !st->buf) { if(!st || !st->buf) {
errno = EINVAL; errno = EINVAL;
...@@ -158,7 +241,7 @@ asn1_REAL2double(const REAL_t *st, double *dbl_value) { ...@@ -158,7 +241,7 @@ asn1_REAL2double(const REAL_t *st, double *dbl_value) {
sign = (octv & 0x40); /* bit 7 */ sign = (octv & 0x40); /* bit 7 */
scaleF = (octv & 0x0C) >> 2; /* bits 4 to 3 */ scaleF = (octv & 0x0C) >> 2; /* bits 4 to 3 */
if(st->size <= (1 + (octv & 0x03))) { if(st->size <= (int)(1 + (octv & 0x03))) {
errno = EINVAL; errno = EINVAL;
return -1; return -1;
} }
...@@ -166,7 +249,7 @@ asn1_REAL2double(const REAL_t *st, double *dbl_value) { ...@@ -166,7 +249,7 @@ asn1_REAL2double(const REAL_t *st, double *dbl_value) {
if((octv & 0x03) == 0x11) { if((octv & 0x03) == 0x11) {
/* 8.5.6.4, case d) */ /* 8.5.6.4, case d) */
elen = st->buf[1]; /* unsigned binary number */ elen = st->buf[1]; /* unsigned binary number */
if(elen == 0 || st->size <= (2 + elen)) { if(elen == 0 || st->size <= (int)(2 + elen)) {
errno = EINVAL; errno = EINVAL;
return -1; return -1;
} }
......
...@@ -15,11 +15,14 @@ typedef struct REAL { ...@@ -15,11 +15,14 @@ typedef struct REAL {
extern asn1_TYPE_descriptor_t asn1_DEF_REAL; extern asn1_TYPE_descriptor_t asn1_DEF_REAL;
asn_struct_print_f REAL_print; asn_struct_print_f REAL_print;
xer_type_encoder_f REAL_encode_xer;
/*********************************** /***********************************
* Some handy conversion routines. * * Some handy conversion routines. *
***********************************/ ***********************************/
ssize_t REAL__dump(double d, int canonical, asn_app_consume_bytes_f *cb, void *app_key);
/* /*
* Convert between native double type and REAL representation (DER). * Convert between native double type and REAL representation (DER).
* RETURN VALUES: * RETURN VALUES:
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
* Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved. * Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved.
* Redistribution and modifications are permitted subject to BSD license. * Redistribution and modifications are permitted subject to BSD license.
*/ */
#include <asn_internal.h>
#include <RELATIVE-OID.h> #include <RELATIVE-OID.h>
#include <limits.h> /* for CHAR_BIT */ #include <limits.h> /* for CHAR_BIT */
#include <assert.h> #include <assert.h>
...@@ -15,11 +16,13 @@ static ber_tlv_tag_t asn1_DEF_RELATIVE_OID_tags[] = { ...@@ -15,11 +16,13 @@ static ber_tlv_tag_t asn1_DEF_RELATIVE_OID_tags[] = {
}; };
asn1_TYPE_descriptor_t asn1_DEF_RELATIVE_OID = { asn1_TYPE_descriptor_t asn1_DEF_RELATIVE_OID = {
"RELATIVE-OID", "RELATIVE-OID",
INTEGER_free,
RELATIVE_OID_print,
asn_generic_no_constraint, asn_generic_no_constraint,
INTEGER_decode_ber, /* Implemented in terms of INTEGER type */ INTEGER_decode_ber, /* Implemented in terms of INTEGER type */
OBJECT_IDENTIFIER_encode_der, OBJECT_IDENTIFIER_encode_der,
RELATIVE_OID_print, 0, /* Not implemented yet */
INTEGER_free, RELATIVE_OID_encode_xer,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn1_DEF_RELATIVE_OID_tags, asn1_DEF_RELATIVE_OID_tags,
sizeof(asn1_DEF_RELATIVE_OID_tags) sizeof(asn1_DEF_RELATIVE_OID_tags)
...@@ -32,12 +35,39 @@ asn1_TYPE_descriptor_t asn1_DEF_RELATIVE_OID = { ...@@ -32,12 +35,39 @@ asn1_TYPE_descriptor_t asn1_DEF_RELATIVE_OID = {
0 /* No specifics */ 0 /* No specifics */
}; };
static ssize_t
RELATIVE_OID__dump_body(const RELATIVE_OID_t *st, asn_app_consume_bytes_f *cb, void *app_key) {
ssize_t wrote = 0;
ssize_t ret;
int startn;
int i;
for(i = 0, startn = 0; i < st->size; i++) {
uint8_t b = st->buf[i];
if((b & 0x80)) /* Continuation expected */
continue;
if(startn) {
/* Separate arcs */
if(cb(".", 1, app_key) < 0)
return -1;
wrote++;
}
ret = OBJECT_IDENTIFIER__dump_arc(&st->buf[startn],
i - startn + 1, 0, cb, app_key);
if(ret < 0) return -1;
wrote += ret;
startn = i + 1;
}
return wrote;
}
int int
RELATIVE_OID_print(asn1_TYPE_descriptor_t *td, const void *sptr, int ilevel, RELATIVE_OID_print(asn1_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) {
const RELATIVE_OID_t *st = (const RELATIVE_OID_t *)sptr; const RELATIVE_OID_t *st = (const RELATIVE_OID_t *)sptr;
int startn;
int i;
(void)td; /* Unused argument */ (void)td; /* Unused argument */
(void)ilevel; /* Unused argument */ (void)ilevel; /* Unused argument */
...@@ -49,21 +79,30 @@ RELATIVE_OID_print(asn1_TYPE_descriptor_t *td, const void *sptr, int ilevel, ...@@ -49,21 +79,30 @@ RELATIVE_OID_print(asn1_TYPE_descriptor_t *td, const void *sptr, int ilevel,
if(cb("{ ", 2, app_key)) if(cb("{ ", 2, app_key))
return -1; return -1;
for(i = 0, startn = 0; i < st->size; i++) { if(RELATIVE_OID__dump_body(st, cb, app_key) < 0)
uint8_t b = st->buf[i];
if((b & 0x80)) /* Continuation expected */
continue;
if(startn && cb(" ", 1, app_key)) /* Separate arcs */
return -1; return -1;
if(OBJECT_IDENTIFIER_print_arc(&st->buf[startn],
i - startn + 1, 0, cb, app_key))
return -1;
startn = i + 1;
}
return cb(" }", 2, app_key); return cb(" }", 2, app_key);
} }
asn_enc_rval_t
RELATIVE_OID_encode_xer(asn1_TYPE_descriptor_t *td, void *sptr,
int ilevel, enum xer_encoder_flags_e flags,
asn_app_consume_bytes_f *cb, void *app_key) {
RELATIVE_OID_t *st = (RELATIVE_OID_t *)sptr;
asn_enc_rval_t er;
(void)ilevel; /* Unused argument */
(void)flags; /* Unused argument */
if(!st || !st->buf)
_ASN_ENCODE_FAILED;
er.encoded = RELATIVE_OID__dump_body(st, cb, app_key);
if(er.encoded < 0) _ASN_ENCODE_FAILED;
return er;
}
int int
RELATIVE_OID_get_arcs(RELATIVE_OID_t *roid, RELATIVE_OID_get_arcs(RELATIVE_OID_t *roid,
......
...@@ -14,6 +14,7 @@ typedef OBJECT_IDENTIFIER_t RELATIVE_OID_t; ...@@ -14,6 +14,7 @@ typedef OBJECT_IDENTIFIER_t RELATIVE_OID_t;
extern asn1_TYPE_descriptor_t asn1_DEF_RELATIVE_OID; extern asn1_TYPE_descriptor_t asn1_DEF_RELATIVE_OID;
asn_struct_print_f RELATIVE_OID_print; asn_struct_print_f RELATIVE_OID_print;
xer_type_encoder_f RELATIVE_OID_encode_xer;
/********************************** /**********************************
* Some handy conversion routines * * Some handy conversion routines *
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
* Copyright (c) 2003 Lev Walkin <vlm@lionet.info>. All rights reserved. * Copyright (c) 2003 Lev Walkin <vlm@lionet.info>. All rights reserved.
* Redistribution and modifications are permitted subject to BSD license. * Redistribution and modifications are permitted subject to BSD license.
*/ */
#include <asn_internal.h>
#include <T61String.h> #include <T61String.h>
/* /*
...@@ -13,11 +14,13 @@ static ber_tlv_tag_t asn1_DEF_T61String_tags[] = { ...@@ -13,11 +14,13 @@ static ber_tlv_tag_t asn1_DEF_T61String_tags[] = {
}; };
asn1_TYPE_descriptor_t asn1_DEF_T61String = { asn1_TYPE_descriptor_t asn1_DEF_T61String = {
"T61String", "T61String",
OCTET_STRING_free,
OCTET_STRING_print, /* non-ascii string */
asn_generic_unknown_constraint, asn_generic_unknown_constraint,
OCTET_STRING_decode_ber, /* Implemented in terms of OCTET STRING */ OCTET_STRING_decode_ber, /* Implemented in terms of OCTET STRING */
OCTET_STRING_encode_der, /* Implemented in terms of OCTET STRING */ OCTET_STRING_encode_der, /* Implemented in terms of OCTET STRING */
OCTET_STRING_print, /* non-ascii string */ 0, /* Not implemented yet */
OCTET_STRING_free, OCTET_STRING_encode_xer, /* Implemented in terms of OCTET STRING */
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn1_DEF_T61String_tags, asn1_DEF_T61String_tags,
sizeof(asn1_DEF_T61String_tags) sizeof(asn1_DEF_T61String_tags)
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
* Copyright (c) 2003 Lev Walkin <vlm@lionet.info>. All rights reserved. * Copyright (c) 2003 Lev Walkin <vlm@lionet.info>. All rights reserved.
* Redistribution and modifications are permitted subject to BSD license. * Redistribution and modifications are permitted subject to BSD license.
*/ */
#include <asn_internal.h>
#include <TeletexString.h> #include <TeletexString.h>
/* /*
...@@ -13,11 +14,13 @@ static ber_tlv_tag_t asn1_DEF_TeletexString_tags[] = { ...@@ -13,11 +14,13 @@ static ber_tlv_tag_t asn1_DEF_TeletexString_tags[] = {
}; };
asn1_TYPE_descriptor_t asn1_DEF_TeletexString = { asn1_TYPE_descriptor_t asn1_DEF_TeletexString = {
"TeletexString", "TeletexString",
OCTET_STRING_free,
OCTET_STRING_print, /* non-ascii string */
asn_generic_unknown_constraint, asn_generic_unknown_constraint,
OCTET_STRING_decode_ber, /* Implemented in terms of OCTET STRING */ OCTET_STRING_decode_ber, /* Implemented in terms of OCTET STRING */
OCTET_STRING_encode_der, /* Implemented in terms of OCTET STRING */ OCTET_STRING_encode_der, /* Implemented in terms of OCTET STRING */
OCTET_STRING_print, /* non-ascii string */ 0, /* Not implemented yet */
OCTET_STRING_free, OCTET_STRING_encode_xer, /* Implemented in terms of OCTET STRING */
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn1_DEF_TeletexString_tags, asn1_DEF_TeletexString_tags,
sizeof(asn1_DEF_TeletexString_tags) sizeof(asn1_DEF_TeletexString_tags)
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
* Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved. * Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved.
* Redistribution and modifications are permitted subject to BSD license. * Redistribution and modifications are permitted subject to BSD license.
*/ */
#include <asn_internal.h>
#include <UTCTime.h> #include <UTCTime.h>
#include <GeneralizedTime.h> #include <GeneralizedTime.h>
#include <time.h> #include <time.h>
...@@ -18,11 +19,13 @@ static ber_tlv_tag_t asn1_DEF_UTCTime_tags[] = { ...@@ -18,11 +19,13 @@ static ber_tlv_tag_t asn1_DEF_UTCTime_tags[] = {
}; };
asn1_TYPE_descriptor_t asn1_DEF_UTCTime = { asn1_TYPE_descriptor_t asn1_DEF_UTCTime = {
"UTCTime", "UTCTime",
OCTET_STRING_free,
UTCTime_print,
UTCTime_constraint, UTCTime_constraint,
OCTET_STRING_decode_ber, /* Implemented in terms of OCTET STRING */ OCTET_STRING_decode_ber, /* Implemented in terms of OCTET STRING */
OCTET_STRING_encode_der, /* Implemented in terms of OCTET STRING */ OCTET_STRING_encode_der, /* Implemented in terms of OCTET STRING */
UTCTime_print, 0, /* Not implemented yet */
OCTET_STRING_free, UTCTime_encode_xer,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn1_DEF_UTCTime_tags, asn1_DEF_UTCTime_tags,
sizeof(asn1_DEF_UTCTime_tags) sizeof(asn1_DEF_UTCTime_tags)
...@@ -58,6 +61,36 @@ UTCTime_constraint(asn1_TYPE_descriptor_t *td, const void *sptr, ...@@ -58,6 +61,36 @@ UTCTime_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
return 0; return 0;
} }
asn_enc_rval_t
UTCTime_encode_xer(asn1_TYPE_descriptor_t *td, void *sptr,
int ilevel, enum xer_encoder_flags_e flags,
asn_app_consume_bytes_f *cb, void *app_key) {
OCTET_STRING_t st;
if(flags & XER_F_CANONICAL) {
char buf[32];
struct tm tm;
ssize_t ret;
errno = EPERM;
if(asn_UT2time((UTCTime_t *)sptr, &tm, 1) == -1
&& errno != EPERM)
_ASN_ENCODE_FAILED;
ret = snprintf(buf, sizeof(buf), "%02d%02d%02d%02d%02d%02dZ",
tm.tm_year % 100, tm.tm_mon + 1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec);
assert(ret > 0 && ret < (int)sizeof(buf));
st.buf = (uint8_t *)buf;
st.size = ret;
sptr = &st;
}
return OCTET_STRING_encode_xer_ascii(td, sptr, ilevel, flags,
cb, app_key);
}
int int
UTCTime_print(asn1_TYPE_descriptor_t *td, const void *sptr, int ilevel, UTCTime_print(asn1_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) {
......
...@@ -12,8 +12,9 @@ typedef OCTET_STRING_t UTCTime_t; /* Implemented using OCTET STRING */ ...@@ -12,8 +12,9 @@ typedef OCTET_STRING_t UTCTime_t; /* Implemented using OCTET STRING */
extern asn1_TYPE_descriptor_t asn1_DEF_UTCTime; extern asn1_TYPE_descriptor_t asn1_DEF_UTCTime;
asn_constr_check_f UTCTime_constraint;
asn_struct_print_f UTCTime_print; asn_struct_print_f UTCTime_print;
asn_constr_check_f UTCTime_constraint;
xer_type_encoder_f UTCTime_encode_xer;
/*********************** /***********************
* Some handy helpers. * * Some handy helpers. *
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
* Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved. * Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved.
* Redistribution and modifications are permitted subject to BSD license. * Redistribution and modifications are permitted subject to BSD license.
*/ */
#include <asn_internal.h>
#include <UTF8String.h> #include <UTF8String.h>
/* /*
...@@ -13,11 +14,13 @@ static ber_tlv_tag_t asn1_DEF_UTF8String_tags[] = { ...@@ -13,11 +14,13 @@ static ber_tlv_tag_t asn1_DEF_UTF8String_tags[] = {
}; };
asn1_TYPE_descriptor_t asn1_DEF_UTF8String = { asn1_TYPE_descriptor_t asn1_DEF_UTF8String = {
"UTF8String", "UTF8String",
OCTET_STRING_free,
UTF8String_print,
UTF8String_constraint, /* Check for invalid codes, etc. */ UTF8String_constraint, /* Check for invalid codes, etc. */
OCTET_STRING_decode_ber, /* Implemented in terms of OCTET STRING */ OCTET_STRING_decode_ber, /* Implemented in terms of OCTET STRING */
OCTET_STRING_encode_der, /* Implemented in terms of OCTET STRING */ OCTET_STRING_encode_der, /* Implemented in terms of OCTET STRING */
UTF8String_print, 0, /* Not implemented yet */
OCTET_STRING_free, OCTET_STRING_encode_xer_ascii, /* Already in UTF-8 format */
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn1_DEF_UTF8String_tags, asn1_DEF_UTF8String_tags,
sizeof(asn1_DEF_UTF8String_tags) sizeof(asn1_DEF_UTF8String_tags)
......
...@@ -12,8 +12,8 @@ typedef OCTET_STRING_t UTF8String_t; /* Implemented in terms of OCTET STRING */ ...@@ -12,8 +12,8 @@ typedef OCTET_STRING_t UTF8String_t; /* Implemented in terms of OCTET STRING */
extern asn1_TYPE_descriptor_t asn1_DEF_UTF8String; extern asn1_TYPE_descriptor_t asn1_DEF_UTF8String;
asn_constr_check_f UTF8String_constraint;
asn_struct_print_f UTF8String_print; asn_struct_print_f UTF8String_print;
asn_constr_check_f UTF8String_constraint;
/* Returns length of UTF-8 string in characters or -1 if error. */ /* Returns length of UTF-8 string in characters or -1 if error. */
ssize_t UTF8String_length(const UTF8String_t *st, const char *opt_type_name, ssize_t UTF8String_length(const UTF8String_t *st, const char *opt_type_name,
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
* Copyright (c) 2003 Lev Walkin <vlm@lionet.info>. All rights reserved. * Copyright (c) 2003 Lev Walkin <vlm@lionet.info>. All rights reserved.
* Redistribution and modifications are permitted subject to BSD license. * Redistribution and modifications are permitted subject to BSD license.
*/ */
#include <asn_internal.h>
#include <UniversalString.h> #include <UniversalString.h>
/* /*
...@@ -13,11 +14,13 @@ static ber_tlv_tag_t asn1_DEF_UniversalString_tags[] = { ...@@ -13,11 +14,13 @@ static ber_tlv_tag_t asn1_DEF_UniversalString_tags[] = {
}; };
asn1_TYPE_descriptor_t asn1_DEF_UniversalString = { asn1_TYPE_descriptor_t asn1_DEF_UniversalString = {
"UniversalString", "UniversalString",
OCTET_STRING_free,
UniversalString_print, /* Convert into UTF8 and print */
asn_generic_no_constraint, asn_generic_no_constraint,
OCTET_STRING_decode_ber, /* Implemented in terms of OCTET STRING */ OCTET_STRING_decode_ber, /* Implemented in terms of OCTET STRING */
OCTET_STRING_encode_der, /* Implemented in terms of OCTET STRING */ OCTET_STRING_encode_der, /* Implemented in terms of OCTET STRING */
UniversalString_print, /* Convert into UTF8 and print */ 0, /* Not implemented yet */
OCTET_STRING_free, UniversalString_encode_xer, /* Conver into UTF8 */
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn1_DEF_UniversalString_tags, asn1_DEF_UniversalString_tags,
sizeof(asn1_DEF_UniversalString_tags) sizeof(asn1_DEF_UniversalString_tags)
...@@ -31,29 +34,25 @@ asn1_TYPE_descriptor_t asn1_DEF_UniversalString = { ...@@ -31,29 +34,25 @@ asn1_TYPE_descriptor_t asn1_DEF_UniversalString = {
}; };
int static ssize_t
UniversalString_print(asn1_TYPE_descriptor_t *td, const void *sptr, int ilevel, UniversalString__dump(const UniversalString_t *st,
asn_app_consume_bytes_f *cb, void *app_key) { asn_app_consume_bytes_f *cb, void *app_key) {
const UniversalString_t *st = (const UniversalString_t *)sptr;
uint32_t *wchar;
uint32_t *wend;
char scratch[128]; /* Scratchpad buffer */ char scratch[128]; /* Scratchpad buffer */
char *p; char *p = scratch;
ssize_t wrote = 0;
(void)td; /* Unused argument */ uint8_t *ch;
(void)ilevel; /* Unused argument */ uint8_t *end;
if(!st || !st->buf) return cb("<absent>", 8, app_key); ch = st->buf;
end = (st->buf + st->size);
wchar = (uint32_t *)st->buf; for(end -= 3; ch < end; ch += 4) {
wend = (uint32_t *)(st->buf + st->size); uint32_t wc = (ch[0] << 24)
for(p = scratch; wchar < wend; wchar++) { | (ch[1] << 16)
uint32_t wc = (((uint8_t *)wchar)[0] << 24) | (ch[2] << 8)
| (((uint8_t *)wchar)[1] << 16) | ch[3]; /* 4 bytes */
| (((uint8_t *)wchar)[2] << 8)
| ((uint8_t *)wchar)[3]; /* 4 bytes */
if(sizeof(scratch) - (p - scratch) < 6) { if(sizeof(scratch) - (p - scratch) < 6) {
if(cb(scratch, p - scratch, app_key)) wrote += p - scratch;
if(cb(scratch, p - scratch, app_key) < 0)
return -1; return -1;
p = scratch; p = scratch;
} }
...@@ -87,5 +86,45 @@ UniversalString_print(asn1_TYPE_descriptor_t *td, const void *sptr, int ilevel, ...@@ -87,5 +86,45 @@ UniversalString_print(asn1_TYPE_descriptor_t *td, const void *sptr, int ilevel,
} }
} }
return cb(scratch, p - scratch, app_key); wrote += p - scratch;
if(cb(scratch, p - scratch, app_key) < 0)
return -1;
return wrote;
} }
asn_enc_rval_t
UniversalString_encode_xer(asn1_TYPE_descriptor_t *td, void *sptr,
int ilevel, enum xer_encoder_flags_e flags,
asn_app_consume_bytes_f *cb, void *app_key) {
const UniversalString_t *st = (const UniversalString_t *)sptr;
asn_enc_rval_t er;
(void)ilevel;
(void)flags;
if(!st || !st->buf)
_ASN_ENCODE_FAILED;
er.encoded = UniversalString__dump(st, cb, app_key);
if(er.encoded < 0) _ASN_ENCODE_FAILED;
return er;
}
int
UniversalString_print(asn1_TYPE_descriptor_t *td, const void *sptr, int ilevel,
asn_app_consume_bytes_f *cb, void *app_key) {
const UniversalString_t *st = (const UniversalString_t *)sptr;
(void)td; /* Unused argument */
(void)ilevel; /* Unused argument */
if(!st || !st->buf) return cb("<absent>", 8, app_key);
if(UniversalString__dump(st, cb, app_key) < 0)
return -1;
return 0;
}
/*- /*-
* Copyright (c) 2003 Lev Walkin <vlm@lionet.info>. All rights reserved. * Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved.
* Redistribution and modifications are permitted subject to BSD license. * Redistribution and modifications are permitted subject to BSD license.
*/ */
#ifndef _UniversalString_H_ #ifndef _UniversalString_H_
...@@ -13,5 +13,6 @@ typedef OCTET_STRING_t UniversalString_t; /* Implemented in terms of OCTET STRIN ...@@ -13,5 +13,6 @@ typedef OCTET_STRING_t UniversalString_t; /* Implemented in terms of OCTET STRIN
extern asn1_TYPE_descriptor_t asn1_DEF_UniversalString; extern asn1_TYPE_descriptor_t asn1_DEF_UniversalString;
asn_struct_print_f UniversalString_print; /* Human-readable output */ asn_struct_print_f UniversalString_print; /* Human-readable output */
xer_type_encoder_f UniversalString_encode_xer;
#endif /* _UniversalString_H_ */ #endif /* _UniversalString_H_ */
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
* Copyright (c) 2003 Lev Walkin <vlm@lionet.info>. All rights reserved. * Copyright (c) 2003 Lev Walkin <vlm@lionet.info>. All rights reserved.
* Redistribution and modifications are permitted subject to BSD license. * Redistribution and modifications are permitted subject to BSD license.
*/ */
#include <asn_internal.h>
#include <VideotexString.h> #include <VideotexString.h>
/* /*
...@@ -13,11 +14,13 @@ static ber_tlv_tag_t asn1_DEF_VideotexString_tags[] = { ...@@ -13,11 +14,13 @@ static ber_tlv_tag_t asn1_DEF_VideotexString_tags[] = {
}; };
asn1_TYPE_descriptor_t asn1_DEF_VideotexString = { asn1_TYPE_descriptor_t asn1_DEF_VideotexString = {
"VideotexString", "VideotexString",
OCTET_STRING_free,
OCTET_STRING_print, /* non-ascii string */
asn_generic_unknown_constraint, asn_generic_unknown_constraint,
OCTET_STRING_decode_ber, /* Implemented in terms of OCTET STRING */ OCTET_STRING_decode_ber, /* Implemented in terms of OCTET STRING */
OCTET_STRING_encode_der, /* Implemented in terms of OCTET STRING */ OCTET_STRING_encode_der, /* Implemented in terms of OCTET STRING */
OCTET_STRING_print, /* non-ascii string */ 0, /* Not implemented yet */
OCTET_STRING_free, OCTET_STRING_encode_xer, /* Implemented in terms of OCTET STRING */
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn1_DEF_VideotexString_tags, asn1_DEF_VideotexString_tags,
sizeof(asn1_DEF_VideotexString_tags) sizeof(asn1_DEF_VideotexString_tags)
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
* Copyright (c) 2003 Lev Walkin <vlm@lionet.info>. All rights reserved. * Copyright (c) 2003 Lev Walkin <vlm@lionet.info>. All rights reserved.
* Redistribution and modifications are permitted subject to BSD license. * Redistribution and modifications are permitted subject to BSD license.
*/ */
#include <asn_internal.h>
#include <VisibleString.h> #include <VisibleString.h>
/* /*
...@@ -13,11 +14,13 @@ static ber_tlv_tag_t asn1_DEF_VisibleString_tags[] = { ...@@ -13,11 +14,13 @@ static ber_tlv_tag_t asn1_DEF_VisibleString_tags[] = {
}; };
asn1_TYPE_descriptor_t asn1_DEF_VisibleString = { asn1_TYPE_descriptor_t asn1_DEF_VisibleString = {
"VisibleString", "VisibleString",
OCTET_STRING_free,
OCTET_STRING_print_ascii, /* ASCII subset */
VisibleString_constraint, VisibleString_constraint,
OCTET_STRING_decode_ber, /* Implemented in terms of OCTET STRING */ OCTET_STRING_decode_ber, /* Implemented in terms of OCTET STRING */
OCTET_STRING_encode_der, /* Implemented in terms of OCTET STRING */ OCTET_STRING_encode_der, /* Implemented in terms of OCTET STRING */
OCTET_STRING_print_ascii, /* ASCII subset */ 0, /* Not implemented yet */
OCTET_STRING_free, OCTET_STRING_encode_xer_ascii,/* Implemented in terms of OCTET STRING */
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn1_DEF_VisibleString_tags, asn1_DEF_VisibleString_tags,
sizeof(asn1_DEF_VisibleString_tags) sizeof(asn1_DEF_VisibleString_tags)
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
* Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved. * Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved.
* Redistribution and modifications are permitted subject to BSD license. * Redistribution and modifications are permitted subject to BSD license.
*/ */
#include <asn_internal.h>
#include <asn_types.h> /* for MALLOC/REALLOC/FREEMEM */ #include <asn_types.h> /* for MALLOC/REALLOC/FREEMEM */
#include <asn_SEQUENCE_OF.h> #include <asn_SEQUENCE_OF.h>
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
* Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved. * Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved.
* Redistribution and modifications are permitted subject to BSD license. * Redistribution and modifications are permitted subject to BSD license.
*/ */
#include <asn_internal.h>
#include <asn_types.h> /* for MALLOC/REALLOC/FREEMEM */ #include <asn_types.h> /* for MALLOC/REALLOC/FREEMEM */
#include <asn_SET_OF.h> #include <asn_SET_OF.h>
#include <errno.h> #include <errno.h>
......
/*-
* Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved.
* Redistribution and modifications are permitted subject to BSD license.
*/
/*
* Declarations internally useful for the ASN.1 support code.
*/
#ifndef _ASN_INTERNAL_H_
#define _ASN_INTERNAL_H_
#define ASN1C_ENVIRONMENT_VERSION 96 /* Compile-time version */
int get_asn1c_environment_version(void); /* Run-time version */
#include <asn_types.h>
#include <constr_TYPE.h>
#define CALLOC(nmemb, size) calloc(nmemb, size)
#define MALLOC(size) malloc(size)
#define REALLOC(oldptr, size) realloc(oldptr, size)
#define FREEMEM(ptr) free(ptr)
/*
* A macro for debugging the ASN.1 internals.
* You may enable or override it.
*/
#ifndef ASN_DEBUG /* If debugging code is not defined elsewhere... */
#if EMIT_ASN_DEBUG == 1 /* And it was asked to emit this code... */
#ifdef __GNUC__
#define ASN_DEBUG(fmt, args...) do { \
fprintf(stderr, fmt, ##args); \
fprintf(stderr, "\n"); \
} while(0)
#else /* !__GNUC__ */
extern void ASN_DEBUG_f(const char *fmt, ...);
#define ASN_DEBUG ASN_DEBUG_f
#endif /* __GNUC__ */
#else /* EMIT_ASN_DEBUG != 1 */
#ifdef __GNUC__
#define ASN_DEBUG(fmt, args...) ((void)0) /* Emit a no-op operator */
#else /* __GNUC__ */
static void ASN_DEBUG(const char *fmt, ...) { (void)fmt; };
#endif /* __GNUC__ */
#endif /* EMIT_ASN_DEBUG */
#endif /* ASN_DEBUG */
/*
* Invoke the application-supplied callback and fail, if something is wrong.
*/
#define __ASN_E_cbc(buf, size) (cb((buf), (size), app_key) == -1)
#define _ASN_E_CALLBACK(foo) do { \
if(foo) _ASN_ENCODE_FAILED; \
} while(0)
#define _ASN_CALLBACK(buf, size) \
_ASN_E_CALLBACK(__ASN_E_cbc(buf, size))
#define _ASN_CALLBACK2(buf1, size1, buf2, size2) \
_ASN_E_CALLBACK(__ASN_E_cbc(buf1, size1) || __ASN_E_cbc(buf2, size2))
#define _ASN_CALLBACK3(buf1, size1, buf2, size2, buf3, size3) \
_ASN_E_CALLBACK(__ASN_E_cbc(buf1, size1) \
|| __ASN_E_cbc(buf2, size2) \
|| __ASN_E_cbc(buf3, size3))
#define _i_ASN_TEXT_INDENT(nl, level) do { \
int __level = (level); \
int __nl = ((nl) != 0); \
int __i; \
if(__nl) _ASN_CALLBACK("\n", 1); \
for(__i = 0; __i < __level; __i++) \
_ASN_CALLBACK(" ", 4); \
er.encoded += __nl + 4 * __level; \
} while(0)
#endif /* _ASN_INTERNAL_H_ */
...@@ -43,11 +43,6 @@ ...@@ -43,11 +43,6 @@
#define offsetof(s, m) ((ptrdiff_t)&(((s *)0)->m) - (ptrdiff_t)((s *)0)) #define offsetof(s, m) ((ptrdiff_t)&(((s *)0)->m) - (ptrdiff_t)((s *)0))
#endif /* offsetof */ #endif /* offsetof */
#define CALLOC(nmemb, size) calloc(nmemb, size)
#define MALLOC(size) malloc(size)
#define REALLOC(oldptr, size) realloc(oldptr, size)
#define FREEMEM(ptr) free(ptr)
#ifndef MIN /* Suitable for comparing primitive types (integers) */ #ifndef MIN /* Suitable for comparing primitive types (integers) */
#if defined(__GNUC__) #if defined(__GNUC__)
#define MIN(a,b) ({ __typeof a _a = a; __typeof b _b = b; \ #define MIN(a,b) ({ __typeof a _a = a; __typeof b _b = b; \
...@@ -57,31 +52,6 @@ ...@@ -57,31 +52,6 @@
#endif /* __GNUC__ */ #endif /* __GNUC__ */
#endif /* MIN */ #endif /* MIN */
/*
* A macro for debugging the ASN.1 internals.
* You may enable or override it.
*/
#ifndef ASN_DEBUG /* If debugging code is not defined elsewhere... */
#if EMIT_ASN_DEBUG == 1 /* And it was asked to emit this code... */
#ifdef __GNUC__
#define ASN_DEBUG(fmt, args...) do { \
fprintf(stderr, fmt, ##args); \
fprintf(stderr, "\n"); \
} while(0)
#else /* !__GNUC__ */
extern void ASN_DEBUG_f(const char *fmt, ...);
#define ASN_DEBUG ASN_DEBUG_f
#endif /* __GNUC__ */
#else /* EMIT_ASN_DEBUG != 1 */
#ifdef __GNUC__
#define ASN_DEBUG(fmt, args...) ((void)0) /* Emit a no-op operator */
#else /* __GNUC__ */
static void ASN_DEBUG(const char *fmt, ...) { (void)fmt; };
#endif /* __GNUC__ */
#endif /* EMIT_ASN_DEBUG */
#endif /* ASN_DEBUG */
/* /*
* Generic type of an application-defined callback to return various * Generic type of an application-defined callback to return various
* types of data to the application. * types of data to the application.
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
* Copyright (c) 2003 Lev Walkin <vlm@lionet.info>. All rights reserved. * Copyright (c) 2003 Lev Walkin <vlm@lionet.info>. All rights reserved.
* Redistribution and modifications are permitted subject to BSD license. * Redistribution and modifications are permitted subject to BSD license.
*/ */
#include <asn_internal.h>
#include <constr_TYPE.h> #include <constr_TYPE.h>
#include <assert.h> #include <assert.h>
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
* Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved. * Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved.
* Redistribution and modifications are permitted subject to BSD license. * Redistribution and modifications are permitted subject to BSD license.
*/ */
#include <asn_internal.h>
#include <constr_TYPE.h> #include <constr_TYPE.h>
#include <ber_tlv_length.h> #include <ber_tlv_length.h>
#include <ber_tlv_tag.h> #include <ber_tlv_tag.h>
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
* Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved. * Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved.
* Redistribution and modifications are permitted subject to BSD license. * Redistribution and modifications are permitted subject to BSD license.
*/ */
#include <asn_internal.h>
#include <constr_TYPE.h> #include <constr_TYPE.h>
#include <ber_tlv_tag.h> #include <ber_tlv_tag.h>
#include <errno.h> #include <errno.h>
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
* Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved. * Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved.
* Redistribution and modifications are permitted subject to BSD license. * Redistribution and modifications are permitted subject to BSD license.
*/ */
#include <asn_internal.h>
#include <constr_CHOICE.h> #include <constr_CHOICE.h>
#include <assert.h> #include <assert.h>
...@@ -348,14 +349,14 @@ CHOICE_decode_ber(asn1_TYPE_descriptor_t *td, ...@@ -348,14 +349,14 @@ CHOICE_decode_ber(asn1_TYPE_descriptor_t *td,
RETURN(RC_OK); RETURN(RC_OK);
} }
der_enc_rval_t asn_enc_rval_t
CHOICE_encode_der(asn1_TYPE_descriptor_t *td, CHOICE_encode_der(asn1_TYPE_descriptor_t *td,
void *struct_ptr, void *struct_ptr,
int tag_mode, ber_tlv_tag_t tag, int tag_mode, ber_tlv_tag_t tag,
asn_app_consume_bytes_f *cb, void *app_key) { asn_app_consume_bytes_f *cb, void *app_key) {
asn1_CHOICE_specifics_t *specs = (asn1_CHOICE_specifics_t *)td->specifics; asn1_CHOICE_specifics_t *specs = (asn1_CHOICE_specifics_t *)td->specifics;
asn1_TYPE_member_t *elm; /* CHOICE element */ asn1_TYPE_member_t *elm; /* CHOICE element */
der_enc_rval_t erval; asn_enc_rval_t erval;
void *memb_ptr; void *memb_ptr;
size_t computed_size = 0; size_t computed_size = 0;
int present; int present;
...@@ -536,6 +537,57 @@ CHOICE_constraint(asn1_TYPE_descriptor_t *td, const void *sptr, ...@@ -536,6 +537,57 @@ CHOICE_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
} }
} }
asn_enc_rval_t
CHOICE_encode_xer(asn1_TYPE_descriptor_t *td, void *sptr,
int ilevel, enum xer_encoder_flags_e flags,
asn_app_consume_bytes_f *cb, void *app_key) {
asn1_CHOICE_specifics_t *specs=(asn1_CHOICE_specifics_t *)td->specifics;
asn_enc_rval_t er;
int present;
if(!sptr)
_ASN_ENCODE_FAILED;
/*
* Figure out which CHOICE element is encoded.
*/
present = _fetch_present_idx(sptr, specs->pres_offset,specs->pres_size);
if(present <= 0 || present > td->elements_count) {
_ASN_ENCODE_FAILED;
} else {
asn_enc_rval_t tmper;
asn1_TYPE_member_t *elm = &td->elements[present-1];
void *memb_ptr;
const char *mname = elm->name;
unsigned int mlen = strlen(mname);
if(elm->flags & ATF_POINTER) {
memb_ptr = *(void **)((char *)sptr + elm->memb_offset);
if(!memb_ptr) _ASN_ENCODE_FAILED;
} else {
memb_ptr = (void *)((char *)sptr + elm->memb_offset);
}
er.encoded = 0;
if(!(flags & XER_F_CANONICAL)) _i_ASN_TEXT_INDENT(1, ilevel);
_ASN_CALLBACK3("<", 1, mname, mlen, ">", 1);
tmper = elm->type->xer_encoder(elm->type, memb_ptr,
ilevel + 1, flags, cb, app_key);
if(tmper.encoded == -1) return tmper;
_ASN_CALLBACK3("</", 2, mname, mlen, ">", 1);
er.encoded += 5 + (2 * mlen) + tmper.encoded;
}
if(!(flags & XER_F_CANONICAL)) _i_ASN_TEXT_INDENT(1, ilevel - 1);
return er;
}
int int
CHOICE_print(asn1_TYPE_descriptor_t *td, const void *sptr, int ilevel, CHOICE_print(asn1_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) {
...@@ -550,7 +602,7 @@ CHOICE_print(asn1_TYPE_descriptor_t *td, const void *sptr, int ilevel, ...@@ -550,7 +602,7 @@ CHOICE_print(asn1_TYPE_descriptor_t *td, const void *sptr, int ilevel,
present = _fetch_present_idx(sptr, specs->pres_offset,specs->pres_size); present = _fetch_present_idx(sptr, specs->pres_offset,specs->pres_size);
/* /*
* Free that element. * Print that element.
*/ */
if(present > 0 && present <= td->elements_count) { if(present > 0 && present <= td->elements_count) {
asn1_TYPE_member_t *elm = &td->elements[present-1]; asn1_TYPE_member_t *elm = &td->elements[present-1];
......
...@@ -31,11 +31,12 @@ typedef struct asn1_CHOICE_specifics_s { ...@@ -31,11 +31,12 @@ typedef struct asn1_CHOICE_specifics_s {
/* /*
* A set specialized functions dealing with the CHOICE type. * A set specialized functions dealing with the CHOICE type.
*/ */
asn_struct_free_f CHOICE_free;
asn_struct_print_f CHOICE_print;
asn_constr_check_f CHOICE_constraint; asn_constr_check_f CHOICE_constraint;
ber_type_decoder_f CHOICE_decode_ber; ber_type_decoder_f CHOICE_decode_ber;
der_type_encoder_f CHOICE_encode_der; der_type_encoder_f CHOICE_encode_der;
xer_type_encoder_f CHOICE_encode_xer;
asn_outmost_tag_f CHOICE_outmost_tag; asn_outmost_tag_f CHOICE_outmost_tag;
asn_struct_print_f CHOICE_print;
asn_struct_free_f CHOICE_free;
#endif /* _CONSTR_CHOICE_H_ */ #endif /* _CONSTR_CHOICE_H_ */
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
* Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved. * Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved.
* Redistribution and modifications are permitted subject to BSD license. * Redistribution and modifications are permitted subject to BSD license.
*/ */
#include <asn_internal.h>
#include <constr_SEQUENCE.h> #include <constr_SEQUENCE.h>
#include <assert.h> #include <assert.h>
...@@ -490,12 +491,12 @@ SEQUENCE_decode_ber(asn1_TYPE_descriptor_t *td, ...@@ -490,12 +491,12 @@ SEQUENCE_decode_ber(asn1_TYPE_descriptor_t *td,
/* /*
* The DER encoder of the SEQUENCE type. * The DER encoder of the SEQUENCE type.
*/ */
der_enc_rval_t asn_enc_rval_t
SEQUENCE_encode_der(asn1_TYPE_descriptor_t *td, SEQUENCE_encode_der(asn1_TYPE_descriptor_t *td,
void *ptr, int tag_mode, ber_tlv_tag_t tag, void *ptr, int tag_mode, ber_tlv_tag_t tag,
asn_app_consume_bytes_f *cb, void *app_key) { asn_app_consume_bytes_f *cb, void *app_key) {
size_t computed_size = 0; size_t computed_size = 0;
der_enc_rval_t erval; asn_enc_rval_t erval;
ssize_t ret; ssize_t ret;
int edx; int edx;
...@@ -544,7 +545,7 @@ SEQUENCE_encode_der(asn1_TYPE_descriptor_t *td, ...@@ -544,7 +545,7 @@ SEQUENCE_encode_der(asn1_TYPE_descriptor_t *td,
*/ */
for(edx = 0; edx < td->elements_count; edx++) { for(edx = 0; edx < td->elements_count; edx++) {
asn1_TYPE_member_t *elm = &td->elements[edx]; asn1_TYPE_member_t *elm = &td->elements[edx];
der_enc_rval_t tmperval; asn_enc_rval_t tmperval;
void *memb_ptr; void *memb_ptr;
if(elm->flags & ATF_POINTER) { if(elm->flags & ATF_POINTER) {
...@@ -575,6 +576,50 @@ SEQUENCE_encode_der(asn1_TYPE_descriptor_t *td, ...@@ -575,6 +576,50 @@ SEQUENCE_encode_der(asn1_TYPE_descriptor_t *td,
return erval; return erval;
} }
asn_enc_rval_t
SEQUENCE_encode_xer(asn1_TYPE_descriptor_t *td, void *sptr,
int ilevel, enum xer_encoder_flags_e flags,
asn_app_consume_bytes_f *cb, void *app_key) {
asn_enc_rval_t er;
int xcan = (flags & XER_F_CANONICAL);
int edx;
if(!sptr)
_ASN_ENCODE_FAILED;
er.encoded = 0;
for(edx = 0; edx < td->elements_count; edx++) {
asn_enc_rval_t tmper;
asn1_TYPE_member_t *elm = &td->elements[edx];
void *memb_ptr;
const char *mname = elm->name;
unsigned int mlen = strlen(mname);
if(elm->flags & ATF_POINTER) {
memb_ptr = *(void **)((char *)sptr + elm->memb_offset);
if(!memb_ptr) continue; /* OPTIONAL element? */
} else {
memb_ptr = (void *)((char *)sptr + elm->memb_offset);
}
if(!xcan) _i_ASN_TEXT_INDENT(1, ilevel);
_ASN_CALLBACK3("<", 1, mname, mlen, ">", 1);
/* Print the member itself */
tmper = elm->type->xer_encoder(elm->type, memb_ptr,
ilevel + 1, flags, cb, app_key);
if(tmper.encoded == -1) return tmper;
_ASN_CALLBACK3("</", 2, mname, mlen, ">", 1);
er.encoded += 5 + (2 * mlen) + tmper.encoded;
}
if(!xcan) _i_ASN_TEXT_INDENT(1, ilevel - 1);
return er;
}
int int
SEQUENCE_print(asn1_TYPE_descriptor_t *td, const void *sptr, int ilevel, SEQUENCE_print(asn1_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) {
......
...@@ -31,10 +31,11 @@ typedef struct asn1_SEQUENCE_specifics_s { ...@@ -31,10 +31,11 @@ typedef struct asn1_SEQUENCE_specifics_s {
/* /*
* A set specialized functions dealing with the SEQUENCE type. * A set specialized functions dealing with the SEQUENCE type.
*/ */
asn_struct_free_f SEQUENCE_free;
asn_struct_print_f SEQUENCE_print;
asn_constr_check_f SEQUENCE_constraint; asn_constr_check_f SEQUENCE_constraint;
ber_type_decoder_f SEQUENCE_decode_ber; ber_type_decoder_f SEQUENCE_decode_ber;
der_type_encoder_f SEQUENCE_encode_der; der_type_encoder_f SEQUENCE_encode_der;
asn_struct_print_f SEQUENCE_print; xer_type_encoder_f SEQUENCE_encode_xer;
asn_struct_free_f SEQUENCE_free;
#endif /* _CONSTR_SEQUENCE_H_ */ #endif /* _CONSTR_SEQUENCE_H_ */
...@@ -2,13 +2,14 @@ ...@@ -2,13 +2,14 @@
* Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved. * Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved.
* Redistribution and modifications are permitted subject to BSD license. * Redistribution and modifications are permitted subject to BSD license.
*/ */
#include <asn_internal.h>
#include <constr_SEQUENCE_OF.h> #include <constr_SEQUENCE_OF.h>
#include <asn_SEQUENCE_OF.h> #include <asn_SEQUENCE_OF.h>
/* /*
* The DER encoder of the SEQUENCE OF type. * The DER encoder of the SEQUENCE OF type.
*/ */
der_enc_rval_t asn_enc_rval_t
SEQUENCE_OF_encode_der(asn1_TYPE_descriptor_t *td, void *ptr, SEQUENCE_OF_encode_der(asn1_TYPE_descriptor_t *td, void *ptr,
int tag_mode, ber_tlv_tag_t tag, int tag_mode, ber_tlv_tag_t tag,
asn_app_consume_bytes_f *cb, void *app_key) { asn_app_consume_bytes_f *cb, void *app_key) {
...@@ -16,7 +17,7 @@ SEQUENCE_OF_encode_der(asn1_TYPE_descriptor_t *td, void *ptr, ...@@ -16,7 +17,7 @@ SEQUENCE_OF_encode_der(asn1_TYPE_descriptor_t *td, void *ptr,
A_SEQUENCE_OF(void) *list; A_SEQUENCE_OF(void) *list;
size_t computed_size = 0; size_t computed_size = 0;
ssize_t encoding_size = 0; ssize_t encoding_size = 0;
der_enc_rval_t erval; asn_enc_rval_t erval;
int edx; int edx;
ASN_DEBUG("Estimating size of SEQUENCE OF %s", td->name); ASN_DEBUG("Estimating size of SEQUENCE OF %s", td->name);
...@@ -82,3 +83,50 @@ SEQUENCE_OF_encode_der(asn1_TYPE_descriptor_t *td, void *ptr, ...@@ -82,3 +83,50 @@ SEQUENCE_OF_encode_der(asn1_TYPE_descriptor_t *td, void *ptr,
return erval; return erval;
} }
asn_enc_rval_t
SEQUENCE_OF_encode_xer(asn1_TYPE_descriptor_t *td, void *sptr,
int ilevel, enum xer_encoder_flags_e flags,
asn_app_consume_bytes_f *cb, void *app_key) {
asn_enc_rval_t er;
asn1_SET_OF_specifics_t *specs = (asn1_SET_OF_specifics_t *)td->specifics;
asn1_TYPE_member_t *element = td->elements;
A_SEQUENCE_OF(void) *list;
const char *mname = specs->as_XMLValueList
? 0 : ((*element->name) ? element->name : element->type->name);
unsigned int mlen = mname ? strlen(mname) : 0;
int xcan = (flags & XER_F_CANONICAL);
int i;
if(!sptr) _ASN_ENCODE_FAILED;
er.encoded = 0;
(void *)list = sptr;
for(i = 0; i < list->count; i++) {
asn_enc_rval_t tmper;
void *memb_ptr = list->array[i];
if(!memb_ptr) continue;
if(mname) {
if(!xcan) _i_ASN_TEXT_INDENT(1, ilevel);
_ASN_CALLBACK3("<", 1, mname, mlen, ">", 1);
}
tmper = element->type->xer_encoder(element->type, memb_ptr,
ilevel + 1, flags, cb, app_key);
if(tmper.encoded == -1) return tmper;
if(mname) {
_ASN_CALLBACK3("</", 2, mname, mlen, ">", 1);
er.encoded += 5;
}
er.encoded += (2 * mlen) + tmper.encoded;
}
if(!xcan) _i_ASN_TEXT_INDENT(1, ilevel - 1);
return er;
}
...@@ -12,10 +12,11 @@ ...@@ -12,10 +12,11 @@
* A set specialized functions dealing with the SEQUENCE OF type. * A set specialized functions dealing with the SEQUENCE OF type.
* Implemented using SET OF. * Implemented using SET OF.
*/ */
#define SEQUENCE_OF_free SET_OF_free
#define SEQUENCE_OF_print SET_OF_print
#define SEQUENCE_OF_constraint SET_OF_constraint #define SEQUENCE_OF_constraint SET_OF_constraint
#define SEQUENCE_OF_decode_ber SET_OF_decode_ber #define SEQUENCE_OF_decode_ber SET_OF_decode_ber
der_type_encoder_f SEQUENCE_OF_encode_der; der_type_encoder_f SEQUENCE_OF_encode_der;
#define SEQUENCE_OF_print SET_OF_print xer_type_encoder_f SEQUENCE_OF_encode_xer;
#define SEQUENCE_OF_free SET_OF_free
#endif /* _CONSTR_SET_OF_H_ */ #endif /* _CONSTR_SET_OF_H_ */
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
* Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved. * Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved.
* Redistribution and modifications are permitted subject to BSD license. * Redistribution and modifications are permitted subject to BSD license.
*/ */
#include <asn_internal.h>
#include <constr_SET.h> #include <constr_SET.h>
#include <assert.h> /* for assert() */ #include <assert.h> /* for assert() */
...@@ -430,13 +431,13 @@ SET_decode_ber(asn1_TYPE_descriptor_t *td, ...@@ -430,13 +431,13 @@ SET_decode_ber(asn1_TYPE_descriptor_t *td,
/* /*
* The DER encoder of the SET type. * The DER encoder of the SET type.
*/ */
der_enc_rval_t asn_enc_rval_t
SET_encode_der(asn1_TYPE_descriptor_t *td, SET_encode_der(asn1_TYPE_descriptor_t *td,
void *ptr, int tag_mode, ber_tlv_tag_t tag, void *ptr, int tag_mode, ber_tlv_tag_t tag,
asn_app_consume_bytes_f *cb, void *app_key) { asn_app_consume_bytes_f *cb, void *app_key) {
asn1_SET_specifics_t *specs = (asn1_SET_specifics_t *)td->specifics; asn1_SET_specifics_t *specs = (asn1_SET_specifics_t *)td->specifics;
size_t computed_size = 0; size_t computed_size = 0;
der_enc_rval_t my_erval; asn_enc_rval_t my_erval;
int t2m_build_own = (specs->tag2el_count != td->elements_count); int t2m_build_own = (specs->tag2el_count != td->elements_count);
asn1_TYPE_tag2member_t *t2m; asn1_TYPE_tag2member_t *t2m;
int t2m_count; int t2m_count;
...@@ -469,7 +470,7 @@ SET_encode_der(asn1_TYPE_descriptor_t *td, ...@@ -469,7 +470,7 @@ SET_encode_der(asn1_TYPE_descriptor_t *td,
*/ */
for(edx = 0; edx < td->elements_count; edx++) { for(edx = 0; edx < td->elements_count; edx++) {
asn1_TYPE_member_t *elm = &td->elements[edx]; asn1_TYPE_member_t *elm = &td->elements[edx];
der_enc_rval_t erval; asn_enc_rval_t erval;
void *memb_ptr; void *memb_ptr;
/* /*
...@@ -545,7 +546,7 @@ SET_encode_der(asn1_TYPE_descriptor_t *td, ...@@ -545,7 +546,7 @@ SET_encode_der(asn1_TYPE_descriptor_t *td,
*/ */
for(edx = 0; edx < td->elements_count; edx++) { for(edx = 0; edx < td->elements_count; edx++) {
asn1_TYPE_member_t *elm; asn1_TYPE_member_t *elm;
der_enc_rval_t erval; asn_enc_rval_t erval;
void *memb_ptr; void *memb_ptr;
/* Encode according to the tag order */ /* Encode according to the tag order */
...@@ -577,6 +578,52 @@ SET_encode_der(asn1_TYPE_descriptor_t *td, ...@@ -577,6 +578,52 @@ SET_encode_der(asn1_TYPE_descriptor_t *td,
return my_erval; return my_erval;
} }
asn_enc_rval_t
SET_encode_xer(asn1_TYPE_descriptor_t *td, void *sptr,
int ilevel, enum xer_encoder_flags_e flags,
asn_app_consume_bytes_f *cb, void *app_key) {
asn_enc_rval_t er;
int xcan = (flags & XER_F_CANONICAL);
int edx;
if(!sptr)
_ASN_ENCODE_FAILED;
er.encoded = 0;
for(edx = 0; edx < td->elements_count; edx++) {
asn_enc_rval_t tmper;
asn1_TYPE_member_t *elm = &td->elements[edx];
void *memb_ptr;
const char *mname = elm->name;
unsigned int mlen = strlen(elm->name);
if(elm->flags & ATF_POINTER) {
memb_ptr = *(void **)((char *)sptr + elm->memb_offset);
if(!memb_ptr) continue; /* OPTIONAL element? */
} else {
memb_ptr = (void *)((char *)sptr + elm->memb_offset);
}
if(!xcan)
_i_ASN_TEXT_INDENT(1, ilevel);
_ASN_CALLBACK3("<", 1, mname, mlen, ">", 1);
/* Print the member itself */
tmper = elm->type->xer_encoder(elm->type, memb_ptr,
ilevel + 1, flags, cb, app_key);
if(tmper.encoded == -1) return tmper;
_ASN_CALLBACK3("</", 2, mname, mlen, ">", 1);
er.encoded += 5 + (2 * mlen) + tmper.encoded;
}
if(!xcan) _i_ASN_TEXT_INDENT(1, ilevel - 1);
return er;
}
int int
SET_print(asn1_TYPE_descriptor_t *td, const void *sptr, int ilevel, SET_print(asn1_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) {
......
...@@ -32,11 +32,12 @@ typedef struct asn1_SET_specifics_s { ...@@ -32,11 +32,12 @@ typedef struct asn1_SET_specifics_s {
/* /*
* A set specialized functions dealing with the SET type. * A set specialized functions dealing with the SET type.
*/ */
asn_struct_free_f SET_free;
asn_struct_print_f SET_print;
asn_constr_check_f SET_constraint; asn_constr_check_f SET_constraint;
ber_type_decoder_f SET_decode_ber; ber_type_decoder_f SET_decode_ber;
der_type_encoder_f SET_encode_der; der_type_encoder_f SET_encode_der;
asn_struct_print_f SET_print; xer_type_encoder_f SET_encode_xer;
asn_struct_free_f SET_free;
/*********************** /***********************
* Some handy helpers. * * Some handy helpers. *
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
* Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved. * Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved.
* Redistribution and modifications are permitted subject to BSD license. * Redistribution and modifications are permitted subject to BSD license.
*/ */
#include <asn_internal.h>
#include <constr_SET_OF.h> #include <constr_SET_OF.h>
#include <asn_SET_OF.h> #include <asn_SET_OF.h>
...@@ -304,7 +305,7 @@ static int _el_buf_cmp(const void *ap, const void *bp) { ...@@ -304,7 +305,7 @@ static int _el_buf_cmp(const void *ap, const void *bp) {
/* /*
* The DER encoder of the SET OF type. * The DER encoder of the SET OF type.
*/ */
der_enc_rval_t asn_enc_rval_t
SET_OF_encode_der(asn1_TYPE_descriptor_t *td, void *ptr, SET_OF_encode_der(asn1_TYPE_descriptor_t *td, void *ptr,
int tag_mode, ber_tlv_tag_t tag, int tag_mode, ber_tlv_tag_t tag,
asn_app_consume_bytes_f *cb, void *app_key) { asn_app_consume_bytes_f *cb, void *app_key) {
...@@ -316,7 +317,7 @@ SET_OF_encode_der(asn1_TYPE_descriptor_t *td, void *ptr, ...@@ -316,7 +317,7 @@ SET_OF_encode_der(asn1_TYPE_descriptor_t *td, void *ptr,
ssize_t encoding_size = 0; ssize_t encoding_size = 0;
struct _el_buffer *encoded_els; struct _el_buffer *encoded_els;
size_t max_encoded_len = 1; size_t max_encoded_len = 1;
der_enc_rval_t erval; asn_enc_rval_t erval;
int ret; int ret;
int edx; int edx;
...@@ -444,6 +445,53 @@ SET_OF_encode_der(asn1_TYPE_descriptor_t *td, void *ptr, ...@@ -444,6 +445,53 @@ SET_OF_encode_der(asn1_TYPE_descriptor_t *td, void *ptr,
return erval; return erval;
} }
asn_enc_rval_t
SET_OF_encode_xer(asn1_TYPE_descriptor_t *td, void *sptr,
int ilevel, enum xer_encoder_flags_e flags,
asn_app_consume_bytes_f *cb, void *app_key) {
asn_enc_rval_t er;
asn1_SET_OF_specifics_t *specs=(asn1_SET_OF_specifics_t *)td->specifics;
asn1_TYPE_member_t *element = td->elements;
A_SET_OF(void) *list;
const char *mname = specs->as_XMLValueList
? 0 : ((*element->name) ? element->name : element->type->name);
size_t mlen = mname ? strlen(mname) : 0;
int xcan = (flags & XER_F_CANONICAL);
int i;
if(!sptr) _ASN_ENCODE_FAILED;
er.encoded = 0;
(void *)list = sptr;
for(i = 0; i < list->count; i++) {
asn_enc_rval_t tmper;
void *memb_ptr = list->array[i];
if(!memb_ptr) continue;
if(mname) {
if(!xcan) _i_ASN_TEXT_INDENT(1, ilevel);
_ASN_CALLBACK3("<", 1, mname, mlen, ">", 1);
}
tmper = element->type->xer_encoder(element->type, memb_ptr,
ilevel + 1, flags, cb, app_key);
if(tmper.encoded == -1) return tmper;
if(mname) {
_ASN_CALLBACK3("</", 2, mname, mlen, ">", 1);
er.encoded += 5;
}
er.encoded += (2 * mlen) + tmper.encoded;
}
if(!xcan) _i_ASN_TEXT_INDENT(1, ilevel - 1);
return er;
}
int int
SET_OF_print(asn1_TYPE_descriptor_t *td, const void *sptr, int ilevel, SET_OF_print(asn1_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) {
......
...@@ -13,15 +13,19 @@ typedef struct asn1_SET_OF_specifics_s { ...@@ -13,15 +13,19 @@ typedef struct asn1_SET_OF_specifics_s {
*/ */
int struct_size; /* Size of the target structure. */ int struct_size; /* Size of the target structure. */
int ctx_offset; /* Offset of the ber_dec_ctx_t member */ int ctx_offset; /* Offset of the ber_dec_ctx_t member */
/* XER-specific stuff */
int as_XMLValueList; /* The member type must be encoded like this */
} asn1_SET_OF_specifics_t; } asn1_SET_OF_specifics_t;
/* /*
* A set specialized functions dealing with the SET OF type. * A set specialized functions dealing with the SET OF type.
*/ */
asn_struct_free_f SET_OF_free;
asn_struct_print_f SET_OF_print;
asn_constr_check_f SET_OF_constraint; asn_constr_check_f SET_OF_constraint;
ber_type_decoder_f SET_OF_decode_ber; ber_type_decoder_f SET_OF_decode_ber;
der_type_encoder_f SET_OF_encode_der; der_type_encoder_f SET_OF_encode_der;
asn_struct_print_f SET_OF_print; xer_type_encoder_f SET_OF_encode_xer;
asn_struct_free_f SET_OF_free;
#endif /* _CONSTR_SET_OF_H_ */ #endif /* _CONSTR_SET_OF_H_ */
...@@ -2,9 +2,15 @@ ...@@ -2,9 +2,15 @@
* Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved. * Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved.
* Redistribution and modifications are permitted subject to BSD license. * Redistribution and modifications are permitted subject to BSD license.
*/ */
#include <asn_internal.h>
#include <constr_TYPE.h> #include <constr_TYPE.h>
#include <errno.h> #include <errno.h>
/*
* Version of the ASN.1 infrastructure shipped with compiler.
*/
int get_asn1c_environment_version() { return ASN1C_ENVIRONMENT_VERSION; }
static asn_app_consume_bytes_f _print2fp; static asn_app_consume_bytes_f _print2fp;
/* /*
......
...@@ -2,19 +2,53 @@ ...@@ -2,19 +2,53 @@
* Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved. * Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved.
* Redistribution and modifications are permitted subject to BSD license. * Redistribution and modifications are permitted subject to BSD license.
*/ */
#ifndef _CONSTR_TYPE_H_ /*
#define _CONSTR_TYPE_H_ * This file contains the declaration structure called "ASN.1 Type Definition",
* which holds all information necessary for encoding and decoding routines.
* This structure even contains pointer to these encoding and decoding routines
* for each defined ASN.1 type.
*/
#ifndef _CONSTR_TYPE_H
#define _CONSTR_TYPE_H
#include <asn_types.h> /* System-dependent types */ #include <asn_types.h> /* System-dependent types */
struct asn1_TYPE_descriptor_s; /* Forward declaration */
struct asn1_TYPE_member_s; /* Forward declaration */
/*
* Type of the return value of the encoding functions (der_encode, xer_encode).
*/
typedef struct asn_enc_rval_s {
/*
* Number of bytes encoded.
* -1 indicates failure to encode the structure.
* In this case, the members below this one are meaningful.
*/
ssize_t encoded;
/*
* Members meaningful when (encoded == -1), for post mortem analysis.
*/
/* Type which cannot be encoded */
struct asn1_TYPE_descriptor_s *failed_type;
/* Pointer to the structure of that type */
void *structure_ptr;
} asn_enc_rval_t;
#define _ASN_ENCODE_FAILED do { \
asn_enc_rval_t __er = { -1, td, sptr }; \
return __er; \
} while(0)
#include <ber_tlv_length.h> #include <ber_tlv_length.h>
#include <ber_tlv_tag.h> #include <ber_tlv_tag.h>
#include <ber_decoder.h> #include <ber_decoder.h>
#include <der_encoder.h> #include <der_encoder.h>
#include <xer_encoder.h>
#include <constraints.h> #include <constraints.h>
struct asn1_TYPE_descriptor_s; /* Forward declaration */
struct asn1_TYPE_member_s; /* Forward declaration */
/* /*
* Free the structure according to its specification. * Free the structure according to its specification.
* If (free_contents_only) is set, the wrapper structure itself (struct_ptr) * If (free_contents_only) is set, the wrapper structure itself (struct_ptr)
...@@ -58,11 +92,13 @@ typedef struct asn1_TYPE_descriptor_s { ...@@ -58,11 +92,13 @@ typedef struct asn1_TYPE_descriptor_s {
* Generalized functions for dealing with the specific type. * Generalized functions for dealing with the specific type.
* May be directly invoked by applications. * May be directly invoked by applications.
*/ */
asn_struct_free_f *free_struct; /* Free the structure */
asn_struct_print_f *print_struct; /* Human readable output */
asn_constr_check_f *check_constraints; /* Constraints validator */ asn_constr_check_f *check_constraints; /* Constraints validator */
ber_type_decoder_f *ber_decoder; /* Free-form BER decoder */ ber_type_decoder_f *ber_decoder; /* Free-form BER decoder */
der_type_encoder_f *der_encoder; /* Canonical DER encoder */ der_type_encoder_f *der_encoder; /* Canonical DER encoder */
asn_struct_print_f *print_struct; /* Human readable output */ int (*xer_decoder);/* PLACEHOLDER */ /* Free-form XER decoder */
asn_struct_free_f *free_struct; /* Free the structure */ xer_type_encoder_f *xer_encoder; /* [Canonical] XER encoder */
/* /*
* Functions used internally. Should not be used by applications. * Functions used internally. Should not be used by applications.
...@@ -129,6 +165,7 @@ typedef struct asn1_TYPE_tag2member_s { ...@@ -129,6 +165,7 @@ typedef struct asn1_TYPE_tag2member_s {
* RETURN VALUES: * RETURN VALUES:
* 0: The structure is printed. * 0: The structure is printed.
* -1: Problem dumping the structure. * -1: Problem dumping the structure.
* (See also xer_fprint() in xer_encoder.h)
*/ */
int asn_fprint(FILE *stream, /* Destination stream descriptor */ int asn_fprint(FILE *stream, /* Destination stream descriptor */
asn1_TYPE_descriptor_t *td, /* ASN.1 type descriptor */ asn1_TYPE_descriptor_t *td, /* ASN.1 type descriptor */
......
#include <asn_internal.h>
#include <constraints.h> #include <constraints.h>
#include <constr_TYPE.h> #include <constr_TYPE.h>
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
* Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved. * Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved.
* Redistribution and modifications are permitted subject to BSD license. * Redistribution and modifications are permitted subject to BSD license.
*/ */
#include <asn_internal.h>
#include <constr_TYPE.h> #include <constr_TYPE.h>
#include <assert.h> #include <assert.h>
#include <errno.h> #include <errno.h>
...@@ -12,7 +13,7 @@ static ssize_t der_write_TL(ber_tlv_tag_t tag, ber_tlv_len_t len, ...@@ -12,7 +13,7 @@ static ssize_t der_write_TL(ber_tlv_tag_t tag, ber_tlv_len_t len,
/* /*
* The DER encoder of any type. * The DER encoder of any type.
*/ */
der_enc_rval_t asn_enc_rval_t
der_encode(asn1_TYPE_descriptor_t *type_descriptor, void *struct_ptr, der_encode(asn1_TYPE_descriptor_t *type_descriptor, void *struct_ptr,
asn_app_consume_bytes_f *consume_bytes, void *app_key) { asn_app_consume_bytes_f *consume_bytes, void *app_key) {
......
...@@ -9,33 +9,10 @@ ...@@ -9,33 +9,10 @@
struct asn1_TYPE_descriptor_s; /* Forward declaration */ struct asn1_TYPE_descriptor_s; /* Forward declaration */
/*
* Type of the return value of the der_encode function.
*/
typedef struct der_enc_rval_s {
/*
* Number of bytes encoded.
* -1 indicates failure to encode the structure.
* In this case, the members below this one are meaningful.
*/
ssize_t encoded;
/*
* Members meaningful when (encoded == -1), for post-mortem analysis.
*/
/* Type which cannot be encoded */
struct asn1_TYPE_descriptor_s *failed_type;
/* Pointer to the structure of that type */
void *structure_ptr;
} der_enc_rval_t;
/* /*
* The DER encoder of any type. May be invoked by the application. * The DER encoder of any type. May be invoked by the application.
*/ */
der_enc_rval_t der_encode(struct asn1_TYPE_descriptor_s *type_descriptor, asn_enc_rval_t der_encode(struct asn1_TYPE_descriptor_s *type_descriptor,
void *struct_ptr, /* Structure to be encoded */ void *struct_ptr, /* Structure to be encoded */
asn_app_consume_bytes_f *consume_bytes_cb, asn_app_consume_bytes_f *consume_bytes_cb,
void *app_key /* Arbitrary callback argument */ void *app_key /* Arbitrary callback argument */
...@@ -44,7 +21,7 @@ der_enc_rval_t der_encode(struct asn1_TYPE_descriptor_s *type_descriptor, ...@@ -44,7 +21,7 @@ der_enc_rval_t der_encode(struct asn1_TYPE_descriptor_s *type_descriptor,
/* /*
* Type of the generic DER encoder. * Type of the generic DER encoder.
*/ */
typedef der_enc_rval_t (der_type_encoder_f)( typedef asn_enc_rval_t (der_type_encoder_f)(
struct asn1_TYPE_descriptor_s *type_descriptor, struct asn1_TYPE_descriptor_s *type_descriptor,
void *struct_ptr, /* Structure to be encoded */ void *struct_ptr, /* Structure to be encoded */
int tag_mode, /* {-1,0,1}: IMPLICIT, no, EXPLICIT */ int tag_mode, /* {-1,0,1}: IMPLICIT, no, EXPLICIT */
......
...@@ -44,6 +44,7 @@ constr_SET_OF.h constr_SET_OF.c asn_SET_OF.h ...@@ -44,6 +44,7 @@ constr_SET_OF.h constr_SET_OF.c asn_SET_OF.h
COMMON-FILES: # This is a special section COMMON-FILES: # This is a special section
asn_types.h asn_types.h
asn_internal.h
OCTET_STRING.h OCTET_STRING.c # This one is used too widely OCTET_STRING.h OCTET_STRING.c # This one is used too widely
ber_decoder.h ber_decoder.c ber_decoder.h ber_decoder.c
ber_tlv_length.h ber_tlv_length.c ber_tlv_length.h ber_tlv_length.c
...@@ -51,3 +52,4 @@ ber_tlv_tag.h ber_tlv_tag.c ...@@ -51,3 +52,4 @@ ber_tlv_tag.h ber_tlv_tag.c
constr_TYPE.h constr_TYPE.c constr_TYPE.h constr_TYPE.c
constraints.h constraints.c constraints.h constraints.c
der_encoder.h der_encoder.c der_encoder.h der_encoder.c
xer_encoder.h xer_encoder.c
...@@ -97,9 +97,9 @@ main(int ac, char **av) { ...@@ -97,9 +97,9 @@ main(int ac, char **av) {
* Dummy function. * Dummy function.
*/ */
der_enc_rval_t asn_enc_rval_t
OCTET_STRING_encode_der(asn1_TYPE_descriptor_t *td, void *ptr, int tag_mode, ber_tlv_tag_t tag, asn_app_consume_bytes_f *cb, void *app_key) { OCTET_STRING_encode_der(asn1_TYPE_descriptor_t *td, void *ptr, int tag_mode, ber_tlv_tag_t tag, asn_app_consume_bytes_f *cb, void *app_key) {
der_enc_rval_t erval; asn_enc_rval_t erval;
(void)td; (void)td;
(void)ptr; (void)ptr;
...@@ -110,3 +110,17 @@ OCTET_STRING_encode_der(asn1_TYPE_descriptor_t *td, void *ptr, int tag_mode, ber ...@@ -110,3 +110,17 @@ OCTET_STRING_encode_der(asn1_TYPE_descriptor_t *td, void *ptr, int tag_mode, ber
return erval; return erval;
} }
asn_enc_rval_t
OCTET_STRING_encode_xer_ascii(asn1_TYPE_descriptor_t *td, void *ptr, int ilevel, enum xer_encoder_flags_e flags, asn_app_consume_bytes_f *cb, void *app_key) {
asn_enc_rval_t erval;
(void)td;
(void)ptr;
(void)ilevel;
(void)flags;
(void)cb;
(void)app_key;
return erval;
}
...@@ -64,9 +64,9 @@ main(int ac, char **av) { ...@@ -64,9 +64,9 @@ main(int ac, char **av) {
* Dummy function. * Dummy function.
*/ */
der_enc_rval_t asn_enc_rval_t
OCTET_STRING_encode_der(asn1_TYPE_descriptor_t *td, void *ptr, int tag_mode, ber_tlv_tag_t tag, asn_app_consume_bytes_f *cb, void *app_key) { OCTET_STRING_encode_der(asn1_TYPE_descriptor_t *td, void *ptr, int tag_mode, ber_tlv_tag_t tag, asn_app_consume_bytes_f *cb, void *app_key) {
der_enc_rval_t erval; asn_enc_rval_t erval;
(void)td; (void)td;
(void)ptr; (void)ptr;
...@@ -77,3 +77,17 @@ OCTET_STRING_encode_der(asn1_TYPE_descriptor_t *td, void *ptr, int tag_mode, ber ...@@ -77,3 +77,17 @@ OCTET_STRING_encode_der(asn1_TYPE_descriptor_t *td, void *ptr, int tag_mode, ber
return erval; return erval;
} }
asn_enc_rval_t
OCTET_STRING_encode_xer_ascii(asn1_TYPE_descriptor_t *td, void *ptr, int ilevel, enum xer_encoder_flags_e flags, asn_app_consume_bytes_f *cb, void *app_key) {
asn_enc_rval_t erval;
(void)td;
(void)ptr;
(void)ilevel;
(void)flags;
(void)cb;
(void)app_key;
return erval;
}
...@@ -36,7 +36,7 @@ static void ...@@ -36,7 +36,7 @@ static void
check(int size) { check(int size) {
OCTET_STRING_t *os; OCTET_STRING_t *os;
OCTET_STRING_t *nos = 0; OCTET_STRING_t *nos = 0;
der_enc_rval_t erval; asn_enc_rval_t erval;
ber_dec_rval_t rval; ber_dec_rval_t rval;
int i; int i;
......
/*-
* Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved.
* Redistribution and modifications are permitted subject to BSD license.
*/
#include <asn_internal.h>
#include <constr_TYPE.h>
#include <stdio.h>
#include <assert.h>
#include <errno.h>
/*
* The XER encoder of any type. May be invoked by the application.
*/
asn_enc_rval_t
xer_encode(asn1_TYPE_descriptor_t *td, void *sptr,
enum xer_encoder_flags_e xer_flags,
asn_app_consume_bytes_f *cb, void *app_key) {
asn_enc_rval_t er, tmper;
const char *mname;
size_t mlen;
int xcan = (xer_flags & XER_F_CANONICAL) ? 1 : 2;
if(!td || !sptr) {
er.encoded = -1;
er.failed_type = td;
er.structure_ptr = sptr;
return er;
}
mname = td->name;
mlen = strlen(mname);
_ASN_CALLBACK3("<", 1, mname, mlen, ">", 1);
tmper = td->xer_encoder(td, sptr, 1, xer_flags, cb, app_key);
if(tmper.encoded == -1) return tmper;
_ASN_CALLBACK3("</", xcan, mname, mlen, ">\n",xcan);
er.encoded = 2 + (2 * xcan) + (2 * mlen) + tmper.encoded;
return er;
}
static int _print2fp(const void *buffer, size_t size, void *app_key);
int
xer_fprint(FILE *stream, asn1_TYPE_descriptor_t *td, void *sptr) {
asn_enc_rval_t er;
if(!stream) stream = stdout;
if(!td || !sptr)
return -1;
er = xer_encode(td, sptr, XER_F_BASIC, _print2fp, stream);
if(er.encoded == -1)
return -1;
return fflush(stream);
}
static int
_print2fp(const void *buffer, size_t size, void *app_key) {
FILE *stream = (FILE *)app_key;
if(fwrite(buffer, 1, size, stream) != size)
return -1;
return 0;
}
/*-
* Copyright (c) 2004 Lev Walkin <vlm@lionet.info>. All rights reserved.
* Redistribution and modifications are permitted subject to BSD license.
*/
#ifndef _XER_ENCODER_H_
#define _XER_ENCODER_H_
#include <constr_TYPE.h>
struct asn1_TYPE_descriptor_s; /* Forward declaration */
/* Flags used by the xer_encode() and (*xer_type_encoder_f), defined below */
enum xer_encoder_flags_e {
/* Mode of encoding */
XER_F_BASIC = 0x01, /* BASIC-XER (pretty-printing) */
XER_F_CANONICAL = 0x02, /* Canonical XER (strict rules, unreadable) */
};
/*
* The XER encoder of any type. May be invoked by the application.
*/
asn_enc_rval_t xer_encode(struct asn1_TYPE_descriptor_s *type_descriptor,
void *struct_ptr, /* Structure to be encoded */
enum xer_encoder_flags_e xer_flags,
asn_app_consume_bytes_f *consume_bytes_cb,
void *app_key /* Arbitrary callback argument */
);
/*
* The variant of the above function which dumps the BASIC-XER (XER_F_BASIC)
* output into the chosen file pointer.
* RETURN VALUES:
* 0: The structure is printed.
* -1: Problem printing the structure.
* WARNING: No sensible errno value is returned.
*/
int xer_fprint(FILE *stream, struct asn1_TYPE_descriptor_s *td, void *sptr);
/*
* Type of the generic XER encoder.
*/
typedef asn_enc_rval_t (xer_type_encoder_f)(
struct asn1_TYPE_descriptor_s *type_descriptor,
void *struct_ptr, /* Structure to be encoded */
int ilevel, /* Level of indentation */
enum xer_encoder_flags_e xer_flags,
asn_app_consume_bytes_f *consume_bytes_cb, /* Callback */
void *app_key /* Arbitrary callback argument */
);
#endif /* _XER_ENCODER_H_ */
...@@ -108,11 +108,13 @@ static asn1_SEQUENCE_specifics_t asn1_DEF_toBeSigned_specs = { ...@@ -108,11 +108,13 @@ static asn1_SEQUENCE_specifics_t asn1_DEF_toBeSigned_specs = {
static /* Use -fall-defs-global to expose */ static /* Use -fall-defs-global to expose */
asn1_TYPE_descriptor_t asn1_DEF_toBeSigned = { asn1_TYPE_descriptor_t asn1_DEF_toBeSigned = {
"toBeSigned", "toBeSigned",
SEQUENCE_free,
SEQUENCE_print,
SEQUENCE_constraint, SEQUENCE_constraint,
SEQUENCE_decode_ber, SEQUENCE_decode_ber,
SEQUENCE_encode_der, SEQUENCE_encode_der,
SEQUENCE_print, 0, /* Not implemented yet */
SEQUENCE_free, SEQUENCE_encode_xer,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn1_DEF_toBeSigned_tags, asn1_DEF_toBeSigned_tags,
sizeof(asn1_DEF_toBeSigned_tags) sizeof(asn1_DEF_toBeSigned_tags)
...@@ -167,11 +169,13 @@ static asn1_SEQUENCE_specifics_t asn1_DEF_Certificate_specs = { ...@@ -167,11 +169,13 @@ static asn1_SEQUENCE_specifics_t asn1_DEF_Certificate_specs = {
}; };
asn1_TYPE_descriptor_t asn1_DEF_Certificate = { asn1_TYPE_descriptor_t asn1_DEF_Certificate = {
"Certificate", "Certificate",
SEQUENCE_free,
SEQUENCE_print,
SEQUENCE_constraint, SEQUENCE_constraint,
SEQUENCE_decode_ber, SEQUENCE_decode_ber,
SEQUENCE_encode_der, SEQUENCE_encode_der,
SEQUENCE_print, 0, /* Not implemented yet */
SEQUENCE_free, SEQUENCE_encode_xer,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn1_DEF_Certificate_tags, asn1_DEF_Certificate_tags,
sizeof(asn1_DEF_Certificate_tags) sizeof(asn1_DEF_Certificate_tags)
...@@ -223,14 +227,17 @@ static ber_tlv_tag_t asn1_DEF_Name_tags[] = { ...@@ -223,14 +227,17 @@ static ber_tlv_tag_t asn1_DEF_Name_tags[] = {
static asn1_SET_OF_specifics_t asn1_DEF_Name_specs = { static asn1_SET_OF_specifics_t asn1_DEF_Name_specs = {
sizeof(struct Name), sizeof(struct Name),
offsetof(struct Name, _ber_dec_ctx), offsetof(struct Name, _ber_dec_ctx),
0, /* XER encoding is XMLDelimitedItemList */
}; };
asn1_TYPE_descriptor_t asn1_DEF_Name = { asn1_TYPE_descriptor_t asn1_DEF_Name = {
"Name", "Name",
SEQUENCE_OF_free,
SEQUENCE_OF_print,
SEQUENCE_OF_constraint, SEQUENCE_OF_constraint,
SEQUENCE_OF_decode_ber, SEQUENCE_OF_decode_ber,
SEQUENCE_OF_encode_der, SEQUENCE_OF_encode_der,
SEQUENCE_OF_print, 0, /* Not implemented yet */
SEQUENCE_OF_free, SEQUENCE_OF_encode_xer,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn1_DEF_Name_tags, asn1_DEF_Name_tags,
sizeof(asn1_DEF_Name_tags) sizeof(asn1_DEF_Name_tags)
...@@ -337,14 +344,17 @@ static ber_tlv_tag_t asn1_DEF_RelativeDistinguishedName_tags[] = { ...@@ -337,14 +344,17 @@ static ber_tlv_tag_t asn1_DEF_RelativeDistinguishedName_tags[] = {
static asn1_SET_OF_specifics_t asn1_DEF_RelativeDistinguishedName_specs = { static asn1_SET_OF_specifics_t asn1_DEF_RelativeDistinguishedName_specs = {
sizeof(struct RelativeDistinguishedName), sizeof(struct RelativeDistinguishedName),
offsetof(struct RelativeDistinguishedName, _ber_dec_ctx), offsetof(struct RelativeDistinguishedName, _ber_dec_ctx),
0, /* XER encoding is XMLDelimitedItemList */
}; };
asn1_TYPE_descriptor_t asn1_DEF_RelativeDistinguishedName = { asn1_TYPE_descriptor_t asn1_DEF_RelativeDistinguishedName = {
"RelativeDistinguishedName", "RelativeDistinguishedName",
SET_OF_free,
SET_OF_print,
SET_OF_constraint, SET_OF_constraint,
SET_OF_decode_ber, SET_OF_decode_ber,
SET_OF_encode_der, SET_OF_encode_der,
SET_OF_print, 0, /* Not implemented yet */
SET_OF_free, SET_OF_encode_xer,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn1_DEF_RelativeDistinguishedName_tags, asn1_DEF_RelativeDistinguishedName_tags,
sizeof(asn1_DEF_RelativeDistinguishedName_tags) sizeof(asn1_DEF_RelativeDistinguishedName_tags)
......
...@@ -36,14 +36,17 @@ static ber_tlv_tag_t asn1_DEF_Forest_tags[] = { ...@@ -36,14 +36,17 @@ static ber_tlv_tag_t asn1_DEF_Forest_tags[] = {
static asn1_SET_OF_specifics_t asn1_DEF_Forest_specs = { static asn1_SET_OF_specifics_t asn1_DEF_Forest_specs = {
sizeof(struct Forest), sizeof(struct Forest),
offsetof(struct Forest, _ber_dec_ctx), offsetof(struct Forest, _ber_dec_ctx),
0, /* XER encoding is XMLDelimitedItemList */
}; };
asn1_TYPE_descriptor_t asn1_DEF_Forest = { asn1_TYPE_descriptor_t asn1_DEF_Forest = {
"Forest", "Forest",
SET_OF_free,
SET_OF_print,
SET_OF_constraint, SET_OF_constraint,
SET_OF_decode_ber, SET_OF_decode_ber,
SET_OF_encode_der, SET_OF_encode_der,
SET_OF_print, 0, /* Not implemented yet */
SET_OF_free, SET_OF_encode_xer,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn1_DEF_Forest_tags, asn1_DEF_Forest_tags,
sizeof(asn1_DEF_Forest_tags) sizeof(asn1_DEF_Forest_tags)
...@@ -113,11 +116,13 @@ static asn1_SEQUENCE_specifics_t asn1_DEF_Tree_specs = { ...@@ -113,11 +116,13 @@ static asn1_SEQUENCE_specifics_t asn1_DEF_Tree_specs = {
}; };
asn1_TYPE_descriptor_t asn1_DEF_Tree = { asn1_TYPE_descriptor_t asn1_DEF_Tree = {
"Tree", "Tree",
SEQUENCE_free,
SEQUENCE_print,
SEQUENCE_constraint, SEQUENCE_constraint,
SEQUENCE_decode_ber, SEQUENCE_decode_ber,
SEQUENCE_encode_der, SEQUENCE_encode_der,
SEQUENCE_print, 0, /* Not implemented yet */
SEQUENCE_free, SEQUENCE_encode_xer,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn1_DEF_Tree_tags, asn1_DEF_Tree_tags,
sizeof(asn1_DEF_Tree_tags) sizeof(asn1_DEF_Tree_tags)
...@@ -205,15 +210,18 @@ static ber_tlv_tag_t asn1_DEF_trees_tags[] = { ...@@ -205,15 +210,18 @@ static ber_tlv_tag_t asn1_DEF_trees_tags[] = {
static asn1_SET_OF_specifics_t asn1_DEF_trees_specs = { static asn1_SET_OF_specifics_t asn1_DEF_trees_specs = {
sizeof(struct trees), sizeof(struct trees),
offsetof(struct trees, _ber_dec_ctx), offsetof(struct trees, _ber_dec_ctx),
0, /* XER encoding is XMLDelimitedItemList */
}; };
static /* Use -fall-defs-global to expose */ static /* Use -fall-defs-global to expose */
asn1_TYPE_descriptor_t asn1_DEF_trees = { asn1_TYPE_descriptor_t asn1_DEF_trees = {
"trees", "trees",
SET_OF_free,
SET_OF_print,
SET_OF_constraint, SET_OF_constraint,
SET_OF_decode_ber, SET_OF_decode_ber,
SET_OF_encode_der, SET_OF_encode_der,
SET_OF_print, 0, /* Not implemented yet */
SET_OF_free, SET_OF_encode_xer,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn1_DEF_trees_tags, asn1_DEF_trees_tags,
sizeof(asn1_DEF_trees_tags) sizeof(asn1_DEF_trees_tags)
...@@ -253,11 +261,13 @@ static asn1_SEQUENCE_specifics_t asn1_DEF_anything_member_specs = { ...@@ -253,11 +261,13 @@ static asn1_SEQUENCE_specifics_t asn1_DEF_anything_member_specs = {
static /* Use -fall-defs-global to expose */ static /* Use -fall-defs-global to expose */
asn1_TYPE_descriptor_t asn1_DEF_anything_member = { asn1_TYPE_descriptor_t asn1_DEF_anything_member = {
"", "",
SEQUENCE_free,
SEQUENCE_print,
SEQUENCE_constraint, SEQUENCE_constraint,
SEQUENCE_decode_ber, SEQUENCE_decode_ber,
SEQUENCE_encode_der, SEQUENCE_encode_der,
SEQUENCE_print, 0, /* Not implemented yet */
SEQUENCE_free, SEQUENCE_encode_xer,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn1_DEF_anything_member_tags, asn1_DEF_anything_member_tags,
sizeof(asn1_DEF_anything_member_tags) sizeof(asn1_DEF_anything_member_tags)
...@@ -287,15 +297,18 @@ static ber_tlv_tag_t asn1_DEF_anything_tags[] = { ...@@ -287,15 +297,18 @@ static ber_tlv_tag_t asn1_DEF_anything_tags[] = {
static asn1_SET_OF_specifics_t asn1_DEF_anything_specs = { static asn1_SET_OF_specifics_t asn1_DEF_anything_specs = {
sizeof(struct anything), sizeof(struct anything),
offsetof(struct anything, _ber_dec_ctx), offsetof(struct anything, _ber_dec_ctx),
0, /* XER encoding is XMLDelimitedItemList */
}; };
static /* Use -fall-defs-global to expose */ static /* Use -fall-defs-global to expose */
asn1_TYPE_descriptor_t asn1_DEF_anything = { asn1_TYPE_descriptor_t asn1_DEF_anything = {
"anything", "anything",
SET_OF_free,
SET_OF_print,
SET_OF_constraint, SET_OF_constraint,
SET_OF_decode_ber, SET_OF_decode_ber,
SET_OF_encode_der, SET_OF_encode_der,
SET_OF_print, 0, /* Not implemented yet */
SET_OF_free, SET_OF_encode_xer,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn1_DEF_anything_tags, asn1_DEF_anything_tags,
sizeof(asn1_DEF_anything_tags) sizeof(asn1_DEF_anything_tags)
...@@ -346,11 +359,13 @@ static asn1_SET_specifics_t asn1_DEF_Stuff_specs = { ...@@ -346,11 +359,13 @@ static asn1_SET_specifics_t asn1_DEF_Stuff_specs = {
}; };
asn1_TYPE_descriptor_t asn1_DEF_Stuff = { asn1_TYPE_descriptor_t asn1_DEF_Stuff = {
"Stuff", "Stuff",
SET_free,
SET_print,
SET_constraint, SET_constraint,
SET_decode_ber, SET_decode_ber,
SET_encode_der, SET_encode_der,
SET_print, 0, /* Not implemented yet */
SET_free, SET_encode_xer,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn1_DEF_Stuff_tags, asn1_DEF_Stuff_tags,
sizeof(asn1_DEF_Stuff_tags) sizeof(asn1_DEF_Stuff_tags)
......
/*** <<< INCLUDES [Programming] >>> ***/
#include <Fault.h>
#include <asn_SEQUENCE_OF.h>
#include <constr_SEQUENCE_OF.h>
/*** <<< DEPS [Programming] >>> ***/
extern asn1_TYPE_descriptor_t asn1_DEF_Programming;
/*** <<< TYPE-DECLS [Programming] >>> ***/
typedef struct Programming {
A_SEQUENCE_OF(Fault_t) list;
/* Context for parsing across buffer boundaries */
ber_dec_ctx_t _ber_dec_ctx;
} Programming_t;
/*** <<< STAT-DEFS [Programming] >>> ***/
static asn1_TYPE_member_t asn1_MBR_Programming[] = {
{ ATF_NOFLAGS, 0, 0,
.tag = (ASN_TAG_CLASS_CONTEXT | (0 << 2)),
.tag_mode = -1, /* IMPLICIT tag at current level */
.type = (void *)&asn1_DEF_Fault,
.memb_constraints = 0, /* Defer to actual type */
.name = ""
},
};
static ber_tlv_tag_t asn1_DEF_Programming_tags[] = {
(ASN_TAG_CLASS_UNIVERSAL | (16 << 2))
};
static asn1_SET_OF_specifics_t asn1_DEF_Programming_specs = {
sizeof(struct Programming),
offsetof(struct Programming, _ber_dec_ctx),
0, /* XER encoding is XMLDelimitedItemList */
};
asn1_TYPE_descriptor_t asn1_DEF_Programming = {
"Programming",
SEQUENCE_OF_free,
SEQUENCE_OF_print,
SEQUENCE_OF_constraint,
SEQUENCE_OF_decode_ber,
SEQUENCE_OF_encode_der,
0, /* Not implemented yet */
SEQUENCE_OF_encode_xer,
0, /* Use generic outmost tag fetcher */
asn1_DEF_Programming_tags,
sizeof(asn1_DEF_Programming_tags)
/sizeof(asn1_DEF_Programming_tags[0]), /* 1 */
asn1_DEF_Programming_tags, /* Same as above */
sizeof(asn1_DEF_Programming_tags)
/sizeof(asn1_DEF_Programming_tags[0]), /* 1 */
1, /* Whether CONSTRUCTED */
asn1_MBR_Programming,
1, /* Single element */
&asn1_DEF_Programming_specs /* Additional specs */
};
/*** <<< INCLUDES [Fault] >>> ***/
#include <Error.h>
#include <asn_SET_OF.h>
#include <constr_SET_OF.h>
/*** <<< DEPS [Fault] >>> ***/
extern asn1_TYPE_descriptor_t asn1_DEF_Fault;
/*** <<< TYPE-DECLS [Fault] >>> ***/
typedef struct Fault {
A_SET_OF(Error_t) list;
/* Context for parsing across buffer boundaries */
ber_dec_ctx_t _ber_dec_ctx;
} Fault_t;
/*** <<< STAT-DEFS [Fault] >>> ***/
static asn1_TYPE_member_t asn1_MBR_Fault[] = {
{ ATF_NOFLAGS, 0, 0,
.tag = (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)),
.tag_mode = 0,
.type = (void *)&asn1_DEF_Error,
.memb_constraints = 0, /* Defer to actual type */
.name = ""
},
};
static ber_tlv_tag_t asn1_DEF_Fault_tags[] = {
(ASN_TAG_CLASS_UNIVERSAL | (17 << 2))
};
static asn1_SET_OF_specifics_t asn1_DEF_Fault_specs = {
sizeof(struct Fault),
offsetof(struct Fault, _ber_dec_ctx),
0, /* XER encoding is XMLDelimitedItemList */
};
asn1_TYPE_descriptor_t asn1_DEF_Fault = {
"Fault",
SET_OF_free,
SET_OF_print,
SET_OF_constraint,
SET_OF_decode_ber,
SET_OF_encode_der,
0, /* Not implemented yet */
SET_OF_encode_xer,
0, /* Use generic outmost tag fetcher */
asn1_DEF_Fault_tags,
sizeof(asn1_DEF_Fault_tags)
/sizeof(asn1_DEF_Fault_tags[0]), /* 1 */
asn1_DEF_Fault_tags, /* Same as above */
sizeof(asn1_DEF_Fault_tags)
/sizeof(asn1_DEF_Fault_tags[0]), /* 1 */
1, /* Whether CONSTRUCTED */
asn1_MBR_Fault,
1, /* Single element */
&asn1_DEF_Fault_specs /* Additional specs */
};
/*** <<< INCLUDES [Error] >>> ***/
#include <constr_SEQUENCE.h>
/*** <<< DEPS [Error] >>> ***/
extern asn1_TYPE_descriptor_t asn1_DEF_Error;
/*** <<< TYPE-DECLS [Error] >>> ***/
typedef struct Error {
/*
* This type is extensible,
* possible extensions are below.
*/
/* Context for parsing across buffer boundaries */
ber_dec_ctx_t _ber_dec_ctx;
} Error_t;
/*** <<< STAT-DEFS [Error] >>> ***/
static ber_tlv_tag_t asn1_DEF_Error_tags[] = {
(ASN_TAG_CLASS_UNIVERSAL | (16 << 2))
};
static asn1_TYPE_tag2member_t asn1_DEF_Error_tag2el[] = {
};
static asn1_SEQUENCE_specifics_t asn1_DEF_Error_specs = {
sizeof(struct Error),
offsetof(struct Error, _ber_dec_ctx),
asn1_DEF_Error_tag2el,
0, /* Count of tags in the map */
-1, /* Start extensions */
-1 /* Stop extensions */
};
asn1_TYPE_descriptor_t asn1_DEF_Error = {
"Error",
SEQUENCE_free,
SEQUENCE_print,
SEQUENCE_constraint,
SEQUENCE_decode_ber,
SEQUENCE_encode_der,
0, /* Not implemented yet */
SEQUENCE_encode_xer,
0, /* Use generic outmost tag fetcher */
asn1_DEF_Error_tags,
sizeof(asn1_DEF_Error_tags)
/sizeof(asn1_DEF_Error_tags[0]), /* 1 */
asn1_DEF_Error_tags, /* Same as above */
sizeof(asn1_DEF_Error_tags)
/sizeof(asn1_DEF_Error_tags[0]), /* 1 */
1, /* Whether CONSTRUCTED */
0, 0, /* No members */
&asn1_DEF_Error_specs /* Additional specs */
};
...@@ -44,15 +44,18 @@ static ber_tlv_tag_t asn1_DEF_collection_tags[] = { ...@@ -44,15 +44,18 @@ static ber_tlv_tag_t asn1_DEF_collection_tags[] = {
static asn1_SET_OF_specifics_t asn1_DEF_collection_specs = { static asn1_SET_OF_specifics_t asn1_DEF_collection_specs = {
sizeof(struct collection), sizeof(struct collection),
offsetof(struct collection, _ber_dec_ctx), offsetof(struct collection, _ber_dec_ctx),
0, /* XER encoding is XMLDelimitedItemList */
}; };
static /* Use -fall-defs-global to expose */ static /* Use -fall-defs-global to expose */
asn1_TYPE_descriptor_t asn1_DEF_collection = { asn1_TYPE_descriptor_t asn1_DEF_collection = {
"collection", "collection",
SEQUENCE_OF_free,
SEQUENCE_OF_print,
SEQUENCE_OF_constraint, SEQUENCE_OF_constraint,
SEQUENCE_OF_decode_ber, SEQUENCE_OF_decode_ber,
SEQUENCE_OF_encode_der, SEQUENCE_OF_encode_der,
SEQUENCE_OF_print, 0, /* Not implemented yet */
SEQUENCE_OF_free, SEQUENCE_OF_encode_xer,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn1_DEF_collection_tags, asn1_DEF_collection_tags,
sizeof(asn1_DEF_collection_tags) sizeof(asn1_DEF_collection_tags)
...@@ -99,11 +102,13 @@ static asn1_SEQUENCE_specifics_t asn1_DEF_T_specs = { ...@@ -99,11 +102,13 @@ static asn1_SEQUENCE_specifics_t asn1_DEF_T_specs = {
}; };
asn1_TYPE_descriptor_t asn1_DEF_T = { asn1_TYPE_descriptor_t asn1_DEF_T = {
"T", "T",
SEQUENCE_free,
SEQUENCE_print,
SEQUENCE_constraint, SEQUENCE_constraint,
SEQUENCE_decode_ber, SEQUENCE_decode_ber,
SEQUENCE_encode_der, SEQUENCE_encode_der,
SEQUENCE_print, 0, /* Not implemented yet */
SEQUENCE_free, SEQUENCE_encode_xer,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn1_DEF_T_tags, asn1_DEF_T_tags,
sizeof(asn1_DEF_T_tags) sizeof(asn1_DEF_T_tags)
...@@ -174,11 +179,13 @@ static asn1_SEQUENCE_specifics_t asn1_DEF_T2_specs = { ...@@ -174,11 +179,13 @@ static asn1_SEQUENCE_specifics_t asn1_DEF_T2_specs = {
}; };
asn1_TYPE_descriptor_t asn1_DEF_T2 = { asn1_TYPE_descriptor_t asn1_DEF_T2 = {
"T2", "T2",
SEQUENCE_free,
SEQUENCE_print,
SEQUENCE_constraint, SEQUENCE_constraint,
SEQUENCE_decode_ber, SEQUENCE_decode_ber,
SEQUENCE_encode_der, SEQUENCE_encode_der,
SEQUENCE_print, 0, /* Not implemented yet */
SEQUENCE_free, SEQUENCE_encode_xer,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn1_DEF_T2_tags, asn1_DEF_T2_tags,
sizeof(asn1_DEF_T2_tags) sizeof(asn1_DEF_T2_tags)
......
...@@ -80,15 +80,18 @@ static ber_tlv_tag_t asn1_DEF_varsets_tags[] = { ...@@ -80,15 +80,18 @@ static ber_tlv_tag_t asn1_DEF_varsets_tags[] = {
static asn1_SET_OF_specifics_t asn1_DEF_varsets_specs = { static asn1_SET_OF_specifics_t asn1_DEF_varsets_specs = {
sizeof(struct varsets), sizeof(struct varsets),
offsetof(struct varsets, _ber_dec_ctx), offsetof(struct varsets, _ber_dec_ctx),
0, /* XER encoding is XMLDelimitedItemList */
}; };
static /* Use -fall-defs-global to expose */ static /* Use -fall-defs-global to expose */
asn1_TYPE_descriptor_t asn1_DEF_varsets = { asn1_TYPE_descriptor_t asn1_DEF_varsets = {
"varsets", "varsets",
SEQUENCE_OF_free,
SEQUENCE_OF_print,
SEQUENCE_OF_constraint, SEQUENCE_OF_constraint,
SEQUENCE_OF_decode_ber, SEQUENCE_OF_decode_ber,
SEQUENCE_OF_encode_der, SEQUENCE_OF_encode_der,
SEQUENCE_OF_print, 0, /* Not implemented yet */
SEQUENCE_OF_free, SEQUENCE_OF_encode_xer,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn1_DEF_varsets_tags, asn1_DEF_varsets_tags,
sizeof(asn1_DEF_varsets_tags) sizeof(asn1_DEF_varsets_tags)
...@@ -135,11 +138,13 @@ static asn1_SEQUENCE_specifics_t asn1_DEF_LogLine_specs = { ...@@ -135,11 +138,13 @@ static asn1_SEQUENCE_specifics_t asn1_DEF_LogLine_specs = {
}; };
asn1_TYPE_descriptor_t asn1_DEF_LogLine = { asn1_TYPE_descriptor_t asn1_DEF_LogLine = {
"LogLine", "LogLine",
SEQUENCE_free,
SEQUENCE_print,
SEQUENCE_constraint, SEQUENCE_constraint,
SEQUENCE_decode_ber, SEQUENCE_decode_ber,
SEQUENCE_encode_der, SEQUENCE_encode_der,
SEQUENCE_print, 0, /* Not implemented yet */
SEQUENCE_free, SEQUENCE_encode_xer,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn1_DEF_LogLine_tags, asn1_DEF_LogLine_tags,
sizeof(asn1_DEF_LogLine_tags) sizeof(asn1_DEF_LogLine_tags)
...@@ -226,15 +231,18 @@ static ber_tlv_tag_t asn1_DEF_vparts_tags[] = { ...@@ -226,15 +231,18 @@ static ber_tlv_tag_t asn1_DEF_vparts_tags[] = {
static asn1_SET_OF_specifics_t asn1_DEF_vparts_specs = { static asn1_SET_OF_specifics_t asn1_DEF_vparts_specs = {
sizeof(struct vparts), sizeof(struct vparts),
offsetof(struct vparts, _ber_dec_ctx), offsetof(struct vparts, _ber_dec_ctx),
1, /* XER encoding is XMLValueList */
}; };
static /* Use -fall-defs-global to expose */ static /* Use -fall-defs-global to expose */
asn1_TYPE_descriptor_t asn1_DEF_vparts = { asn1_TYPE_descriptor_t asn1_DEF_vparts = {
"vparts", "vparts",
SEQUENCE_OF_free,
SEQUENCE_OF_print,
SEQUENCE_OF_constraint, SEQUENCE_OF_constraint,
SEQUENCE_OF_decode_ber, SEQUENCE_OF_decode_ber,
SEQUENCE_OF_encode_der, SEQUENCE_OF_encode_der,
SEQUENCE_OF_print, 0, /* Not implemented yet */
SEQUENCE_OF_free, SEQUENCE_OF_encode_xer,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn1_DEF_vparts_tags, asn1_DEF_vparts_tags,
sizeof(asn1_DEF_vparts_tags) sizeof(asn1_DEF_vparts_tags)
...@@ -281,11 +289,13 @@ static asn1_SEQUENCE_specifics_t asn1_DEF_VariablePartSet_specs = { ...@@ -281,11 +289,13 @@ static asn1_SEQUENCE_specifics_t asn1_DEF_VariablePartSet_specs = {
}; };
asn1_TYPE_descriptor_t asn1_DEF_VariablePartSet = { asn1_TYPE_descriptor_t asn1_DEF_VariablePartSet = {
"VariablePartSet", "VariablePartSet",
SEQUENCE_free,
SEQUENCE_print,
SEQUENCE_constraint, SEQUENCE_constraint,
SEQUENCE_decode_ber, SEQUENCE_decode_ber,
SEQUENCE_encode_der, SEQUENCE_encode_der,
SEQUENCE_print, 0, /* Not implemented yet */
SEQUENCE_free, SEQUENCE_encode_xer,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn1_DEF_VariablePartSet_tags, asn1_DEF_VariablePartSet_tags,
sizeof(asn1_DEF_VariablePartSet_tags) sizeof(asn1_DEF_VariablePartSet_tags)
...@@ -400,15 +410,18 @@ static ber_tlv_tag_t asn1_DEF_vset_tags[] = { ...@@ -400,15 +410,18 @@ static ber_tlv_tag_t asn1_DEF_vset_tags[] = {
static asn1_SET_OF_specifics_t asn1_DEF_vset_specs = { static asn1_SET_OF_specifics_t asn1_DEF_vset_specs = {
sizeof(struct vset), sizeof(struct vset),
offsetof(struct vset, _ber_dec_ctx), offsetof(struct vset, _ber_dec_ctx),
0, /* XER encoding is XMLDelimitedItemList */
}; };
static /* Use -fall-defs-global to expose */ static /* Use -fall-defs-global to expose */
asn1_TYPE_descriptor_t asn1_DEF_vset = { asn1_TYPE_descriptor_t asn1_DEF_vset = {
"vset", "vset",
SET_OF_free,
SET_OF_print,
SET_OF_constraint, SET_OF_constraint,
SET_OF_decode_ber, SET_OF_decode_ber,
SET_OF_encode_der, SET_OF_encode_der,
SET_OF_print, 0, /* Not implemented yet */
SET_OF_free, SET_OF_encode_xer,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn1_DEF_vset_tags, asn1_DEF_vset_tags,
sizeof(asn1_DEF_vset_tags) sizeof(asn1_DEF_vset_tags)
...@@ -456,11 +469,13 @@ static asn1_SEQUENCE_specifics_t asn1_DEF_vrange_specs = { ...@@ -456,11 +469,13 @@ static asn1_SEQUENCE_specifics_t asn1_DEF_vrange_specs = {
static /* Use -fall-defs-global to expose */ static /* Use -fall-defs-global to expose */
asn1_TYPE_descriptor_t asn1_DEF_vrange = { asn1_TYPE_descriptor_t asn1_DEF_vrange = {
"vrange", "vrange",
SEQUENCE_free,
SEQUENCE_print,
SEQUENCE_constraint, SEQUENCE_constraint,
SEQUENCE_decode_ber, SEQUENCE_decode_ber,
SEQUENCE_encode_der, SEQUENCE_encode_der,
SEQUENCE_print, 0, /* Not implemented yet */
SEQUENCE_free, SEQUENCE_encode_xer,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn1_DEF_vrange_tags, asn1_DEF_vrange_tags,
sizeof(asn1_DEF_vrange_tags) sizeof(asn1_DEF_vrange_tags)
...@@ -505,11 +520,13 @@ static asn1_CHOICE_specifics_t asn1_DEF_VariablePart_specs = { ...@@ -505,11 +520,13 @@ static asn1_CHOICE_specifics_t asn1_DEF_VariablePart_specs = {
}; };
asn1_TYPE_descriptor_t asn1_DEF_VariablePart = { asn1_TYPE_descriptor_t asn1_DEF_VariablePart = {
"VariablePart", "VariablePart",
CHOICE_free,
CHOICE_print,
CHOICE_constraint, CHOICE_constraint,
CHOICE_decode_ber, CHOICE_decode_ber,
CHOICE_encode_der, CHOICE_encode_der,
CHOICE_print, 0, /* Not implemented yet */
CHOICE_free, CHOICE_encode_xer,
CHOICE_outmost_tag, CHOICE_outmost_tag,
0, /* No effective tags (pointer) */ 0, /* No effective tags (pointer) */
0, /* No effective tags (count) */ 0, /* No effective tags (count) */
...@@ -590,15 +607,18 @@ static ber_tlv_tag_t asn1_DEF_email_tags[] = { ...@@ -590,15 +607,18 @@ static ber_tlv_tag_t asn1_DEF_email_tags[] = {
static asn1_SET_OF_specifics_t asn1_DEF_email_specs = { static asn1_SET_OF_specifics_t asn1_DEF_email_specs = {
sizeof(struct email), sizeof(struct email),
offsetof(struct email, _ber_dec_ctx), offsetof(struct email, _ber_dec_ctx),
0, /* XER encoding is XMLDelimitedItemList */
}; };
static /* Use -fall-defs-global to expose */ static /* Use -fall-defs-global to expose */
asn1_TYPE_descriptor_t asn1_DEF_email = { asn1_TYPE_descriptor_t asn1_DEF_email = {
"email", "email",
SET_OF_free,
SET_OF_print,
SET_OF_constraint, SET_OF_constraint,
SET_OF_decode_ber, SET_OF_decode_ber,
SET_OF_encode_der, SET_OF_encode_der,
SET_OF_print, 0, /* Not implemented yet */
SET_OF_free, SET_OF_encode_xer,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn1_DEF_email_tags, asn1_DEF_email_tags,
sizeof(asn1_DEF_email_tags) sizeof(asn1_DEF_email_tags)
...@@ -646,11 +666,13 @@ static asn1_SEQUENCE_specifics_t asn1_DEF_notify_specs = { ...@@ -646,11 +666,13 @@ static asn1_SEQUENCE_specifics_t asn1_DEF_notify_specs = {
static /* Use -fall-defs-global to expose */ static /* Use -fall-defs-global to expose */
asn1_TYPE_descriptor_t asn1_DEF_notify = { asn1_TYPE_descriptor_t asn1_DEF_notify = {
"notify", "notify",
SEQUENCE_free,
SEQUENCE_print,
SEQUENCE_constraint, SEQUENCE_constraint,
SEQUENCE_decode_ber, SEQUENCE_decode_ber,
SEQUENCE_encode_der, SEQUENCE_encode_der,
SEQUENCE_print, 0, /* Not implemented yet */
SEQUENCE_free, SEQUENCE_encode_xer,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn1_DEF_notify_tags, asn1_DEF_notify_tags,
sizeof(asn1_DEF_notify_tags) sizeof(asn1_DEF_notify_tags)
...@@ -697,11 +719,13 @@ static asn1_SEQUENCE_specifics_t asn1_DEF_ActionItem_specs = { ...@@ -697,11 +719,13 @@ static asn1_SEQUENCE_specifics_t asn1_DEF_ActionItem_specs = {
}; };
asn1_TYPE_descriptor_t asn1_DEF_ActionItem = { asn1_TYPE_descriptor_t asn1_DEF_ActionItem = {
"ActionItem", "ActionItem",
SEQUENCE_free,
SEQUENCE_print,
SEQUENCE_constraint, SEQUENCE_constraint,
SEQUENCE_decode_ber, SEQUENCE_decode_ber,
SEQUENCE_encode_der, SEQUENCE_encode_der,
SEQUENCE_print, 0, /* Not implemented yet */
SEQUENCE_free, SEQUENCE_encode_xer,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn1_DEF_ActionItem_tags, asn1_DEF_ActionItem_tags,
sizeof(asn1_DEF_ActionItem_tags) sizeof(asn1_DEF_ActionItem_tags)
......
...@@ -53,15 +53,18 @@ static ber_tlv_tag_t asn1_DEF_t_member1_tags[] = { ...@@ -53,15 +53,18 @@ static ber_tlv_tag_t asn1_DEF_t_member1_tags[] = {
static asn1_SET_OF_specifics_t asn1_DEF_t_member1_specs = { static asn1_SET_OF_specifics_t asn1_DEF_t_member1_specs = {
sizeof(struct t_member1), sizeof(struct t_member1),
offsetof(struct t_member1, _ber_dec_ctx), offsetof(struct t_member1, _ber_dec_ctx),
0, /* XER encoding is XMLDelimitedItemList */
}; };
static /* Use -fall-defs-global to expose */ static /* Use -fall-defs-global to expose */
asn1_TYPE_descriptor_t asn1_DEF_t_member1 = { asn1_TYPE_descriptor_t asn1_DEF_t_member1 = {
"t-member1", "t-member1",
SET_OF_free,
SET_OF_print,
SET_OF_constraint, SET_OF_constraint,
SET_OF_decode_ber, SET_OF_decode_ber,
SET_OF_encode_der, SET_OF_encode_der,
SET_OF_print, 0, /* Not implemented yet */
SET_OF_free, SET_OF_encode_xer,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn1_DEF_t_member1_tags, asn1_DEF_t_member1_tags,
sizeof(asn1_DEF_t_member1_tags) sizeof(asn1_DEF_t_member1_tags)
...@@ -90,15 +93,18 @@ static ber_tlv_tag_t asn1_DEF_t_member2_tags[] = { ...@@ -90,15 +93,18 @@ static ber_tlv_tag_t asn1_DEF_t_member2_tags[] = {
static asn1_SET_OF_specifics_t asn1_DEF_t_member2_specs = { static asn1_SET_OF_specifics_t asn1_DEF_t_member2_specs = {
sizeof(struct t_member2), sizeof(struct t_member2),
offsetof(struct t_member2, _ber_dec_ctx), offsetof(struct t_member2, _ber_dec_ctx),
0, /* XER encoding is XMLDelimitedItemList */
}; };
static /* Use -fall-defs-global to expose */ static /* Use -fall-defs-global to expose */
asn1_TYPE_descriptor_t asn1_DEF_t_member2 = { asn1_TYPE_descriptor_t asn1_DEF_t_member2 = {
"t-member2", "t-member2",
SEQUENCE_OF_free,
SEQUENCE_OF_print,
SEQUENCE_OF_constraint, SEQUENCE_OF_constraint,
SEQUENCE_OF_decode_ber, SEQUENCE_OF_decode_ber,
SEQUENCE_OF_encode_der, SEQUENCE_OF_encode_der,
SEQUENCE_OF_print, 0, /* Not implemented yet */
SEQUENCE_OF_free, SEQUENCE_OF_encode_xer,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn1_DEF_t_member2_tags, asn1_DEF_t_member2_tags,
sizeof(asn1_DEF_t_member2_tags) sizeof(asn1_DEF_t_member2_tags)
...@@ -161,11 +167,13 @@ static asn1_SEQUENCE_specifics_t asn1_DEF_Test_structure_1_specs = { ...@@ -161,11 +167,13 @@ static asn1_SEQUENCE_specifics_t asn1_DEF_Test_structure_1_specs = {
}; };
asn1_TYPE_descriptor_t asn1_DEF_Test_structure_1 = { asn1_TYPE_descriptor_t asn1_DEF_Test_structure_1 = {
"Test-structure-1", "Test-structure-1",
SEQUENCE_free,
SEQUENCE_print,
SEQUENCE_constraint, SEQUENCE_constraint,
SEQUENCE_decode_ber, SEQUENCE_decode_ber,
SEQUENCE_encode_der, SEQUENCE_encode_der,
SEQUENCE_print, 0, /* Not implemented yet */
SEQUENCE_free, SEQUENCE_encode_xer,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn1_DEF_Test_structure_1_tags, asn1_DEF_Test_structure_1_tags,
sizeof(asn1_DEF_Test_structure_1_tags) sizeof(asn1_DEF_Test_structure_1_tags)
...@@ -238,15 +246,18 @@ static ber_tlv_tag_t asn1_DEF_or_tags[] = { ...@@ -238,15 +246,18 @@ static ber_tlv_tag_t asn1_DEF_or_tags[] = {
static asn1_SET_OF_specifics_t asn1_DEF_or_specs = { static asn1_SET_OF_specifics_t asn1_DEF_or_specs = {
sizeof(struct or), sizeof(struct or),
offsetof(struct or, _ber_dec_ctx), offsetof(struct or, _ber_dec_ctx),
1, /* XER encoding is XMLValueList */
}; };
static /* Use -fall-defs-global to expose */ static /* Use -fall-defs-global to expose */
asn1_TYPE_descriptor_t asn1_DEF_or = { asn1_TYPE_descriptor_t asn1_DEF_or = {
"or", "or",
SET_OF_free,
SET_OF_print,
SET_OF_constraint, SET_OF_constraint,
SET_OF_decode_ber, SET_OF_decode_ber,
SET_OF_encode_der, SET_OF_encode_der,
SET_OF_print, 0, /* Not implemented yet */
SET_OF_free, SET_OF_encode_xer,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn1_DEF_or_tags, asn1_DEF_or_tags,
sizeof(asn1_DEF_or_tags) sizeof(asn1_DEF_or_tags)
...@@ -307,11 +318,13 @@ static asn1_CHOICE_specifics_t asn1_DEF_Choice_1_specs = { ...@@ -307,11 +318,13 @@ static asn1_CHOICE_specifics_t asn1_DEF_Choice_1_specs = {
}; };
asn1_TYPE_descriptor_t asn1_DEF_Choice_1 = { asn1_TYPE_descriptor_t asn1_DEF_Choice_1 = {
"Choice-1", "Choice-1",
CHOICE_free,
CHOICE_print,
CHOICE_constraint, CHOICE_constraint,
CHOICE_decode_ber, CHOICE_decode_ber,
CHOICE_encode_der, CHOICE_encode_der,
CHOICE_print, 0, /* Not implemented yet */
CHOICE_free, CHOICE_encode_xer,
CHOICE_outmost_tag, CHOICE_outmost_tag,
0, /* No effective tags (pointer) */ 0, /* No effective tags (pointer) */
0, /* No effective tags (count) */ 0, /* No effective tags (count) */
......
...@@ -100,11 +100,13 @@ static asn1_CHOICE_specifics_t asn1_DEF_e_specs = { ...@@ -100,11 +100,13 @@ static asn1_CHOICE_specifics_t asn1_DEF_e_specs = {
static /* Use -fall-defs-global to expose */ static /* Use -fall-defs-global to expose */
asn1_TYPE_descriptor_t asn1_DEF_e = { asn1_TYPE_descriptor_t asn1_DEF_e = {
"e", "e",
CHOICE_free,
CHOICE_print,
CHOICE_constraint, CHOICE_constraint,
CHOICE_decode_ber, CHOICE_decode_ber,
CHOICE_encode_der, CHOICE_encode_der,
CHOICE_print, 0, /* Not implemented yet */
CHOICE_free, CHOICE_encode_xer,
CHOICE_outmost_tag, CHOICE_outmost_tag,
0, /* No effective tags (pointer) */ 0, /* No effective tags (pointer) */
0, /* No effective tags (count) */ 0, /* No effective tags (count) */
...@@ -148,11 +150,13 @@ static asn1_CHOICE_specifics_t asn1_DEF_h_specs = { ...@@ -148,11 +150,13 @@ static asn1_CHOICE_specifics_t asn1_DEF_h_specs = {
static /* Use -fall-defs-global to expose */ static /* Use -fall-defs-global to expose */
asn1_TYPE_descriptor_t asn1_DEF_h = { asn1_TYPE_descriptor_t asn1_DEF_h = {
"h", "h",
CHOICE_free,
CHOICE_print,
CHOICE_constraint, CHOICE_constraint,
CHOICE_decode_ber, CHOICE_decode_ber,
CHOICE_encode_der, CHOICE_encode_der,
CHOICE_print, 0, /* Not implemented yet */
CHOICE_free, CHOICE_encode_xer,
CHOICE_outmost_tag, CHOICE_outmost_tag,
0, /* No effective tags (pointer) */ 0, /* No effective tags (pointer) */
0, /* No effective tags (count) */ 0, /* No effective tags (count) */
...@@ -213,11 +217,13 @@ static asn1_CHOICE_specifics_t asn1_DEF_b_specs = { ...@@ -213,11 +217,13 @@ static asn1_CHOICE_specifics_t asn1_DEF_b_specs = {
static /* Use -fall-defs-global to expose */ static /* Use -fall-defs-global to expose */
asn1_TYPE_descriptor_t asn1_DEF_b = { asn1_TYPE_descriptor_t asn1_DEF_b = {
"b", "b",
CHOICE_free,
CHOICE_print,
CHOICE_constraint, CHOICE_constraint,
CHOICE_decode_ber, CHOICE_decode_ber,
CHOICE_encode_der, CHOICE_encode_der,
CHOICE_print, 0, /* Not implemented yet */
CHOICE_free, CHOICE_encode_xer,
CHOICE_outmost_tag, CHOICE_outmost_tag,
0, /* No effective tags (pointer) */ 0, /* No effective tags (pointer) */
0, /* No effective tags (count) */ 0, /* No effective tags (count) */
...@@ -267,11 +273,13 @@ static asn1_SEQUENCE_specifics_t asn1_DEF_T_specs = { ...@@ -267,11 +273,13 @@ static asn1_SEQUENCE_specifics_t asn1_DEF_T_specs = {
}; };
asn1_TYPE_descriptor_t asn1_DEF_T = { asn1_TYPE_descriptor_t asn1_DEF_T = {
"T", "T",
SEQUENCE_free,
SEQUENCE_print,
SEQUENCE_constraint, SEQUENCE_constraint,
SEQUENCE_decode_ber, SEQUENCE_decode_ber,
SEQUENCE_encode_der, SEQUENCE_encode_der,
SEQUENCE_print, 0, /* Not implemented yet */
SEQUENCE_free, SEQUENCE_encode_xer,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn1_DEF_T_tags, asn1_DEF_T_tags,
sizeof(asn1_DEF_T_tags) sizeof(asn1_DEF_T_tags)
......
...@@ -11,11 +11,12 @@ typedef OCTET_STRING_t PrimitiveType_t; ...@@ -11,11 +11,12 @@ typedef OCTET_STRING_t PrimitiveType_t;
/*** <<< FUNC-DECLS [PrimitiveType] >>> ***/ /*** <<< FUNC-DECLS [PrimitiveType] >>> ***/
extern asn1_TYPE_descriptor_t asn1_DEF_PrimitiveType; extern asn1_TYPE_descriptor_t asn1_DEF_PrimitiveType;
asn_struct_free_f PrimitiveType_free;
asn_struct_print_f PrimitiveType_print;
asn_constr_check_f PrimitiveType_constraint; asn_constr_check_f PrimitiveType_constraint;
ber_type_decoder_f PrimitiveType_decode_ber; ber_type_decoder_f PrimitiveType_decode_ber;
der_type_encoder_f PrimitiveType_encode_der; der_type_encoder_f PrimitiveType_encode_der;
asn_struct_print_f PrimitiveType_print; xer_type_encoder_f PrimitiveType_encode_xer;
asn_struct_free_f PrimitiveType_free;
/*** <<< CODE [PrimitiveType] >>> ***/ /*** <<< CODE [PrimitiveType] >>> ***/
...@@ -35,16 +36,32 @@ PrimitiveType_constraint(asn1_TYPE_descriptor_t *td, const void *sptr, ...@@ -35,16 +36,32 @@ PrimitiveType_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
*/ */
static void static void
PrimitiveType_inherit_TYPE_descriptor(asn1_TYPE_descriptor_t *td) { PrimitiveType_inherit_TYPE_descriptor(asn1_TYPE_descriptor_t *td) {
td->ber_decoder = asn1_DEF_OCTET_STRING.ber_decoder;
td->der_encoder = asn1_DEF_OCTET_STRING.der_encoder;
td->free_struct = asn1_DEF_OCTET_STRING.free_struct; td->free_struct = asn1_DEF_OCTET_STRING.free_struct;
td->print_struct = asn1_DEF_OCTET_STRING.print_struct; td->print_struct = asn1_DEF_OCTET_STRING.print_struct;
td->ber_decoder = asn1_DEF_OCTET_STRING.ber_decoder;
td->der_encoder = asn1_DEF_OCTET_STRING.der_encoder;
td->xer_decoder = asn1_DEF_OCTET_STRING.xer_decoder;
td->xer_encoder = asn1_DEF_OCTET_STRING.xer_encoder;
td->last_tag_form = asn1_DEF_OCTET_STRING.last_tag_form; td->last_tag_form = asn1_DEF_OCTET_STRING.last_tag_form;
td->elements = asn1_DEF_OCTET_STRING.elements; td->elements = asn1_DEF_OCTET_STRING.elements;
td->elements_count = asn1_DEF_OCTET_STRING.elements_count; td->elements_count = asn1_DEF_OCTET_STRING.elements_count;
td->specifics = asn1_DEF_OCTET_STRING.specifics; td->specifics = asn1_DEF_OCTET_STRING.specifics;
} }
void
PrimitiveType_free(asn1_TYPE_descriptor_t *td,
void *struct_ptr, int contents_only) {
PrimitiveType_inherit_TYPE_descriptor(td);
td->free_struct(td, struct_ptr, contents_only);
}
int
PrimitiveType_print(asn1_TYPE_descriptor_t *td, const void *struct_ptr,
int ilevel, asn_app_consume_bytes_f *cb, void *app_key) {
PrimitiveType_inherit_TYPE_descriptor(td);
return td->print_struct(td, struct_ptr, ilevel, cb, app_key);
}
ber_dec_rval_t ber_dec_rval_t
PrimitiveType_decode_ber(asn1_TYPE_descriptor_t *td, PrimitiveType_decode_ber(asn1_TYPE_descriptor_t *td,
void **structure, void *bufptr, size_t size, int tag_mode) { void **structure, void *bufptr, size_t size, int tag_mode) {
...@@ -52,7 +69,7 @@ PrimitiveType_decode_ber(asn1_TYPE_descriptor_t *td, ...@@ -52,7 +69,7 @@ PrimitiveType_decode_ber(asn1_TYPE_descriptor_t *td,
return td->ber_decoder(td, structure, bufptr, size, tag_mode); return td->ber_decoder(td, structure, bufptr, size, tag_mode);
} }
der_enc_rval_t asn_enc_rval_t
PrimitiveType_encode_der(asn1_TYPE_descriptor_t *td, PrimitiveType_encode_der(asn1_TYPE_descriptor_t *td,
void *structure, int tag_mode, ber_tlv_tag_t tag, void *structure, int tag_mode, ber_tlv_tag_t tag,
asn_app_consume_bytes_f *cb, void *app_key) { asn_app_consume_bytes_f *cb, void *app_key) {
...@@ -60,18 +77,12 @@ PrimitiveType_encode_der(asn1_TYPE_descriptor_t *td, ...@@ -60,18 +77,12 @@ PrimitiveType_encode_der(asn1_TYPE_descriptor_t *td,
return td->der_encoder(td, structure, tag_mode, tag, cb, app_key); return td->der_encoder(td, structure, tag_mode, tag, cb, app_key);
} }
int asn_enc_rval_t
PrimitiveType_print(asn1_TYPE_descriptor_t *td, const void *struct_ptr, PrimitiveType_encode_xer(asn1_TYPE_descriptor_t *td, void *structure,
int ilevel, asn_app_consume_bytes_f *cb, void *app_key) { int ilevel, enum xer_encoder_flags_e flags,
PrimitiveType_inherit_TYPE_descriptor(td); asn_app_consume_bytes_f *cb, void *app_key) {
return td->print_struct(td, struct_ptr, ilevel, cb, app_key);
}
void
PrimitiveType_free(asn1_TYPE_descriptor_t *td,
void *struct_ptr, int contents_only) {
PrimitiveType_inherit_TYPE_descriptor(td); PrimitiveType_inherit_TYPE_descriptor(td);
td->free_struct(td, struct_ptr, contents_only); return td->xer_encoder(td, structure, ilevel, flags, cb, app_key);
} }
...@@ -82,11 +93,13 @@ static ber_tlv_tag_t asn1_DEF_PrimitiveType_tags[] = { ...@@ -82,11 +93,13 @@ static ber_tlv_tag_t asn1_DEF_PrimitiveType_tags[] = {
}; };
asn1_TYPE_descriptor_t asn1_DEF_PrimitiveType = { asn1_TYPE_descriptor_t asn1_DEF_PrimitiveType = {
"PrimitiveType", "PrimitiveType",
PrimitiveType_free,
PrimitiveType_print,
PrimitiveType_constraint, PrimitiveType_constraint,
PrimitiveType_decode_ber, PrimitiveType_decode_ber,
PrimitiveType_encode_der, PrimitiveType_encode_der,
PrimitiveType_print, 0, /* Not implemented yet */
PrimitiveType_free, PrimitiveType_encode_xer,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn1_DEF_PrimitiveType_tags, asn1_DEF_PrimitiveType_tags,
sizeof(asn1_DEF_PrimitiveType_tags) sizeof(asn1_DEF_PrimitiveType_tags)
...@@ -146,11 +159,13 @@ static asn1_SEQUENCE_specifics_t asn1_DEF_ConstructedType_specs = { ...@@ -146,11 +159,13 @@ static asn1_SEQUENCE_specifics_t asn1_DEF_ConstructedType_specs = {
}; };
asn1_TYPE_descriptor_t asn1_DEF_ConstructedType = { asn1_TYPE_descriptor_t asn1_DEF_ConstructedType = {
"ConstructedType", "ConstructedType",
SEQUENCE_free,
SEQUENCE_print,
SEQUENCE_constraint, SEQUENCE_constraint,
SEQUENCE_decode_ber, SEQUENCE_decode_ber,
SEQUENCE_encode_der, SEQUENCE_encode_der,
SEQUENCE_print, 0, /* Not implemented yet */
SEQUENCE_free, SEQUENCE_encode_xer,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn1_DEF_ConstructedType_tags, asn1_DEF_ConstructedType_tags,
sizeof(asn1_DEF_ConstructedType_tags) sizeof(asn1_DEF_ConstructedType_tags)
...@@ -177,11 +192,12 @@ typedef ConstructedType_t T_t; ...@@ -177,11 +192,12 @@ typedef ConstructedType_t T_t;
/*** <<< FUNC-DECLS [T] >>> ***/ /*** <<< FUNC-DECLS [T] >>> ***/
extern asn1_TYPE_descriptor_t asn1_DEF_T; extern asn1_TYPE_descriptor_t asn1_DEF_T;
asn_struct_free_f T_free;
asn_struct_print_f T_print;
asn_constr_check_f T_constraint; asn_constr_check_f T_constraint;
ber_type_decoder_f T_decode_ber; ber_type_decoder_f T_decode_ber;
der_type_encoder_f T_encode_der; der_type_encoder_f T_encode_der;
asn_struct_print_f T_print; xer_type_encoder_f T_encode_xer;
asn_struct_free_f T_free;
/*** <<< CODE [T] >>> ***/ /*** <<< CODE [T] >>> ***/
...@@ -201,16 +217,32 @@ T_constraint(asn1_TYPE_descriptor_t *td, const void *sptr, ...@@ -201,16 +217,32 @@ T_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
*/ */
static void static void
T_inherit_TYPE_descriptor(asn1_TYPE_descriptor_t *td) { T_inherit_TYPE_descriptor(asn1_TYPE_descriptor_t *td) {
td->ber_decoder = asn1_DEF_ConstructedType.ber_decoder;
td->der_encoder = asn1_DEF_ConstructedType.der_encoder;
td->free_struct = asn1_DEF_ConstructedType.free_struct; td->free_struct = asn1_DEF_ConstructedType.free_struct;
td->print_struct = asn1_DEF_ConstructedType.print_struct; td->print_struct = asn1_DEF_ConstructedType.print_struct;
td->ber_decoder = asn1_DEF_ConstructedType.ber_decoder;
td->der_encoder = asn1_DEF_ConstructedType.der_encoder;
td->xer_decoder = asn1_DEF_ConstructedType.xer_decoder;
td->xer_encoder = asn1_DEF_ConstructedType.xer_encoder;
td->last_tag_form = asn1_DEF_ConstructedType.last_tag_form; td->last_tag_form = asn1_DEF_ConstructedType.last_tag_form;
td->elements = asn1_DEF_ConstructedType.elements; td->elements = asn1_DEF_ConstructedType.elements;
td->elements_count = asn1_DEF_ConstructedType.elements_count; td->elements_count = asn1_DEF_ConstructedType.elements_count;
td->specifics = asn1_DEF_ConstructedType.specifics; td->specifics = asn1_DEF_ConstructedType.specifics;
} }
void
T_free(asn1_TYPE_descriptor_t *td,
void *struct_ptr, int contents_only) {
T_inherit_TYPE_descriptor(td);
td->free_struct(td, struct_ptr, contents_only);
}
int
T_print(asn1_TYPE_descriptor_t *td, const void *struct_ptr,
int ilevel, asn_app_consume_bytes_f *cb, void *app_key) {
T_inherit_TYPE_descriptor(td);
return td->print_struct(td, struct_ptr, ilevel, cb, app_key);
}
ber_dec_rval_t ber_dec_rval_t
T_decode_ber(asn1_TYPE_descriptor_t *td, T_decode_ber(asn1_TYPE_descriptor_t *td,
void **structure, void *bufptr, size_t size, int tag_mode) { void **structure, void *bufptr, size_t size, int tag_mode) {
...@@ -218,7 +250,7 @@ T_decode_ber(asn1_TYPE_descriptor_t *td, ...@@ -218,7 +250,7 @@ T_decode_ber(asn1_TYPE_descriptor_t *td,
return td->ber_decoder(td, structure, bufptr, size, tag_mode); return td->ber_decoder(td, structure, bufptr, size, tag_mode);
} }
der_enc_rval_t asn_enc_rval_t
T_encode_der(asn1_TYPE_descriptor_t *td, T_encode_der(asn1_TYPE_descriptor_t *td,
void *structure, int tag_mode, ber_tlv_tag_t tag, void *structure, int tag_mode, ber_tlv_tag_t tag,
asn_app_consume_bytes_f *cb, void *app_key) { asn_app_consume_bytes_f *cb, void *app_key) {
...@@ -226,18 +258,12 @@ T_encode_der(asn1_TYPE_descriptor_t *td, ...@@ -226,18 +258,12 @@ T_encode_der(asn1_TYPE_descriptor_t *td,
return td->der_encoder(td, structure, tag_mode, tag, cb, app_key); return td->der_encoder(td, structure, tag_mode, tag, cb, app_key);
} }
int asn_enc_rval_t
T_print(asn1_TYPE_descriptor_t *td, const void *struct_ptr, T_encode_xer(asn1_TYPE_descriptor_t *td, void *structure,
int ilevel, asn_app_consume_bytes_f *cb, void *app_key) { int ilevel, enum xer_encoder_flags_e flags,
T_inherit_TYPE_descriptor(td); asn_app_consume_bytes_f *cb, void *app_key) {
return td->print_struct(td, struct_ptr, ilevel, cb, app_key);
}
void
T_free(asn1_TYPE_descriptor_t *td,
void *struct_ptr, int contents_only) {
T_inherit_TYPE_descriptor(td); T_inherit_TYPE_descriptor(td);
td->free_struct(td, struct_ptr, contents_only); return td->xer_encoder(td, structure, ilevel, flags, cb, app_key);
} }
...@@ -249,11 +275,13 @@ static ber_tlv_tag_t asn1_DEF_T_tags[] = { ...@@ -249,11 +275,13 @@ static ber_tlv_tag_t asn1_DEF_T_tags[] = {
}; };
asn1_TYPE_descriptor_t asn1_DEF_T = { asn1_TYPE_descriptor_t asn1_DEF_T = {
"T", "T",
T_free,
T_print,
T_constraint, T_constraint,
T_decode_ber, T_decode_ber,
T_encode_der, T_encode_der,
T_print, 0, /* Not implemented yet */
T_free, T_encode_xer,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn1_DEF_T_tags, asn1_DEF_T_tags,
sizeof(asn1_DEF_T_tags) sizeof(asn1_DEF_T_tags)
......
...@@ -64,11 +64,13 @@ static asn1_SET_specifics_t asn1_DEF_T1_specs = { ...@@ -64,11 +64,13 @@ static asn1_SET_specifics_t asn1_DEF_T1_specs = {
}; };
asn1_TYPE_descriptor_t asn1_DEF_T1 = { asn1_TYPE_descriptor_t asn1_DEF_T1 = {
"T1", "T1",
SET_free,
SET_print,
SET_constraint, SET_constraint,
SET_decode_ber, SET_decode_ber,
SET_encode_der, SET_encode_der,
SET_print, 0, /* Not implemented yet */
SET_free, SET_encode_xer,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn1_DEF_T1_tags, asn1_DEF_T1_tags,
sizeof(asn1_DEF_T1_tags) sizeof(asn1_DEF_T1_tags)
...@@ -148,11 +150,13 @@ static asn1_SET_specifics_t asn1_DEF_T2_specs = { ...@@ -148,11 +150,13 @@ static asn1_SET_specifics_t asn1_DEF_T2_specs = {
}; };
asn1_TYPE_descriptor_t asn1_DEF_T2 = { asn1_TYPE_descriptor_t asn1_DEF_T2 = {
"T2", "T2",
SET_free,
SET_print,
SET_constraint, SET_constraint,
SET_decode_ber, SET_decode_ber,
SET_encode_der, SET_encode_der,
SET_print, 0, /* Not implemented yet */
SET_free, SET_encode_xer,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn1_DEF_T2_tags, asn1_DEF_T2_tags,
sizeof(asn1_DEF_T2_tags) sizeof(asn1_DEF_T2_tags)
...@@ -223,11 +227,13 @@ static asn1_CHOICE_specifics_t asn1_DEF_T3_specs = { ...@@ -223,11 +227,13 @@ static asn1_CHOICE_specifics_t asn1_DEF_T3_specs = {
}; };
asn1_TYPE_descriptor_t asn1_DEF_T3 = { asn1_TYPE_descriptor_t asn1_DEF_T3 = {
"T3", "T3",
CHOICE_free,
CHOICE_print,
CHOICE_constraint, CHOICE_constraint,
CHOICE_decode_ber, CHOICE_decode_ber,
CHOICE_encode_der, CHOICE_encode_der,
CHOICE_print, 0, /* Not implemented yet */
CHOICE_free, CHOICE_encode_xer,
CHOICE_outmost_tag, CHOICE_outmost_tag,
0, /* No effective tags (pointer) */ 0, /* No effective tags (pointer) */
0, /* No effective tags (count) */ 0, /* No effective tags (count) */
...@@ -296,11 +302,13 @@ static asn1_CHOICE_specifics_t asn1_DEF_T4_specs = { ...@@ -296,11 +302,13 @@ static asn1_CHOICE_specifics_t asn1_DEF_T4_specs = {
}; };
asn1_TYPE_descriptor_t asn1_DEF_T4 = { asn1_TYPE_descriptor_t asn1_DEF_T4 = {
"T4", "T4",
CHOICE_free,
CHOICE_print,
CHOICE_constraint, CHOICE_constraint,
CHOICE_decode_ber, CHOICE_decode_ber,
CHOICE_encode_der, CHOICE_encode_der,
CHOICE_print, 0, /* Not implemented yet */
CHOICE_free, CHOICE_encode_xer,
CHOICE_outmost_tag, CHOICE_outmost_tag,
0, /* No effective tags (pointer) */ 0, /* No effective tags (pointer) */
0, /* No effective tags (count) */ 0, /* No effective tags (count) */
......
This diff is collapsed.
...@@ -54,11 +54,13 @@ static asn1_SEQUENCE_specifics_t asn1_DEF_T1_specs = { ...@@ -54,11 +54,13 @@ static asn1_SEQUENCE_specifics_t asn1_DEF_T1_specs = {
}; };
asn1_TYPE_descriptor_t asn1_DEF_T1 = { asn1_TYPE_descriptor_t asn1_DEF_T1 = {
"T1", "T1",
SEQUENCE_free,
SEQUENCE_print,
SEQUENCE_constraint, SEQUENCE_constraint,
SEQUENCE_decode_ber, SEQUENCE_decode_ber,
SEQUENCE_encode_der, SEQUENCE_encode_der,
SEQUENCE_print, 0, /* Not implemented yet */
SEQUENCE_free, SEQUENCE_encode_xer,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn1_DEF_T1_tags, asn1_DEF_T1_tags,
sizeof(asn1_DEF_T1_tags) sizeof(asn1_DEF_T1_tags)
...@@ -129,11 +131,13 @@ static asn1_SEQUENCE_specifics_t asn1_DEF_T2_specs = { ...@@ -129,11 +131,13 @@ static asn1_SEQUENCE_specifics_t asn1_DEF_T2_specs = {
}; };
asn1_TYPE_descriptor_t asn1_DEF_T2 = { asn1_TYPE_descriptor_t asn1_DEF_T2 = {
"T2", "T2",
SEQUENCE_free,
SEQUENCE_print,
SEQUENCE_constraint, SEQUENCE_constraint,
SEQUENCE_decode_ber, SEQUENCE_decode_ber,
SEQUENCE_encode_der, SEQUENCE_encode_der,
SEQUENCE_print, 0, /* Not implemented yet */
SEQUENCE_free, SEQUENCE_encode_xer,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn1_DEF_T2_tags, asn1_DEF_T2_tags,
sizeof(asn1_DEF_T2_tags) sizeof(asn1_DEF_T2_tags)
......
This diff is collapsed.
This diff is collapsed.
...@@ -5,13 +5,13 @@ ...@@ -5,13 +5,13 @@
-- .spelio.software.asn1c.test (9363.1.5.1) -- .spelio.software.asn1c.test (9363.1.5.1)
-- .66 -- .66
ModuleTestReferenceToSimpleType ModuleTestReferenceToNamedSimpleType
{ iso org(3) dod(6) internet(1) private(4) enterprise(1) { iso org(3) dod(6) internet(1) private(4) enterprise(1)
spelio(9363) software(1) asn1c(5) test(1) 66 } spelio(9363) software(1) asn1c(5) test(1) 66 }
DEFINITIONS IMPLICIT TAGS ::= DEFINITIONS IMPLICIT TAGS ::=
BEGIN BEGIN
T ::= SET OF SimpleType T ::= SET OF named SimpleType
SimpleType ::= ENUMERATED { one, two, three } SimpleType ::= ENUMERATED { one, two, three }
......
...@@ -36,14 +36,17 @@ static ber_tlv_tag_t asn1_DEF_T_tags[] = { ...@@ -36,14 +36,17 @@ static ber_tlv_tag_t asn1_DEF_T_tags[] = {
static asn1_SET_OF_specifics_t asn1_DEF_T_specs = { static asn1_SET_OF_specifics_t asn1_DEF_T_specs = {
sizeof(struct T), sizeof(struct T),
offsetof(struct T, _ber_dec_ctx), offsetof(struct T, _ber_dec_ctx),
1, /* XER encoding is XMLValueList */
}; };
asn1_TYPE_descriptor_t asn1_DEF_T = { asn1_TYPE_descriptor_t asn1_DEF_T = {
"T", "T",
SET_OF_free,
SET_OF_print,
SET_OF_constraint, SET_OF_constraint,
SET_OF_decode_ber, SET_OF_decode_ber,
SET_OF_encode_der, SET_OF_encode_der,
SET_OF_print, 0, /* Not implemented yet */
SET_OF_free, SET_OF_encode_xer,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn1_DEF_T_tags, asn1_DEF_T_tags,
sizeof(asn1_DEF_T_tags) sizeof(asn1_DEF_T_tags)
...@@ -78,11 +81,12 @@ typedef ENUMERATED_t SimpleType_t; ...@@ -78,11 +81,12 @@ typedef ENUMERATED_t SimpleType_t;
/*** <<< FUNC-DECLS [SimpleType] >>> ***/ /*** <<< FUNC-DECLS [SimpleType] >>> ***/
extern asn1_TYPE_descriptor_t asn1_DEF_SimpleType; extern asn1_TYPE_descriptor_t asn1_DEF_SimpleType;
asn_struct_free_f SimpleType_free;
asn_struct_print_f SimpleType_print;
asn_constr_check_f SimpleType_constraint; asn_constr_check_f SimpleType_constraint;
ber_type_decoder_f SimpleType_decode_ber; ber_type_decoder_f SimpleType_decode_ber;
der_type_encoder_f SimpleType_encode_der; der_type_encoder_f SimpleType_encode_der;
asn_struct_print_f SimpleType_print; xer_type_encoder_f SimpleType_encode_xer;
asn_struct_free_f SimpleType_free;
/*** <<< CODE [SimpleType] >>> ***/ /*** <<< CODE [SimpleType] >>> ***/
...@@ -102,16 +106,32 @@ SimpleType_constraint(asn1_TYPE_descriptor_t *td, const void *sptr, ...@@ -102,16 +106,32 @@ SimpleType_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
*/ */
static void static void
SimpleType_inherit_TYPE_descriptor(asn1_TYPE_descriptor_t *td) { SimpleType_inherit_TYPE_descriptor(asn1_TYPE_descriptor_t *td) {
td->ber_decoder = asn1_DEF_ENUMERATED.ber_decoder;
td->der_encoder = asn1_DEF_ENUMERATED.der_encoder;
td->free_struct = asn1_DEF_ENUMERATED.free_struct; td->free_struct = asn1_DEF_ENUMERATED.free_struct;
td->print_struct = asn1_DEF_ENUMERATED.print_struct; td->print_struct = asn1_DEF_ENUMERATED.print_struct;
td->ber_decoder = asn1_DEF_ENUMERATED.ber_decoder;
td->der_encoder = asn1_DEF_ENUMERATED.der_encoder;
td->xer_decoder = asn1_DEF_ENUMERATED.xer_decoder;
td->xer_encoder = asn1_DEF_ENUMERATED.xer_encoder;
td->last_tag_form = asn1_DEF_ENUMERATED.last_tag_form; td->last_tag_form = asn1_DEF_ENUMERATED.last_tag_form;
td->elements = asn1_DEF_ENUMERATED.elements; td->elements = asn1_DEF_ENUMERATED.elements;
td->elements_count = asn1_DEF_ENUMERATED.elements_count; td->elements_count = asn1_DEF_ENUMERATED.elements_count;
td->specifics = asn1_DEF_ENUMERATED.specifics; td->specifics = asn1_DEF_ENUMERATED.specifics;
} }
void
SimpleType_free(asn1_TYPE_descriptor_t *td,
void *struct_ptr, int contents_only) {
SimpleType_inherit_TYPE_descriptor(td);
td->free_struct(td, struct_ptr, contents_only);
}
int
SimpleType_print(asn1_TYPE_descriptor_t *td, const void *struct_ptr,
int ilevel, asn_app_consume_bytes_f *cb, void *app_key) {
SimpleType_inherit_TYPE_descriptor(td);
return td->print_struct(td, struct_ptr, ilevel, cb, app_key);
}
ber_dec_rval_t ber_dec_rval_t
SimpleType_decode_ber(asn1_TYPE_descriptor_t *td, SimpleType_decode_ber(asn1_TYPE_descriptor_t *td,
void **structure, void *bufptr, size_t size, int tag_mode) { void **structure, void *bufptr, size_t size, int tag_mode) {
...@@ -119,7 +139,7 @@ SimpleType_decode_ber(asn1_TYPE_descriptor_t *td, ...@@ -119,7 +139,7 @@ SimpleType_decode_ber(asn1_TYPE_descriptor_t *td,
return td->ber_decoder(td, structure, bufptr, size, tag_mode); return td->ber_decoder(td, structure, bufptr, size, tag_mode);
} }
der_enc_rval_t asn_enc_rval_t
SimpleType_encode_der(asn1_TYPE_descriptor_t *td, SimpleType_encode_der(asn1_TYPE_descriptor_t *td,
void *structure, int tag_mode, ber_tlv_tag_t tag, void *structure, int tag_mode, ber_tlv_tag_t tag,
asn_app_consume_bytes_f *cb, void *app_key) { asn_app_consume_bytes_f *cb, void *app_key) {
...@@ -127,18 +147,12 @@ SimpleType_encode_der(asn1_TYPE_descriptor_t *td, ...@@ -127,18 +147,12 @@ SimpleType_encode_der(asn1_TYPE_descriptor_t *td,
return td->der_encoder(td, structure, tag_mode, tag, cb, app_key); return td->der_encoder(td, structure, tag_mode, tag, cb, app_key);
} }
int asn_enc_rval_t
SimpleType_print(asn1_TYPE_descriptor_t *td, const void *struct_ptr, SimpleType_encode_xer(asn1_TYPE_descriptor_t *td, void *structure,
int ilevel, asn_app_consume_bytes_f *cb, void *app_key) { int ilevel, enum xer_encoder_flags_e flags,
SimpleType_inherit_TYPE_descriptor(td); asn_app_consume_bytes_f *cb, void *app_key) {
return td->print_struct(td, struct_ptr, ilevel, cb, app_key);
}
void
SimpleType_free(asn1_TYPE_descriptor_t *td,
void *struct_ptr, int contents_only) {
SimpleType_inherit_TYPE_descriptor(td); SimpleType_inherit_TYPE_descriptor(td);
td->free_struct(td, struct_ptr, contents_only); return td->xer_encoder(td, structure, ilevel, flags, cb, app_key);
} }
...@@ -149,11 +163,13 @@ static ber_tlv_tag_t asn1_DEF_SimpleType_tags[] = { ...@@ -149,11 +163,13 @@ static ber_tlv_tag_t asn1_DEF_SimpleType_tags[] = {
}; };
asn1_TYPE_descriptor_t asn1_DEF_SimpleType = { asn1_TYPE_descriptor_t asn1_DEF_SimpleType = {
"SimpleType", "SimpleType",
SimpleType_free,
SimpleType_print,
SimpleType_constraint, SimpleType_constraint,
SimpleType_decode_ber, SimpleType_decode_ber,
SimpleType_encode_der, SimpleType_encode_der,
SimpleType_print, 0, /* Not implemented yet */
SimpleType_free, SimpleType_encode_xer,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn1_DEF_SimpleType_tags, asn1_DEF_SimpleType_tags,
sizeof(asn1_DEF_SimpleType_tags) sizeof(asn1_DEF_SimpleType_tags)
......
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