Harald Welte | 35cbc11 | 2015-09-11 17:36:59 +0200 | [diff] [blame^] | 1 | #include "iu_helpers.h" |
| 2 | #include "asn1helpers.h" |
| 3 | |
| 4 | #include <assert.h> |
| 5 | #define ASSERT(x) assert(x) |
| 6 | |
| 7 | #include <osmocom/core/utils.h> |
| 8 | |
| 9 | void *talloc_asn1_ctx; |
| 10 | |
| 11 | /* use odd number of digits */ |
| 12 | const uint8_t imsi_encoded[] = { 0x10, 0x32, 0x54, 0x76, 0xF8 }; |
| 13 | const char imsi_decoded[] = "012345678"; |
| 14 | |
| 15 | int main(int argc, char **argv) |
| 16 | { |
| 17 | char outstr[32]; |
| 18 | uint8_t outbuf[16]; |
| 19 | int rc; |
| 20 | |
| 21 | printf("pre-encoded: %s\n", osmo_hexdump_nospc(imsi_encoded, |
| 22 | sizeof(imsi_encoded))); |
| 23 | rc = decode_iu_bcd(outstr, sizeof(outstr), imsi_encoded, |
| 24 | sizeof(imsi_encoded)); |
| 25 | ASSERT(rc >= 0); |
| 26 | printf("decoded: %s\n", outstr); |
| 27 | ASSERT(!strcmp(outstr, imsi_decoded)); |
| 28 | |
| 29 | rc = encode_iu_imsi(outbuf, sizeof(outbuf), imsi_decoded); |
| 30 | ASSERT(rc >= 0); |
| 31 | printf("re-encoded: %s\n", osmo_hexdump_nospc(outbuf, rc)); |
| 32 | ASSERT(!memcmp(outbuf, imsi_encoded, sizeof(imsi_encoded))); |
| 33 | |
| 34 | return 0; |
| 35 | } |