#include #include #include "asn1.h" void printasn1(const char* buf,const char* max) { const char* maxstack[100]; size_t sptr=0; size_t indent=0; unsigned long tag; enum asn1_tagclass tc; enum asn1_tagtype tt; size_t cl,len; maxstack[sptr]=max; while (buf %ld\n",indent,"",l); } else if (tag==OCTET_STRING) { printf("%*s-> \"",indent,""); for (i=0; i ",indent,""); for (i=0; i=99) { printf("too many nested constructed elements!\n"); return; } maxstack[++sptr]=buf+len; } else buf+=len; while (sptr && maxstack[sptr]<=buf) { --sptr; indent-=2; printf("%*s}\n",indent,""); } } } const unsigned long oid[]={1,2,840,113549,1}; const unsigned long oidlen = sizeof(oid) / sizeof(oid[0]); main() { char buf[1024]; int l,i; struct oid o; struct string B; B.s="\xfe\x74"; B.l=8+6; o.l=oidlen; o.a=oid; byte_zero(buf,1024); l=fmt_asn1generic(buf,"a{isbo}",8,23,"fnord",&B,&o); printf("formatted into %d bytes\n",l); { printf("-> "); for (i=0; i