vlm | d3da851 | 2004-08-19 13:26:54 +0000 | [diff] [blame] | 1 | #include <OBJECT_IDENTIFIER.c> |
| 2 | #include <RELATIVE-OID.c> |
vlm | 69be6fa | 2004-10-21 12:23:47 +0000 | [diff] [blame] | 3 | #include <asn_codecs_prim.c> |
vlm | d3da851 | 2004-08-19 13:26:54 +0000 | [diff] [blame] | 4 | #include <ber_decoder.c> |
| 5 | #include <ber_tlv_length.c> |
| 6 | #include <ber_tlv_tag.c> |
| 7 | #include <der_encoder.c> |
vlm | 69be6fa | 2004-10-21 12:23:47 +0000 | [diff] [blame] | 8 | #include <xer_decoder.c> |
| 9 | #include <xer_support.c> |
vlm | d3da851 | 2004-08-19 13:26:54 +0000 | [diff] [blame] | 10 | #include <constraints.c> |
| 11 | |
vlm | 2e3dd3b | 2004-06-14 07:24:36 +0000 | [diff] [blame] | 12 | #include <sys/time.h> |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 13 | |
| 14 | static int |
| 15 | _print(const void *buffer, size_t size, void *app_key) { |
vlm | a97e224 | 2004-06-14 07:40:17 +0000 | [diff] [blame] | 16 | (void)app_key; |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 17 | fwrite(buffer, size, 1, stdout); |
| 18 | return 0; |
| 19 | } |
| 20 | |
| 21 | static void |
| 22 | check_OID(uint8_t *buf, size_t len, int *ck_buf, int ck_len) { |
| 23 | OBJECT_IDENTIFIER_t *oid; |
vlm | 9de248e | 2004-10-20 15:50:55 +0000 | [diff] [blame] | 24 | asn_dec_rval_t rval; |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 25 | unsigned long arcs[10]; |
| 26 | int alen; |
| 27 | int i; |
| 28 | |
| 29 | printf("Checking {"); |
vlm | a97e224 | 2004-06-14 07:40:17 +0000 | [diff] [blame] | 30 | for(i = 0; i < (int)len; i++) { printf("%s%02x", i?" ":"", buf[i]); } |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 31 | printf("} against {"); |
| 32 | for(i = 0; i < ck_len; i++) { printf("%s%d", i?" ":"", ck_buf[i]); } |
| 33 | printf("}\n"); |
| 34 | |
| 35 | oid = NULL; |
vlm | ef6355b | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 36 | rval = ber_decode(0, &asn_DEF_OBJECT_IDENTIFIER, (void *)&oid, buf, len); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 37 | assert(rval.code == RC_OK); |
| 38 | |
vlm | a97e224 | 2004-06-14 07:40:17 +0000 | [diff] [blame] | 39 | assert(oid->size == (ssize_t)len - 2); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 40 | |
| 41 | /* |
| 42 | * Print the contents for visual debugging. |
| 43 | */ |
| 44 | printf("OBJECT_IDENTIFIER_print() => "); |
vlm | ef6355b | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 45 | OBJECT_IDENTIFIER_print(&asn_DEF_OBJECT_IDENTIFIER, oid, 0, _print, 0); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 46 | printf("\n"); |
| 47 | |
vlm | 1255771 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 48 | memset(arcs, 'A', sizeof(arcs)); |
vlm | 2e3dd3b | 2004-06-14 07:24:36 +0000 | [diff] [blame] | 49 | alen = OBJECT_IDENTIFIER_get_arcs(oid, |
| 50 | arcs, sizeof(arcs[0]), sizeof(arcs)/sizeof(arcs[0])); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 51 | assert(alen > 0); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 52 | |
vlm | 903a213 | 2004-08-22 03:01:37 +0000 | [diff] [blame] | 53 | printf("OBJECT_IDENTIFIER_get_arcs() => {"); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 54 | /* |
| 55 | * Make sure they are equivalent. |
| 56 | */ |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 57 | for(i = 0; i < alen; i++) { |
| 58 | printf(" %lu", arcs[i]); |
vlm | 903a213 | 2004-08-22 03:01:37 +0000 | [diff] [blame] | 59 | if(alen == ck_len) { |
| 60 | assert(arcs[i] == (unsigned long)ck_buf[i]); |
| 61 | } |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 62 | } |
| 63 | printf(" }\n"); |
vlm | 903a213 | 2004-08-22 03:01:37 +0000 | [diff] [blame] | 64 | assert(alen == ck_len); |
| 65 | |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | static void |
| 69 | check_ROID(uint8_t *buf, size_t len, int *ck_buf, int ck_len) { |
| 70 | RELATIVE_OID_t *oid; |
vlm | 9de248e | 2004-10-20 15:50:55 +0000 | [diff] [blame] | 71 | asn_dec_rval_t rval; |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 72 | unsigned long arcs[10]; |
| 73 | int alen; |
| 74 | int i; |
| 75 | |
| 76 | printf("Checking {"); |
vlm | a97e224 | 2004-06-14 07:40:17 +0000 | [diff] [blame] | 77 | for(i = 0; i < (ssize_t)len; i++) { printf("%s%02x", i?" ":"", buf[i]); } |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 78 | printf("} against {"); |
| 79 | for(i = 0; i < ck_len; i++) { printf("%s%d", i?" ":"", ck_buf[i]); } |
| 80 | printf("}\n"); |
| 81 | |
| 82 | oid = NULL; |
vlm | ef6355b | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 83 | rval = ber_decode(0, &asn_DEF_RELATIVE_OID, (void *)&oid, buf, len); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 84 | assert(rval.code == RC_OK); |
| 85 | |
vlm | a97e224 | 2004-06-14 07:40:17 +0000 | [diff] [blame] | 86 | assert(oid->size == (ssize_t)len - 2); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 87 | |
| 88 | /* |
| 89 | * Print the contents for visual debugging. |
| 90 | */ |
| 91 | printf("RELATIVE_OID_print() => "); |
vlm | ef6355b | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 92 | RELATIVE_OID_print(&asn_DEF_RELATIVE_OID, oid, 0, _print, 0); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 93 | printf("\n"); |
| 94 | |
vlm | 1255771 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 95 | memset(arcs, 'A', sizeof(arcs)); |
vlm | 2e3dd3b | 2004-06-14 07:24:36 +0000 | [diff] [blame] | 96 | alen = RELATIVE_OID_get_arcs(oid, |
| 97 | arcs, sizeof(arcs[0]), sizeof(arcs)/sizeof(arcs[0])); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 98 | assert(alen > 0); |
| 99 | assert(alen == ck_len); |
| 100 | |
| 101 | /* |
| 102 | * Make sure they are equivalent. |
| 103 | */ |
| 104 | printf("RELATIVE_OID_get_arcs() => {"); |
| 105 | for(i = 0; i < alen; i++) { |
| 106 | printf(" %lu", (unsigned long)arcs[i]); |
vlm | a97e224 | 2004-06-14 07:40:17 +0000 | [diff] [blame] | 107 | assert(arcs[i] == (unsigned long)ck_buf[i]); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 108 | } |
| 109 | printf(" }\n"); |
| 110 | } |
| 111 | |
| 112 | /* |
| 113 | * Encode the specified array of arcs as RELATIVE-OID, decode it and compare. |
| 114 | */ |
| 115 | static void |
| 116 | check_REGEN(int *arcs, int acount) { |
| 117 | static RELATIVE_OID_t oid; |
| 118 | unsigned long tmp_arcs[10]; |
| 119 | int tmp_alen = 10; |
| 120 | int alen; |
| 121 | int ret; |
| 122 | int i; |
| 123 | |
vlm | 735e461 | 2006-07-13 09:22:34 +0000 | [diff] [blame] | 124 | if(0) { |
| 125 | fprintf(stderr, "Encoding (R) {"); |
| 126 | for(i = 0; i < acount; i++) { |
| 127 | fprintf(stderr, " %u", arcs[i]); |
| 128 | } |
| 129 | fprintf(stderr, " }\n"); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 130 | } |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 131 | |
vlm | 1255771 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 132 | ret = RELATIVE_OID_set_arcs(&oid, arcs, sizeof(arcs[0]), acount); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 133 | assert(ret == 0); |
| 134 | |
vlm | 1255771 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 135 | memset(tmp_arcs, 'A', sizeof(tmp_arcs)); |
vlm | 2e3dd3b | 2004-06-14 07:24:36 +0000 | [diff] [blame] | 136 | alen = RELATIVE_OID_get_arcs(&oid, tmp_arcs, |
| 137 | sizeof(tmp_arcs[0]), tmp_alen); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 138 | assert(alen >= 0); |
vlm | 1255771 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 139 | assert(alen <= tmp_alen); |
| 140 | assert(alen == acount); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 141 | |
vlm | 735e461 | 2006-07-13 09:22:34 +0000 | [diff] [blame] | 142 | if(0) { |
| 143 | fprintf(stderr, "Encoded (R) { "); |
| 144 | for(i = 0; i < alen; i++) { |
| 145 | fprintf(stderr, "%lu ", tmp_arcs[i]); fflush(stdout); |
| 146 | assert(arcs[i] == (int)tmp_arcs[i]); |
| 147 | } |
| 148 | fprintf(stderr, "}\n"); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 149 | } |
vlm | 735e461 | 2006-07-13 09:22:34 +0000 | [diff] [blame] | 150 | |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | /* |
| 154 | * Encode the specified array of arcs as OBJECT IDENTIFIER, |
| 155 | * decode it and compare. |
| 156 | */ |
| 157 | static void |
| 158 | check_REGEN_OID(int *arcs, int acount) { |
| 159 | static OBJECT_IDENTIFIER_t oid; |
| 160 | unsigned long tmp_arcs[10]; |
| 161 | int tmp_alen = 10; |
| 162 | int alen; |
| 163 | int ret; |
| 164 | int i; |
| 165 | |
vlm | 735e461 | 2006-07-13 09:22:34 +0000 | [diff] [blame] | 166 | if(0) { |
| 167 | fprintf(stderr, "Encoding (O) {"); |
| 168 | for(i = 0; i < acount; i++) { |
| 169 | fprintf(stderr, " %u", arcs[i]); |
| 170 | } |
| 171 | fprintf(stderr, " }\n"); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 172 | } |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 173 | |
vlm | 1255771 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 174 | ret = OBJECT_IDENTIFIER_set_arcs(&oid, arcs, sizeof(arcs[0]), acount); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 175 | assert(ret == 0); |
| 176 | |
vlm | 1255771 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 177 | memset(tmp_arcs, 'A', sizeof(tmp_arcs)); |
vlm | 2e3dd3b | 2004-06-14 07:24:36 +0000 | [diff] [blame] | 178 | alen = OBJECT_IDENTIFIER_get_arcs(&oid, |
| 179 | tmp_arcs, sizeof(tmp_arcs[0]), tmp_alen); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 180 | assert(alen >= 0); |
vlm | 1255771 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 181 | assert(alen <= tmp_alen); |
| 182 | assert(alen == acount); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 183 | |
vlm | 735e461 | 2006-07-13 09:22:34 +0000 | [diff] [blame] | 184 | if(0) { |
| 185 | fprintf(stderr, "Encoded (O) { "); |
| 186 | for(i = 0; i < alen; i++) { |
| 187 | fprintf(stderr, "%lu ", tmp_arcs[i]); fflush(stdout); |
| 188 | assert(arcs[i] == (int)tmp_arcs[i]); |
| 189 | } |
| 190 | fprintf(stderr, "}\n"); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 191 | } |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 192 | } |
vlm | 2e3dd3b | 2004-06-14 07:24:36 +0000 | [diff] [blame] | 193 | static int |
| 194 | check_speed() { |
| 195 | uint8_t buf[] = { 0x80 | 7, 0x80 | 2, 0x80 | 3, 0x80 | 4, 13 }; |
| 196 | int ret = 0; |
| 197 | int cycles = 100000000; |
| 198 | double a, b, c; |
| 199 | struct timeval tv; |
| 200 | unsigned long value; |
| 201 | int i; |
| 202 | |
vlm | a97e224 | 2004-06-14 07:40:17 +0000 | [diff] [blame] | 203 | ret = OBJECT_IDENTIFIER_get_single_arc(buf, sizeof(buf), 0, &value, sizeof(value)); |
vlm | 2e3dd3b | 2004-06-14 07:24:36 +0000 | [diff] [blame] | 204 | assert(ret == 0); |
| 205 | assert(value == 0x7040c20d); |
| 206 | |
| 207 | gettimeofday(&tv, 0); |
| 208 | a = tv.tv_sec + tv.tv_usec / 1000000.0; |
| 209 | for(i = 0; i < cycles; i++) { |
| 210 | ret = OBJECT_IDENTIFIER_get_single_arc(buf, sizeof(buf), 0, |
| 211 | &value, sizeof(value)); |
| 212 | } |
| 213 | assert(ret == 0); |
| 214 | assert(value == 0x7040c20d); |
| 215 | gettimeofday(&tv, 0); |
| 216 | b = tv.tv_sec + tv.tv_usec / 1000000.0; |
| 217 | for(i = 0; i < cycles; i++) { |
| 218 | ret = OBJECT_IDENTIFIER_get_single_arc(buf, sizeof(buf), 0, |
| 219 | &value, sizeof(value)); |
| 220 | } |
| 221 | assert(ret == 0); |
| 222 | assert(value == 0x7040c20d); |
| 223 | gettimeofday(&tv, 0); |
| 224 | c = tv.tv_sec + tv.tv_usec / 1000000.0; |
| 225 | |
| 226 | a = b - a; |
| 227 | b = c - b; |
| 228 | printf("Time for single_arc(): %f\n", a); |
| 229 | printf("Time for get_arc_l(): %f\n", b); |
| 230 | |
| 231 | return 0; |
| 232 | } |
| 233 | |
vlm | 1f73df2 | 2004-10-23 10:16:51 +0000 | [diff] [blame] | 234 | static void check_parse(const char *oid_txt, int retval) { |
| 235 | int ret; |
| 236 | long l[2]; |
vlm | 31feaf3 | 2005-03-10 11:50:24 +0000 | [diff] [blame] | 237 | const char *p; |
vlm | 1f73df2 | 2004-10-23 10:16:51 +0000 | [diff] [blame] | 238 | |
| 239 | ret = OBJECT_IDENTIFIER_parse_arcs(oid_txt, -1, l, 2, &p); |
| 240 | printf("[%s] => %d == %d\n", oid_txt, ret, retval); |
| 241 | assert(ret == retval); |
| 242 | assert(p >= oid_txt); |
| 243 | } |
| 244 | |
| 245 | static void check_xer(int expect_arcs, char *xer) { |
| 246 | asn_dec_rval_t rc; |
| 247 | RELATIVE_OID_t *st = 0; |
| 248 | long arcs[10]; |
| 249 | int ret; |
| 250 | int i; |
| 251 | |
| 252 | printf("[%s] => ", xer); fflush(stdout); |
| 253 | rc = asn_DEF_RELATIVE_OID.xer_decoder(0, |
| 254 | &asn_DEF_RELATIVE_OID, (void **)&st, "t", |
| 255 | xer, strlen(xer)); |
| 256 | if(expect_arcs == -1) { |
| 257 | if(rc.code != RC_OK) |
| 258 | return; |
| 259 | } |
| 260 | assert(rc.code == RC_OK); |
| 261 | |
| 262 | ret = RELATIVE_OID_get_arcs(st, arcs, sizeof(arcs[0]), |
| 263 | sizeof(arcs)/sizeof(arcs[0])); |
| 264 | assert(ret < 10); |
| 265 | if(expect_arcs == -1) { |
| 266 | assert(ret == -1); |
| 267 | return; |
| 268 | } |
| 269 | for(i = 0; i < ret; i++) { |
| 270 | if(i) printf("."); |
| 271 | printf("%ld", arcs[i]); |
| 272 | assert(arcs[i] == i + 1); |
| 273 | } |
| 274 | printf(": %d == %d\n", ret, expect_arcs); |
| 275 | assert(ret == expect_arcs); |
| 276 | } |
| 277 | |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 278 | #define CHECK_OID(n) check_OID(buf ## n, sizeof(buf ## n), \ |
| 279 | buf ## n ## _check, \ |
| 280 | sizeof(buf ## n ## _check)/sizeof(buf ## n ## _check[0])) |
| 281 | #define CHECK_ROID(n) check_ROID(buf ## n, sizeof(buf ## n), \ |
| 282 | buf ## n ## _check, \ |
| 283 | sizeof(buf ## n ## _check)/sizeof(buf ## n ## _check[0])) |
| 284 | #define CHECK_REGEN(n) check_REGEN(buf ## n ## _check, \ |
| 285 | sizeof(buf ## n ## _check)/sizeof(buf ## n ## _check[0])) |
| 286 | #define CHECK_REGEN_OID(n) check_REGEN_OID(buf ## n ## _check, \ |
| 287 | sizeof(buf ## n ## _check)/sizeof(buf ## n ## _check[0])) |
| 288 | |
| 289 | int |
vlm | a97e224 | 2004-06-14 07:40:17 +0000 | [diff] [blame] | 290 | main() { |
vlm | 1255771 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 291 | int i; |
| 292 | |
vlm | 2e3dd3b | 2004-06-14 07:24:36 +0000 | [diff] [blame] | 293 | /* {joint-iso-itu-t 230 3} */ |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 294 | uint8_t buf1[] = { |
| 295 | 0x06, /* OBJECT IDENTIFIER */ |
| 296 | 0x03, /* Length */ |
vlm | 2e3dd3b | 2004-06-14 07:24:36 +0000 | [diff] [blame] | 297 | 0x82, 0x36, 0x03 |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 298 | }; |
vlm | 2e3dd3b | 2004-06-14 07:24:36 +0000 | [diff] [blame] | 299 | int buf1_check[] = { 2, 230, 3 }; |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 300 | |
| 301 | /* {8571 3 2} */ |
| 302 | uint8_t buf2[] = { |
| 303 | 0x0D, /* RELATIVE-OID */ |
| 304 | 0x04, /* Length */ |
| 305 | 0xC2, 0x7B, 0x03, 0x02 |
| 306 | }; |
| 307 | int buf2_check[] = { 8571, 3, 2 }; |
| 308 | |
vlm | 1255771 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 309 | /* {joint-iso-itu-t 42 } */ |
| 310 | uint8_t buf3[] = { |
| 311 | 0x06, /* OBJECT IDENTIFIER */ |
| 312 | 0x01, /* Length */ |
| 313 | 0x7A |
| 314 | }; |
| 315 | int buf3_check[] = { 2, 42 }; |
| 316 | |
| 317 | /* {joint-iso-itu-t 25957 } */ |
| 318 | uint8_t buf4[] = { |
| 319 | 0x06, /* OBJECT IDENTIFIER */ |
| 320 | 0x03, /* Length */ |
| 321 | 0x81, 0x80 + 0x4B, 0x35 |
| 322 | }; |
| 323 | int buf4_check[] = { 2, 25957 }; |
| 324 | |
| 325 | int buf5_check[] = { 0 }; |
| 326 | int buf6_check[] = { 1 }; |
| 327 | int buf7_check[] = { 80, 40 }; |
| 328 | int buf8_check[] = { 127 }; |
| 329 | int buf9_check[] = { 128 }; |
| 330 | int buf10_check[] = { 65535, 65536 }; |
| 331 | int buf11_check[] = { 100000, 0x20000, 1234, 256, 127, 128 }; |
| 332 | int buf12_check[] = { 0, 0xffffffff, 0xff00ff00, 0 }; |
| 333 | int buf13_check[] = { 0, 1, 2 }; |
| 334 | int buf14_check[] = { 1, 38, 3 }; |
| 335 | int buf15_check[] = { 0, 0, 0xf000 }; |
| 336 | int buf16_check[] = { 0, 0, 0, 1, 0 }; |
| 337 | int buf17_check[] = { 2, 0xffffffAf, 0xff00ff00, 0 }; |
vlm | 903a213 | 2004-08-22 03:01:37 +0000 | [diff] [blame] | 338 | int buf18_check[] = { 2, 2, 1, 1 }; |
| 339 | |
| 340 | /* { joint-iso-itu-t 2 1 1 } */ |
| 341 | uint8_t buf19[] = { |
| 342 | 0x06, /* OBJECT IDENTIFIER */ |
| 343 | 0x03, /* Length */ |
| 344 | 0x52, 0x01, 0x01 |
| 345 | }; |
| 346 | int buf19_check[] = { 2, 2, 1, 1 }; |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 347 | |
vlm | 3fff06b | 2004-08-23 09:23:02 +0000 | [diff] [blame] | 348 | /* { joint-iso-itu-t 2 1 0 1 } */ |
| 349 | uint8_t buf20[] = { |
| 350 | 0x06, /* OBJECT IDENTIFIER */ |
| 351 | 0x04, /* Length */ |
| 352 | 0x52, 0x01, 0x00, 0x01 |
| 353 | }; |
| 354 | int buf20_check[] = { 2, 2, 1, 0, 1 }; |
| 355 | |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 356 | |
| 357 | CHECK_OID(1); /* buf1, buf1_check */ |
| 358 | CHECK_ROID(2); /* buf2, buf2_check */ |
vlm | 1255771 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 359 | CHECK_OID(3); /* buf3, buf3_check */ |
| 360 | CHECK_OID(4); /* buf4, buf4_check */ |
vlm | 903a213 | 2004-08-22 03:01:37 +0000 | [diff] [blame] | 361 | CHECK_OID(19); /* buf19, buf19_check */ |
vlm | 3fff06b | 2004-08-23 09:23:02 +0000 | [diff] [blame] | 362 | CHECK_OID(20); /* buf20, buf20_check */ |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 363 | |
vlm | 1255771 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 364 | CHECK_REGEN(5); /* Regenerate RELATIVE-OID */ |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 365 | CHECK_REGEN(6); |
| 366 | CHECK_REGEN(7); |
| 367 | CHECK_REGEN(8); |
| 368 | CHECK_REGEN(9); |
| 369 | CHECK_REGEN(10); |
vlm | 1255771 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 370 | CHECK_REGEN(11); |
| 371 | CHECK_REGEN(12); |
| 372 | CHECK_REGEN(13); |
| 373 | CHECK_REGEN(14); |
| 374 | CHECK_REGEN(15); |
| 375 | CHECK_REGEN(16); |
| 376 | CHECK_REGEN(17); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 377 | CHECK_REGEN_OID(1); /* Regenerate OBJECT IDENTIFIER */ |
vlm | 1255771 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 378 | CHECK_REGEN_OID(3); /* Regenerate OBJECT IDENTIFIER */ |
| 379 | CHECK_REGEN_OID(4); /* Regenerate OBJECT IDENTIFIER */ |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 380 | CHECK_REGEN_OID(13); |
vlm | 1255771 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 381 | CHECK_REGEN_OID(14); |
| 382 | CHECK_REGEN_OID(15); |
| 383 | CHECK_REGEN_OID(16); |
| 384 | CHECK_REGEN_OID(17); |
vlm | 903a213 | 2004-08-22 03:01:37 +0000 | [diff] [blame] | 385 | CHECK_REGEN_OID(18); |
vlm | 3fff06b | 2004-08-23 09:23:02 +0000 | [diff] [blame] | 386 | CHECK_REGEN_OID(19); |
| 387 | CHECK_REGEN_OID(20); |
vlm | 1255771 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 388 | |
vlm | 1f73df2 | 2004-10-23 10:16:51 +0000 | [diff] [blame] | 389 | check_parse("", 0); |
| 390 | check_parse(" ", 0); |
| 391 | check_parse(" ", 0); |
| 392 | check_parse(".", -1); |
| 393 | check_parse(" .", -1); |
| 394 | check_parse(" 1", 1); |
| 395 | check_parse(" 1.2", 2); |
| 396 | check_parse(" 1.", -1); |
| 397 | check_parse(" 1. ", -1); |
| 398 | check_parse("1. ", -1); |
| 399 | check_parse("1.2", 2); |
| 400 | check_parse("10.30.234.234", 4); |
| 401 | check_parse("10.30.234.234 ", 4); |
| 402 | check_parse("10.30.234. 234 ", -1); |
| 403 | check_parse("10.30.234.234.", -1); |
| 404 | check_parse("1.2000000000.3", 3); |
| 405 | check_parse("1.2147483647.3", 3); |
| 406 | if(sizeof(long) == 4) { |
| 407 | check_parse("1.2147483648.3", -1); /* overflow on ILP32 */ |
| 408 | check_parse("1.3000000000.3", -1); |
| 409 | check_parse("1.4000000000.3", -1); |
| 410 | check_parse("1.5000000000.3", -1); |
| 411 | check_parse("1.6000000000.3", -1); |
| 412 | check_parse("1.9000000000.3", -1); |
| 413 | } else { |
| 414 | check_parse("1.2147483648.3", 3); |
| 415 | } |
| 416 | check_parse("1.900a0000000.3", -1); |
| 417 | check_parse("1.900a.3", -1); |
| 418 | |
| 419 | check_xer(0, "<t></t>"); |
| 420 | check_xer(2, "<t>1.2</t>"); |
| 421 | check_xer(3, "<t>1.2.3</t>"); |
| 422 | check_xer(3, "<t> 1.2.3 </t>"); |
| 423 | check_xer(-1, "<t>1.2.3 1</t>"); |
| 424 | |
vlm | 1255771 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 425 | for(i = 0; i < 100000; i++) { |
| 426 | int bufA_check[3] = { 2, i, rand() }; |
| 427 | int bufB_check[2] = { rand(), i * 121 }; |
| 428 | CHECK_REGEN(A); |
| 429 | CHECK_REGEN_OID(A); |
| 430 | CHECK_REGEN(B); |
| 431 | if(i > 100) i++; |
| 432 | if(i > 500) i++; |
| 433 | if(i > 1000) i += 3; |
| 434 | if(i > 5000) i += 151; |
| 435 | } |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 436 | |
vlm | 3717fb3 | 2004-06-14 08:17:27 +0000 | [diff] [blame] | 437 | if(getenv("CHECK_SPEED")) { |
| 438 | /* Useful for developers only */ |
| 439 | check_speed(); |
| 440 | } |
vlm | 2e3dd3b | 2004-06-14 07:24:36 +0000 | [diff] [blame] | 441 | |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 442 | return 0; |
| 443 | } |