aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--skeletons/Makefile.am2
-rw-r--r--skeletons/Makefile.in2
-rw-r--r--skeletons/file-dependencies50
-rw-r--r--skeletons/tests/check-ber_tlv_tag.c146
4 files changed, 198 insertions, 2 deletions
diff --git a/skeletons/Makefile.am b/skeletons/Makefile.am
index 4a01bf3d..a029345c 100644
--- a/skeletons/Makefile.am
+++ b/skeletons/Makefile.am
@@ -1,7 +1,7 @@
SUBDIRS = tests
-dist_pkgdata_DATA = *.[ch]
+dist_pkgdata_DATA = *.[ch] file-dependencies
uninstall-local:
-@echo -n " "
-rm -f -r $(DESTDIR)$(pkgdatadir)
diff --git a/skeletons/Makefile.in b/skeletons/Makefile.in
index 53ddc102..ed4c177a 100644
--- a/skeletons/Makefile.in
+++ b/skeletons/Makefile.in
@@ -173,7 +173,7 @@ target_cpu = @target_cpu@
target_os = @target_os@
target_vendor = @target_vendor@
SUBDIRS = tests
-dist_pkgdata_DATA = *.[ch]
+dist_pkgdata_DATA = *.[ch] file-dependencies
all: all-recursive
.SUFFIXES:
diff --git a/skeletons/file-dependencies b/skeletons/file-dependencies
new file mode 100644
index 00000000..4c19c7a5
--- /dev/null
+++ b/skeletons/file-dependencies
@@ -0,0 +1,50 @@
+# This file contains dependency information for the asn1c compiler's skeletons.
+# Feel free to edit this file.
+# The format is like this:
+# <filename> <dependent-file> ...
+#
+# $Id$
+#
+
+BIT_STRING.h BIT_STRING.c
+BMPString.h BMPString.c
+BOOLEAN.h BOOLEAN.c
+ENUMERATED.h ENUMERATED.c INTEGER.h
+GeneralString.h GeneralString.c
+GeneralizedTime.h GeneralizedTime.c
+GraphicString.h GraphicString.c
+IA5String.h IA5String.c
+INTEGER.h INTEGER.c
+ISO646String.h ISO646String.c
+NULL.h NULL.c BOOLEAN.h
+NativeEnumerated.h NativeEnumerated.c NativeInteger.h
+NativeInteger.h NativeInteger.c INTEGER.h
+NumericString.h NumericString.c
+OBJECT_IDENTIFIER.h OBJECT_IDENTIFIER.c INTEGER.h
+ObjectDescriptor.h ObjectDescriptor.c GraphicString.h
+PrintableString.h PrintableString.c
+RELATIVE-OID.h RELATIVE-OID.c OBJECT-IDENTIFIER.h
+T61String.h T61String.c
+TeletexString.h TeletexString.c
+UTCTime.h UTCTime.c GeneralizedTime.h
+UTF8String.h UTF8String.c
+UniversalString.h UniversalString.c
+VideotexString.h VideotexString.c
+VisibleString.h VisibleString.c
+asn_SEQUENCE_OF.h asn_SEQUENCE_OF.c asn_SET_OF.h
+asn_SET_OF.h asn_SET_OF.c
+constr_CHOICE.h constr_CHOICE.c
+constr_SEQUENCE.h constr_SEQUENCE.c
+constr_SEQUENCE_OF.h constr_SEQUENCE_OF.c asn_SEQUENCE_OF.h
+constr_SET.h constr_SET.c
+constr_SET_OF.h constr_SET_OF.c asn_SET_OF.h
+
+COMMON-FILES: # This is a special section
+asn_types.h
+OCTET_STRING.h OCTET_STRING.c # This one is used too widely
+ber_decoder.h ber_decoder.c
+ber_tlv_length.h ber_tlv_length.c
+ber_tlv_tag.h ber_tlv_tag.c
+constr_TYPE.h constr_TYPE.c
+constraints.h constraints.c
+der_encoder.h der_encoder.c
diff --git a/skeletons/tests/check-ber_tlv_tag.c b/skeletons/tests/check-ber_tlv_tag.c
new file mode 100644
index 00000000..41184202
--- /dev/null
+++ b/skeletons/tests/check-ber_tlv_tag.c
@@ -0,0 +1,146 @@
+#include <stdio.h>
+#include <assert.h>
+
+#include <ber_tlv_tag.c>
+
+struct tag_control_s {
+ int taglen;
+ uint8_t tagbuf[8];
+
+ int correctly_decodable;
+
+ int tclass; /* Tag class */
+ ber_tlv_tag_t tvalue; /* Tag value */
+ int constr; /* Is it constructed? */
+} control[] = {
+ { 1, { 0x2 << 6 }, 1, ASN_TAG_CLASS_CONTEXT, 0, 0 },
+ { 1, { 0x2 << 6 | 32 | 1 }, 1, ASN_TAG_CLASS_CONTEXT, 1, 1 },
+ { 1, { 0x3 << 6 | 30 }, 1, ASN_TAG_CLASS_PRIVATE, 30, 0 },
+ { 1, { 29 }, 1, ASN_TAG_CLASS_UNIVERSAL, 29, 0 },
+ { 1, { 0xbf, 31 }, 0, ASN_TAG_CLASS_CONTEXT, 31, 1 },
+ { 2, { 0xbf, 31 }, 1, ASN_TAG_CLASS_CONTEXT, 31, 1 },
+ { 2, { 0xbf, 127 }, 1, ASN_TAG_CLASS_CONTEXT, 127, 1 },
+ { 2, { 0xbf, 129 }, 0, ASN_TAG_CLASS_CONTEXT, 127, 1 },
+ { 3, { 0xbf, 129, 0 }, 1, ASN_TAG_CLASS_CONTEXT, 128, 1 },
+ { 3, { 0xbf, 129, 1 }, 1, ASN_TAG_CLASS_CONTEXT, 129, 1 },
+ { 3, { 0xbf, 130, 0 }, 1, ASN_TAG_CLASS_CONTEXT, 256, 1 },
+ { 3, { 0xbf, 130, 1 }, 1, ASN_TAG_CLASS_CONTEXT, 257, 1 },
+ { 3, { 0xbf, 130, 0x81 }, 0, 0, 0, 0 },
+ { 4, { 0xbf, 130, 0x81, 2 }, 1, ASN_TAG_CLASS_CONTEXT, 32898, 1 },
+ { 4, { 0xbf, 130, 0x81, 0x82 }, 0, ASN_TAG_CLASS_CONTEXT, 32898, 1 },
+ { 5, { 0x1f, 130, 0x81, 0x82, 1 }, 1, 0, 4210945, 0 },
+ { 5, { 0x1f, 130, 0x81, 0x82, 2 }, 1, 0, 4210946, 0 },
+ { 5, { 0x1f, 0xff, 0x81, 0x82, 2 }, 1, 0, 266354946, 0 },
+ { 6, { 0x1f, 0xff, 0xff, 0x82, 0x80, 1 }, -1, 0, 266354946, 0 },
+ { 7, { 0x1f, 0x8E, 0x87, 0xAA, 0x95, 0x99, 3}, -1, 0, 4000000000UL, 0 },
+};
+
+
+static void check_decode(struct tag_control_s *ctrl);
+static void check_encode(struct tag_control_s *ctrl);
+
+int
+main() {
+ size_t i;
+
+ for(i = 0; i < sizeof(control) / sizeof(control[0]); i++) {
+ check_decode(&control[i]);
+ check_encode(&control[i]);
+ }
+
+ return 0;
+}
+
+static void
+check_decode(struct tag_control_s *ctrl) {
+ ber_tlv_tag_t tag = 123;
+ ber_tlv_tag_t tag1 = 124;
+ ber_tlv_tag_t tag2 = 125;
+ ssize_t size;
+
+ if(ctrl->correctly_decodable < 1) {
+ size = ber_fetch_tag(ctrl->tagbuf, ctrl->taglen, &tag1);
+ assert(size == ctrl->correctly_decodable);
+ return;
+ }
+
+ printf("Expecting ");
+ tag = (ctrl->tvalue << 2) | ctrl->tclass;
+ ber_tlv_tag_fwrite(tag, stdout);
+ printf(", got ");
+
+ size = ber_fetch_tag(ctrl->tagbuf, 0, &tag1);
+ assert(size == 0);
+
+ size = ber_fetch_tag(ctrl->tagbuf, ctrl->taglen, &tag1);
+ assert(size == ctrl->taglen);
+
+ size = ber_fetch_tag(ctrl->tagbuf, ctrl->taglen + 10, &tag2);
+ assert(size == ctrl->taglen);
+
+ ber_tlv_tag_fwrite(tag1, stdout);
+ printf("\n");
+
+ assert(tag1 == tag2);
+ assert(tag == tag1);
+
+ assert(ctrl->constr == BER_TLV_CONSTRUCTED(ctrl->tagbuf));
+}
+
+
+
+static void
+check_encode(struct tag_control_s *ctrl) {
+ uint8_t buf[16];
+ ber_tlv_tag_t tag;
+ int Filler = 0xDA;
+ ssize_t size;
+ ssize_t i;
+
+ tag = ctrl->tvalue << 2 | ctrl->tclass;
+
+ /*
+ * Testing buffer overruns.
+ */
+ for(i = 0; i < (int)sizeof(buf); i++) {
+ int j;
+
+ memset(buf, Filler, sizeof(buf));
+
+ size = ber_tlv_tag_serialize(tag, buf, i);
+ assert(size < (int)sizeof(buf));
+
+ if(size <= i) {
+ for(j = 0; j < size; j++) assert(buf[j] != Filler);
+ } else {
+ j = i;
+ }
+ for(; j < (int)sizeof(buf); j++) assert(buf[j] == Filler);
+ }
+
+ memset(buf, Filler, sizeof(buf));
+
+ size = ber_tlv_tag_serialize(tag, buf, sizeof(buf));
+ assert(size < (int)sizeof(buf));
+
+ for(i = 0; i < size; i++) assert(buf[i] != Filler);
+ for(; i < (int)sizeof(buf); i++) assert(buf[i] == Filler);
+
+ if(ctrl->correctly_decodable == 1) {
+ assert(size == ctrl->taglen);
+ }
+ if(ctrl->constr) *buf |= 0x20;
+
+ ber_tlv_tag_fwrite(tag, stdout);
+
+ printf(":");
+
+ for(i = 0; i < size; i++) {
+ printf(" %02x", buf[i]);
+ if(ctrl->correctly_decodable == 1) {
+ assert(ctrl->tagbuf[i] == buf[i]);
+ }
+ }
+ printf("\n");
+}
+