5 #include <asn_internal.h>
6 #include <ber_tlv_tag.h>
12 int correctly_decodable;
14 int tclass; /* Tag class */
15 ber_tlv_tag_t tvalue; /* Tag value */
16 int constr; /* Is it constructed? */
18 { 1, { 0x2 << 6 }, 1, ASN_TAG_CLASS_CONTEXT, 0, 0 },
19 { 1, { 0x2 << 6 | 32 | 1 }, 1, ASN_TAG_CLASS_CONTEXT, 1, 1 },
20 { 1, { 0x3 << 6 | 30 }, 1, ASN_TAG_CLASS_PRIVATE, 30, 0 },
21 { 1, { 29 }, 1, ASN_TAG_CLASS_UNIVERSAL, 29, 0 },
22 { 1, { 0xbf, 31 }, 0, ASN_TAG_CLASS_CONTEXT, 31, 1 },
23 { 2, { 0xbf, 31 }, 1, ASN_TAG_CLASS_CONTEXT, 31, 1 },
24 { 2, { 0xbf, 83 }, 1, ASN_TAG_CLASS_CONTEXT, 83, 1 },
25 { 2, { 0xbf, 127 }, 1, ASN_TAG_CLASS_CONTEXT, 127, 1 },
26 { 2, { 0xbf, 129 }, 0, ASN_TAG_CLASS_CONTEXT, 127, 1 },
27 { 3, { 0xbf, 129, 0 }, 1, ASN_TAG_CLASS_CONTEXT, 128, 1 },
28 { 3, { 0xbf, 129, 1 }, 1, ASN_TAG_CLASS_CONTEXT, 129, 1 },
29 { 3, { 0xbf, 130, 0 }, 1, ASN_TAG_CLASS_CONTEXT, 256, 1 },
30 { 3, { 0xbf, 130, 1 }, 1, ASN_TAG_CLASS_CONTEXT, 257, 1 },
31 { 3, { 0xbf, 130, 0x81 }, 0, 0, 0, 0 },
32 { 4, { 0xbf, 130, 0x81, 2 }, 1, ASN_TAG_CLASS_CONTEXT, 32898, 1 },
33 { 4, { 0xbf, 130, 0x81, 0x82 }, 0, ASN_TAG_CLASS_CONTEXT, 32898, 1 },
34 { 5, { 0x1f, 130, 0x81, 0x82, 1 }, 1, 0, 4210945, 0 },
35 { 5, { 0x1f, 130, 0x81, 0x82, 2 }, 1, 0, 4210946, 0 },
36 { 5, { 0x1f, 0xff, 0x81, 0x82, 2 }, 1, 0, 266354946, 0 },
37 { 6, { 0x1f, 0xff, 0xff, 0x82, 0x80, 1 }, -1, 0, 266354946, 0 },
38 { 7, { 0x1f, 0x8E, 0x87, 0xAA, 0x95, 0x99, 3}, -1, 0, 4000000000UL, 0 },
42 static void check_decode(struct tag_control_s *ctrl);
43 static void check_encode(struct tag_control_s *ctrl);
49 for(i = 0; i < sizeof(control) / sizeof(control[0]); i++) {
50 check_decode(&control[i]);
51 check_encode(&control[i]);
58 check_decode(struct tag_control_s *ctrl) {
59 ber_tlv_tag_t tag = 123;
60 ber_tlv_tag_t tag1 = 124;
61 ber_tlv_tag_t tag2 = 125;
64 if(ctrl->correctly_decodable < 1) {
65 size = ber_fetch_tag(ctrl->tagbuf, ctrl->taglen, &tag1);
66 assert(size == ctrl->correctly_decodable);
71 tag = (ctrl->tvalue << 2) | ctrl->tclass;
72 ber_tlv_tag_fwrite(tag, stdout);
75 size = ber_fetch_tag(ctrl->tagbuf, 0, &tag1);
78 size = ber_fetch_tag(ctrl->tagbuf, ctrl->taglen, &tag1);
79 assert(size == ctrl->taglen);
81 size = ber_fetch_tag(ctrl->tagbuf, ctrl->taglen + 10, &tag2);
82 assert(size == ctrl->taglen);
84 ber_tlv_tag_fwrite(tag1, stdout);
90 assert(ctrl->constr == BER_TLV_CONSTRUCTED(ctrl->tagbuf));
96 check_encode(struct tag_control_s *ctrl) {
103 tag = ctrl->tvalue << 2 | ctrl->tclass;
106 * Testing buffer overruns.
108 for(i = 0; i < (int)sizeof(buf); i++) {
111 memset(buf, Filler, sizeof(buf));
113 size = ber_tlv_tag_serialize(tag, buf, i);
114 assert(size < (int)sizeof(buf));
117 for(j = 0; j < size; j++) assert(buf[j] != Filler);
121 for(; j < (int)sizeof(buf); j++) assert(buf[j] == Filler);
124 memset(buf, Filler, sizeof(buf));
126 size = ber_tlv_tag_serialize(tag, buf, sizeof(buf));
127 assert(size < (int)sizeof(buf));
129 for(i = 0; i < size; i++) assert(buf[i] != Filler);
130 for(; i < (int)sizeof(buf); i++) assert(buf[i] == Filler);
132 if(ctrl->correctly_decodable == 1) {
133 assert(size == ctrl->taglen);
135 if(ctrl->constr) *buf |= 0x20;
137 ber_tlv_tag_fwrite(tag, stdout);
141 for(i = 0; i < size; i++) {
142 printf(" %02x", buf[i]);
143 if(ctrl->correctly_decodable == 1) {
144 assert(ctrl->tagbuf[i] == buf[i]);