#define EMIT_ASN_DEBUG 1 #include #include #include #include #include #include #include #include #include #include enum encoding_type { HEX, BINARY, UTF8 }; static void check(enum encoding_type type, char *tagname, char *xmlbuf, char *verify) { int xmllen = strlen(xmlbuf); int verlen = verify ? strlen(verify) : 0; asn_TYPE_descriptor_t *td = &asn_DEF_OCTET_STRING; OCTET_STRING_t *st = 0; asn_dec_rval_t rc; xer_type_decoder_f *decoder = 0; switch(type) { case HEX: decoder = OCTET_STRING_decode_xer_hex; break; case BINARY: td = &asn_DEF_BIT_STRING; decoder = OCTET_STRING_decode_xer_binary; break; case UTF8: decoder = OCTET_STRING_decode_xer_utf8; break; } rc = decoder(0, td, (void **)&st, tagname, xmlbuf, xmllen); printf("[%s] => [%s]:%d vs [%s]:%d, code %d\n", xmlbuf, st ? (const char *)st->buf : "", st ? st->size : 0, verify ? verify : "", verlen, rc.code); if(verify) { assert(rc.code == RC_OK); assert(st); assert(st->buf); assert(st->size == verlen); assert(!memcmp(st->buf, verify, verlen)); } else { assert(rc.code != RC_OK); } } int main() { check(HEX, 0, "41424", "AB@"); check(HEX, 0, "\n" "41424", "AB@"); check(HEX, 0, " 4 1 4 2 4 5 44 ", "ABED"); /* Some hard cases */ check(HEX, "z", "40", "@"); check(HEX, "z", "40", "@"); check(HEX, "z", ">40", 0); check(HEX, "z", "40", "@"); check(HEX, "z", ">40", 0); check(HEX, "z", "ignored40stuff", "@"); check(HEX, "tag", "4", "@"); check(HEX, "a-z", "7 375 73 6c6 96 b", "suslik"); /* This one has a comment in a not-yet-supported place */ /* check(HEX, "a-z", "73 75 73 6c 69 6b", "suslik"); */ check(BINARY, "tag", "", ""); check(BINARY, "tag", "blah", 0); check(BINARY, "tag", "01000001", "A"); check(BINARY, "tag", "01000 00 101 00001", "AB"); check(UTF8, 0, "one, two, three", "one, two, three"); check(UTF8, "z", "", ""); check(UTF8, "z", "<&>", "<&>"); check(UTF8, "z", "a<b&c>d", "ad"); check(UTF8, "z", "a<", "a<"); check(UTF8, "z", "a&sdfsdfsdf;b", "a&sdfsdfsdf;b"); check(UTF8, "z", "a b", "a b"); check(UTF8, "z", "a b", "a b"); check(UTF8, "z", "a繃b", "a\347\271\203b"); check(UTF8, "z", "a�b", "a�b"); check(UTF8, "z", "a�b", "a�b"); check(UTF8, "z", "", "aĬ"); check(UTF8, "z", "a&#-300;", "a&#-300;"); check(UTF8, "z", "ab", "a\014b"); check(UTF8, "z", "ab", "a\001b"); check(UTF8, "z", "a", "a\007"); return 0; }