Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1 | #include "../INTEGER.c" |
| 2 | #include "../ber_decoder.c" |
| 3 | #include "../ber_tlv_length.c" |
| 4 | #include "../ber_tlv_tag.c" |
| 5 | #include "../der_encoder.c" |
| 6 | #include "../constraints.c" |
| 7 | |
| 8 | static void |
| 9 | check(uint8_t *buf, int size, long check_long, int check_ret) { |
| 10 | INTEGER_t val; |
| 11 | int ret; |
| 12 | long rlong = 123; |
| 13 | |
| 14 | assert(buf); |
| 15 | assert(size >= 0); |
| 16 | |
| 17 | val.buf = buf; |
| 18 | val.size = size; |
| 19 | |
| 20 | |
| 21 | ret = asn1_INTEGER2long(&val, &rlong); |
| 22 | printf("Testing (%ld, %d) vs (%ld, %d)\n", |
| 23 | rlong, ret, check_long, check_ret); |
| 24 | assert(ret == check_ret); |
| 25 | if(ret == -1) return; |
| 26 | assert(rlong == check_long); |
| 27 | } |
| 28 | |
| 29 | int |
| 30 | main(int ac, char **av) { |
| 31 | uint8_t buf1[] = { 1 }; |
| 32 | uint8_t buf2[] = { 0xff }; |
| 33 | uint8_t buf3[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; |
| 34 | uint8_t buf4[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0 }; |
| 35 | uint8_t buf5[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1 }; |
| 36 | uint8_t buf6[] = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; |
| 37 | uint8_t buf7[] = { 0xff, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; |
| 38 | uint8_t buf8[] = { 0x7f, 0x7e, 0x7d, 0x7c }; |
| 39 | uint8_t buf9[] = { 0, 0x7f, 0x7e, 0x7d, 0x7c }; |
| 40 | uint8_t buf10[] = { 0, 0, 0, 0, 0, 0, 0x7f, 0x7e, 0x7d, 0x7c }; |
| 41 | |
| 42 | #define CHECK(buf, val, ret) check(buf, sizeof(buf), val, ret) |
| 43 | |
| 44 | CHECK(buf1, 1, 0); |
| 45 | CHECK(buf2, -1, 0); |
| 46 | CHECK(buf3, -1, 0); |
| 47 | CHECK(buf4, -16, 0); |
| 48 | CHECK(buf5, 257, 0); |
| 49 | CHECK(buf6, 123, -1); |
| 50 | CHECK(buf7, 123, -1); |
| 51 | CHECK(buf8, 0x7F7E7D7C, 0); |
| 52 | CHECK(buf9, 0x7F7E7D7C, 0); |
| 53 | CHECK(buf10, 0x7F7E7D7C, 0); |
| 54 | |
| 55 | return 0; |
| 56 | } |