diff --git a/Makefile b/Makefile index 968f33b..26412aa 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ fmt_asn1int.o fmt_asn1string.o fmt_asn1transparent.o scan_asn1tag.o \ scan_asn1length.o scan_asn1int.o scan_asn1string.o scan_asn1INTEGER.o \ scan_asn1STRING.o scan_asn1SEQUENCE.o scan_asn1ENUMERATED.o \ scan_asn1BOOLEAN.o scan_asn1rawint.o scan_asn1SET.o fmt_asn1sint.o \ -fmt_asn1sintpayload.o +fmt_asn1sintpayload.o scan_asn1oid.o ldap.a: scan_ldapmessage.o fmt_ldapmessage.o fmt_ldapbindrequest.o \ scan_ldapbindrequest.o scan_ldapbindresponse.o scan_ldapresult.o \ diff --git a/scan_asn1oid.c b/scan_asn1oid.c new file mode 100644 index 0000000..6e90f44 --- /dev/null +++ b/scan_asn1oid.c @@ -0,0 +1,49 @@ +#include "asn1.h" + +int scan_asn1oid(const char* src,const char* max) { + int res,tmp; + unsigned long tag,tlen; + enum asn1_tagclass tc; + enum asn1_tagtype tt; + if (!(res=scan_asn1tag(src,max,&tc,&tt,&tag))) goto error; + if (!(tmp=scan_asn1length(src+res,max,&tlen))) goto error; + res+=tmp; + { + unsigned int i,x,y; + tmp=0; + for(i=0;src[res+i]&128;++i) + tmp=(tmp<<7)+((unsigned char)src[res+i]&(~128)); + tmp=(tmp<<7)+(unsigned char)src[res+i]; ++i; + x=tmp/40; y=tmp-x*40; + /* AFAIK gilt fuer alle bisher zugewiesenen OIDs: x<=2 & y<40 */ +#if 1 + /* Hier wird das Beispiel aus dem Standard korrekt geparst. */ + while (x>2) { --x; y+=40; } +#else + /* Hier nicht. Dennoch arbeiten einige ASN.1 Parser ebenso. */ + while (y>40) { y-=40; ++x; } +#endif +#if 0 + buffer_putulong(buffer_2,x); + buffer_puts(buffer_2,"."); + buffer_putulong(buffer_2,y); +#endif + for(;i