Skip to content

Commit

Permalink
Merge pull request vlm#5 from velichkov/external-gh140_mouse07410_115
Browse files Browse the repository at this point in the history
Add EXTERNAL support. vlm#140
  • Loading branch information
mouse07410 committed Mar 27, 2017
2 parents ab3ae38 + 25dd8ac commit b5424fa
Show file tree
Hide file tree
Showing 62 changed files with 10,334 additions and 10,194 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ doc/docsrc/*.xdv

# /libasn1parser/
/libasn1parser/check_parser
/libasn1parser/asn1p_l.c
/libasn1parser/asn1p_y.c
/libasn1parser/asn1p_y.h

# /skeletons/tests/
/skeletons/tests/check-*
Expand Down
2 changes: 1 addition & 1 deletion TODO
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@

2. MEDIUM:

2.1 Support for EXTERNAL, EMBEDDED-PDV and CHARACTER STRING types.
2.1 Support for EMBEDDED-PDV and CHARACTER STRING types.
Requires something from 1.2 (Information Object Classes).
1 change: 1 addition & 0 deletions asn1c/tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ TESTS += check-src/check-127.-gen-PER.c
TESTS += check-src/check-131.-gen-PER.c
TESTS += check-src/check-132.-gen-PER.c
TESTS += check-src/check-133.-gen-PER.c
TESTS += check-src/check-135.c
TESTS += check-src/check-19.c
TESTS += check-src/check-22.-fwide-types.c
TESTS += check-src/check-24.-fwide-types.c
Expand Down
135 changes: 135 additions & 0 deletions asn1c/tests/check-src/check-135.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
#undef NDEBUG
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <string.h>
#include <assert.h>

#include "T.h"


uint8_t buf1[] = {
0x28,0x18,
0x06,0x07,0x00,0x11,0x86,0x05,0x01,0x01,0x01,
0xa0,0x0d,
0x60,0x0b,
0xa1,0x09,
0x06,0x07,0x04,0x00,0x00,0x01,0x00,0x05,0x03
};


uint8_t buf1_reconstr[] = {
0x28,0x18,
0x06,0x07,0x00,0x11,0x86,0x05,0x01,0x01,0x01,
0xa0,0x0d,
0x60,0x0b,
0xa1,0x09,
0x06,0x07,0x04,0x00,0x00,0x01,0x00,0x05,0x03
};


static void
check(T_t *tp, uint8_t *buf, size_t size, size_t consumed) {
asn_dec_rval_t rval;

tp = memset(tp, 0, sizeof(*tp));

fprintf(stderr, "Buf %p (%zd)\n", buf, size);
rval = ber_decode(0, &asn_DEF_T, (void **)&tp, buf, size);
fprintf(stderr, "Returned code %d, consumed %zd\n",
(int)rval.code, rval.consumed);

assert(rval.code == RC_OK);
assert(rval.consumed == consumed);

const uint8_t direct_reference[] = {0x00,0x11,0x86,0x05,0x01,0x01,0x01};
assert(tp->direct_reference);
assert(tp->direct_reference->size == sizeof(direct_reference));
assert(memcmp(tp->direct_reference->buf, direct_reference,
sizeof(direct_reference)) == 0);

assert(tp->indirect_reference == NULL);
assert(tp->data_value_descriptor == NULL);

const uint8_t single_asn1_type[] = {
0x60,0x0b,0xa1,0x09,0x06,0x07,0x04,0x00,0x00,0x01,0x00,0x05,0x03};
assert(tp->encoding.present == encoding_PR_single_ASN1_type);
assert(tp->encoding.choice.single_ASN1_type.size == sizeof(single_asn1_type));
assert(memcmp(tp->encoding.choice.single_ASN1_type.buf, single_asn1_type,
sizeof(single_asn1_type)) == 0);
}

size_t buf_pos;
size_t buf_size;
uint8_t *buf;

static int
buf_fill(const void *buffer, size_t size, void *app_key) {

(void)app_key; /* Unused argument */

if(buf_pos + size > buf_size) {
fprintf(stderr, "%zd + %zd > %zd\n",
buf_pos, size, buf_size);
return -1;
}

memcpy(buf + buf_pos, buffer, size);
buf_pos += size;
fprintf(stderr, " written %zd (%zd)\n", size, buf_pos);

return 0;
}

static void
compare(T_t *tp, uint8_t *cmp_buf, ssize_t cmp_buf_size) {
asn_enc_rval_t erval;
int i;

buf_size = cmp_buf_size + 100;
buf = alloca(buf_size);
buf_pos = 0;

/*
* Try to re-create using DER encoding.
*/
erval = der_encode(&asn_DEF_T, tp, buf_fill, 0);
assert(erval.encoded != -1);
if(erval.encoded != cmp_buf_size) {
printf("%zd != %zd\n", erval.encoded, cmp_buf_size);
}
assert(erval.encoded == cmp_buf_size);
for(i = 0; i < cmp_buf_size; i++) {
if(buf[i] != cmp_buf[i]) {
fprintf(stderr, "Recreated buffer content mismatch:\n");
fprintf(stderr, "Byte %d, %x != %x (%d != %d)\n",
i,
buf[i], cmp_buf[i],
buf[i], cmp_buf[i]
);
}
assert(buf[i] == cmp_buf[i]);
}
}

int
main(int ac, char **av) {
T_t t;

(void)ac; /* Unused argument */
(void)av; /* Unused argument */

/* Check exact buf1 */
check(&t, buf1, sizeof(buf1), sizeof(buf1));
compare(&t, buf1_reconstr, sizeof(buf1_reconstr));
asn_fprint(stderr, &asn_DEF_T, &t);
asn_DEF_T.free_struct(&asn_DEF_T, &t, 1);

/* Check slightly more than buf1 */
check(&t, buf1, sizeof(buf1) + 10, sizeof(buf1));
compare(&t, buf1_reconstr, sizeof(buf1_reconstr));
asn_fprint(stderr, &asn_DEF_T, &t);
asn_DEF_T.free_struct(&asn_DEF_T, &t, 1);

return 0;
}
5 changes: 4 additions & 1 deletion libasn1parser/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ AM_LFLAGS = -s -p -Cem -Pasn1p_ -olex.yy.c

noinst_LTLIBRARIES = libasn1parser.la

BUILT_SOURCES = asn1p_y.h

libasn1parser_la_SOURCES = \
asn1parser.c asn1parser.h \
asn1p_y.c asn1p_y.h asn1p_l.c \
asn1p_y.y \
asn1p_l.l \
asn1p_module.c asn1p_module.h \
asn1p_oid.c asn1p_oid.h \
asn1p_value.c asn1p_value.h \
Expand Down
Loading

0 comments on commit b5424fa

Please sign in to comment.