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 | 1255771 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 124 | printf("Encoding (R) {"); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 125 | for(i = 0; i < acount; i++) { |
| 126 | printf(" %u", arcs[i]); |
| 127 | } |
| 128 | printf(" }\n"); |
| 129 | |
vlm | 1255771 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 130 | ret = RELATIVE_OID_set_arcs(&oid, arcs, sizeof(arcs[0]), acount); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 131 | assert(ret == 0); |
| 132 | |
vlm | 1255771 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 133 | memset(tmp_arcs, 'A', sizeof(tmp_arcs)); |
vlm | 2e3dd3b | 2004-06-14 07:24:36 +0000 | [diff] [blame] | 134 | alen = RELATIVE_OID_get_arcs(&oid, tmp_arcs, |
| 135 | sizeof(tmp_arcs[0]), tmp_alen); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 136 | assert(alen >= 0); |
vlm | 1255771 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 137 | assert(alen <= tmp_alen); |
| 138 | assert(alen == acount); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 139 | |
vlm | 1255771 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 140 | printf("Encoded (R) {"); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 141 | for(i = 0; i < alen; i++) { |
| 142 | printf(" %lu", tmp_arcs[i]); |
vlm | a97e224 | 2004-06-14 07:40:17 +0000 | [diff] [blame] | 143 | assert((unsigned long)arcs[i] == tmp_arcs[i]); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 144 | } |
| 145 | printf(" }\n"); |
| 146 | } |
| 147 | |
| 148 | /* |
| 149 | * Encode the specified array of arcs as OBJECT IDENTIFIER, |
| 150 | * decode it and compare. |
| 151 | */ |
| 152 | static void |
| 153 | check_REGEN_OID(int *arcs, int acount) { |
| 154 | static OBJECT_IDENTIFIER_t oid; |
| 155 | unsigned long tmp_arcs[10]; |
| 156 | int tmp_alen = 10; |
| 157 | int alen; |
| 158 | int ret; |
| 159 | int i; |
| 160 | |
vlm | 1255771 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 161 | printf("Encoding (O) {"); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 162 | for(i = 0; i < acount; i++) { |
| 163 | printf(" %u", arcs[i]); |
| 164 | } |
| 165 | printf(" }\n"); |
| 166 | |
vlm | 1255771 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 167 | ret = OBJECT_IDENTIFIER_set_arcs(&oid, arcs, sizeof(arcs[0]), acount); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 168 | assert(ret == 0); |
| 169 | |
vlm | 1255771 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 170 | memset(tmp_arcs, 'A', sizeof(tmp_arcs)); |
vlm | 2e3dd3b | 2004-06-14 07:24:36 +0000 | [diff] [blame] | 171 | alen = OBJECT_IDENTIFIER_get_arcs(&oid, |
| 172 | tmp_arcs, sizeof(tmp_arcs[0]), tmp_alen); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 173 | assert(alen >= 0); |
vlm | 1255771 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 174 | assert(alen <= tmp_alen); |
| 175 | assert(alen == acount); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 176 | |
vlm | 1255771 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 177 | printf("Encoded (O) { "); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 178 | for(i = 0; i < alen; i++) { |
vlm | 1255771 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 179 | printf("%lu ", tmp_arcs[i]); fflush(stdout); |
vlm | a97e224 | 2004-06-14 07:40:17 +0000 | [diff] [blame] | 180 | assert((unsigned long)arcs[i] == tmp_arcs[i]); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 181 | } |
vlm | 1255771 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 182 | printf("}\n"); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 183 | } |
| 184 | |
vlm | 2e3dd3b | 2004-06-14 07:24:36 +0000 | [diff] [blame] | 185 | static int |
| 186 | check_speed() { |
| 187 | uint8_t buf[] = { 0x80 | 7, 0x80 | 2, 0x80 | 3, 0x80 | 4, 13 }; |
| 188 | int ret = 0; |
| 189 | int cycles = 100000000; |
| 190 | double a, b, c; |
| 191 | struct timeval tv; |
| 192 | unsigned long value; |
| 193 | int i; |
| 194 | |
vlm | a97e224 | 2004-06-14 07:40:17 +0000 | [diff] [blame] | 195 | ret = OBJECT_IDENTIFIER_get_single_arc(buf, sizeof(buf), 0, &value, sizeof(value)); |
vlm | 2e3dd3b | 2004-06-14 07:24:36 +0000 | [diff] [blame] | 196 | assert(ret == 0); |
| 197 | assert(value == 0x7040c20d); |
| 198 | |
| 199 | gettimeofday(&tv, 0); |
| 200 | a = tv.tv_sec + tv.tv_usec / 1000000.0; |
| 201 | for(i = 0; i < cycles; i++) { |
| 202 | ret = OBJECT_IDENTIFIER_get_single_arc(buf, sizeof(buf), 0, |
| 203 | &value, sizeof(value)); |
| 204 | } |
| 205 | assert(ret == 0); |
| 206 | assert(value == 0x7040c20d); |
| 207 | gettimeofday(&tv, 0); |
| 208 | b = 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 | c = tv.tv_sec + tv.tv_usec / 1000000.0; |
| 217 | |
| 218 | a = b - a; |
| 219 | b = c - b; |
| 220 | printf("Time for single_arc(): %f\n", a); |
| 221 | printf("Time for get_arc_l(): %f\n", b); |
| 222 | |
| 223 | return 0; |
| 224 | } |
| 225 | |
vlm | 1f73df2 | 2004-10-23 10:16:51 +0000 | [diff] [blame] | 226 | static void check_parse(const char *oid_txt, int retval) { |
| 227 | int ret; |
| 228 | long l[2]; |
| 229 | char *p; |
| 230 | |
| 231 | ret = OBJECT_IDENTIFIER_parse_arcs(oid_txt, -1, l, 2, &p); |
| 232 | printf("[%s] => %d == %d\n", oid_txt, ret, retval); |
| 233 | assert(ret == retval); |
| 234 | assert(p >= oid_txt); |
| 235 | } |
| 236 | |
| 237 | static void check_xer(int expect_arcs, char *xer) { |
| 238 | asn_dec_rval_t rc; |
| 239 | RELATIVE_OID_t *st = 0; |
| 240 | long arcs[10]; |
| 241 | int ret; |
| 242 | int i; |
| 243 | |
| 244 | printf("[%s] => ", xer); fflush(stdout); |
| 245 | rc = asn_DEF_RELATIVE_OID.xer_decoder(0, |
| 246 | &asn_DEF_RELATIVE_OID, (void **)&st, "t", |
| 247 | xer, strlen(xer)); |
| 248 | if(expect_arcs == -1) { |
| 249 | if(rc.code != RC_OK) |
| 250 | return; |
| 251 | } |
| 252 | assert(rc.code == RC_OK); |
| 253 | |
| 254 | ret = RELATIVE_OID_get_arcs(st, arcs, sizeof(arcs[0]), |
| 255 | sizeof(arcs)/sizeof(arcs[0])); |
| 256 | assert(ret < 10); |
| 257 | if(expect_arcs == -1) { |
| 258 | assert(ret == -1); |
| 259 | return; |
| 260 | } |
| 261 | for(i = 0; i < ret; i++) { |
| 262 | if(i) printf("."); |
| 263 | printf("%ld", arcs[i]); |
| 264 | assert(arcs[i] == i + 1); |
| 265 | } |
| 266 | printf(": %d == %d\n", ret, expect_arcs); |
| 267 | assert(ret == expect_arcs); |
| 268 | } |
| 269 | |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 270 | #define CHECK_OID(n) check_OID(buf ## n, sizeof(buf ## n), \ |
| 271 | buf ## n ## _check, \ |
| 272 | sizeof(buf ## n ## _check)/sizeof(buf ## n ## _check[0])) |
| 273 | #define CHECK_ROID(n) check_ROID(buf ## n, sizeof(buf ## n), \ |
| 274 | buf ## n ## _check, \ |
| 275 | sizeof(buf ## n ## _check)/sizeof(buf ## n ## _check[0])) |
| 276 | #define CHECK_REGEN(n) check_REGEN(buf ## n ## _check, \ |
| 277 | sizeof(buf ## n ## _check)/sizeof(buf ## n ## _check[0])) |
| 278 | #define CHECK_REGEN_OID(n) check_REGEN_OID(buf ## n ## _check, \ |
| 279 | sizeof(buf ## n ## _check)/sizeof(buf ## n ## _check[0])) |
| 280 | |
| 281 | int |
vlm | a97e224 | 2004-06-14 07:40:17 +0000 | [diff] [blame] | 282 | main() { |
vlm | 1255771 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 283 | int i; |
| 284 | |
vlm | 2e3dd3b | 2004-06-14 07:24:36 +0000 | [diff] [blame] | 285 | /* {joint-iso-itu-t 230 3} */ |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 286 | uint8_t buf1[] = { |
| 287 | 0x06, /* OBJECT IDENTIFIER */ |
| 288 | 0x03, /* Length */ |
vlm | 2e3dd3b | 2004-06-14 07:24:36 +0000 | [diff] [blame] | 289 | 0x82, 0x36, 0x03 |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 290 | }; |
vlm | 2e3dd3b | 2004-06-14 07:24:36 +0000 | [diff] [blame] | 291 | int buf1_check[] = { 2, 230, 3 }; |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 292 | |
| 293 | /* {8571 3 2} */ |
| 294 | uint8_t buf2[] = { |
| 295 | 0x0D, /* RELATIVE-OID */ |
| 296 | 0x04, /* Length */ |
| 297 | 0xC2, 0x7B, 0x03, 0x02 |
| 298 | }; |
| 299 | int buf2_check[] = { 8571, 3, 2 }; |
| 300 | |
vlm | 1255771 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 301 | /* {joint-iso-itu-t 42 } */ |
| 302 | uint8_t buf3[] = { |
| 303 | 0x06, /* OBJECT IDENTIFIER */ |
| 304 | 0x01, /* Length */ |
| 305 | 0x7A |
| 306 | }; |
| 307 | int buf3_check[] = { 2, 42 }; |
| 308 | |
| 309 | /* {joint-iso-itu-t 25957 } */ |
| 310 | uint8_t buf4[] = { |
| 311 | 0x06, /* OBJECT IDENTIFIER */ |
| 312 | 0x03, /* Length */ |
| 313 | 0x81, 0x80 + 0x4B, 0x35 |
| 314 | }; |
| 315 | int buf4_check[] = { 2, 25957 }; |
| 316 | |
| 317 | int buf5_check[] = { 0 }; |
| 318 | int buf6_check[] = { 1 }; |
| 319 | int buf7_check[] = { 80, 40 }; |
| 320 | int buf8_check[] = { 127 }; |
| 321 | int buf9_check[] = { 128 }; |
| 322 | int buf10_check[] = { 65535, 65536 }; |
| 323 | int buf11_check[] = { 100000, 0x20000, 1234, 256, 127, 128 }; |
| 324 | int buf12_check[] = { 0, 0xffffffff, 0xff00ff00, 0 }; |
| 325 | int buf13_check[] = { 0, 1, 2 }; |
| 326 | int buf14_check[] = { 1, 38, 3 }; |
| 327 | int buf15_check[] = { 0, 0, 0xf000 }; |
| 328 | int buf16_check[] = { 0, 0, 0, 1, 0 }; |
| 329 | int buf17_check[] = { 2, 0xffffffAf, 0xff00ff00, 0 }; |
vlm | 903a213 | 2004-08-22 03:01:37 +0000 | [diff] [blame] | 330 | int buf18_check[] = { 2, 2, 1, 1 }; |
| 331 | |
| 332 | /* { joint-iso-itu-t 2 1 1 } */ |
| 333 | uint8_t buf19[] = { |
| 334 | 0x06, /* OBJECT IDENTIFIER */ |
| 335 | 0x03, /* Length */ |
| 336 | 0x52, 0x01, 0x01 |
| 337 | }; |
| 338 | int buf19_check[] = { 2, 2, 1, 1 }; |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 339 | |
vlm | 3fff06b | 2004-08-23 09:23:02 +0000 | [diff] [blame] | 340 | /* { joint-iso-itu-t 2 1 0 1 } */ |
| 341 | uint8_t buf20[] = { |
| 342 | 0x06, /* OBJECT IDENTIFIER */ |
| 343 | 0x04, /* Length */ |
| 344 | 0x52, 0x01, 0x00, 0x01 |
| 345 | }; |
| 346 | int buf20_check[] = { 2, 2, 1, 0, 1 }; |
| 347 | |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 348 | |
| 349 | CHECK_OID(1); /* buf1, buf1_check */ |
| 350 | CHECK_ROID(2); /* buf2, buf2_check */ |
vlm | 1255771 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 351 | CHECK_OID(3); /* buf3, buf3_check */ |
| 352 | CHECK_OID(4); /* buf4, buf4_check */ |
vlm | 903a213 | 2004-08-22 03:01:37 +0000 | [diff] [blame] | 353 | CHECK_OID(19); /* buf19, buf19_check */ |
vlm | 3fff06b | 2004-08-23 09:23:02 +0000 | [diff] [blame] | 354 | CHECK_OID(20); /* buf20, buf20_check */ |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 355 | |
vlm | 1255771 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 356 | CHECK_REGEN(5); /* Regenerate RELATIVE-OID */ |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 357 | CHECK_REGEN(6); |
| 358 | CHECK_REGEN(7); |
| 359 | CHECK_REGEN(8); |
| 360 | CHECK_REGEN(9); |
| 361 | CHECK_REGEN(10); |
vlm | 1255771 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 362 | CHECK_REGEN(11); |
| 363 | CHECK_REGEN(12); |
| 364 | CHECK_REGEN(13); |
| 365 | CHECK_REGEN(14); |
| 366 | CHECK_REGEN(15); |
| 367 | CHECK_REGEN(16); |
| 368 | CHECK_REGEN(17); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 369 | CHECK_REGEN_OID(1); /* Regenerate OBJECT IDENTIFIER */ |
vlm | 1255771 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 370 | CHECK_REGEN_OID(3); /* Regenerate OBJECT IDENTIFIER */ |
| 371 | CHECK_REGEN_OID(4); /* Regenerate OBJECT IDENTIFIER */ |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 372 | CHECK_REGEN_OID(13); |
vlm | 1255771 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 373 | CHECK_REGEN_OID(14); |
| 374 | CHECK_REGEN_OID(15); |
| 375 | CHECK_REGEN_OID(16); |
| 376 | CHECK_REGEN_OID(17); |
vlm | 903a213 | 2004-08-22 03:01:37 +0000 | [diff] [blame] | 377 | CHECK_REGEN_OID(18); |
vlm | 3fff06b | 2004-08-23 09:23:02 +0000 | [diff] [blame] | 378 | CHECK_REGEN_OID(19); |
| 379 | CHECK_REGEN_OID(20); |
vlm | 1255771 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 380 | |
vlm | 1f73df2 | 2004-10-23 10:16:51 +0000 | [diff] [blame] | 381 | check_parse("", 0); |
| 382 | check_parse(" ", 0); |
| 383 | check_parse(" ", 0); |
| 384 | check_parse(".", -1); |
| 385 | check_parse(" .", -1); |
| 386 | check_parse(" 1", 1); |
| 387 | check_parse(" 1.2", 2); |
| 388 | check_parse(" 1.", -1); |
| 389 | check_parse(" 1. ", -1); |
| 390 | check_parse("1. ", -1); |
| 391 | check_parse("1.2", 2); |
| 392 | check_parse("10.30.234.234", 4); |
| 393 | check_parse("10.30.234.234 ", 4); |
| 394 | check_parse("10.30.234. 234 ", -1); |
| 395 | check_parse("10.30.234.234.", -1); |
| 396 | check_parse("1.2000000000.3", 3); |
| 397 | check_parse("1.2147483647.3", 3); |
| 398 | if(sizeof(long) == 4) { |
| 399 | check_parse("1.2147483648.3", -1); /* overflow on ILP32 */ |
| 400 | check_parse("1.3000000000.3", -1); |
| 401 | check_parse("1.4000000000.3", -1); |
| 402 | check_parse("1.5000000000.3", -1); |
| 403 | check_parse("1.6000000000.3", -1); |
| 404 | check_parse("1.9000000000.3", -1); |
| 405 | } else { |
| 406 | check_parse("1.2147483648.3", 3); |
| 407 | } |
| 408 | check_parse("1.900a0000000.3", -1); |
| 409 | check_parse("1.900a.3", -1); |
| 410 | |
| 411 | check_xer(0, "<t></t>"); |
| 412 | check_xer(2, "<t>1.2</t>"); |
| 413 | check_xer(3, "<t>1.2.3</t>"); |
| 414 | check_xer(3, "<t> 1.2.3 </t>"); |
| 415 | check_xer(-1, "<t>1.2.3 1</t>"); |
| 416 | |
vlm | 1255771 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 417 | for(i = 0; i < 100000; i++) { |
| 418 | int bufA_check[3] = { 2, i, rand() }; |
| 419 | int bufB_check[2] = { rand(), i * 121 }; |
| 420 | CHECK_REGEN(A); |
| 421 | CHECK_REGEN_OID(A); |
| 422 | CHECK_REGEN(B); |
| 423 | if(i > 100) i++; |
| 424 | if(i > 500) i++; |
| 425 | if(i > 1000) i += 3; |
| 426 | if(i > 5000) i += 151; |
| 427 | } |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 428 | |
vlm | 3717fb3 | 2004-06-14 08:17:27 +0000 | [diff] [blame] | 429 | if(getenv("CHECK_SPEED")) { |
| 430 | /* Useful for developers only */ |
| 431 | check_speed(); |
| 432 | } |
vlm | 2e3dd3b | 2004-06-14 07:24:36 +0000 | [diff] [blame] | 433 | |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 434 | return 0; |
| 435 | } |