add scan_asn1oid from Thomas Walpuski

This commit is contained in:
leitner
2003-03-14 23:55:19 +00:00
parent b9b3b03e02
commit 4b6b20f995
2 changed files with 50 additions and 1 deletions

View File

@@ -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 \

49
scan_asn1oid.c Normal file
View File

@@ -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<tlen;++i) {
tmp=0;
for(;src[res+i]&128;++i)
tmp=(tmp<<7)+((unsigned char)src[res+i]&(~128));
tmp=(tmp<<7)+(unsigned char)src[res+i];
#if 0
buffer_puts(buffer_2,".");
buffer_putulong(buffer_2,tmp);
#endif
}
#if 0
buffer_putsflush(buffer_2,"\n");
#endif
}
return res+tlen;
error:
return 0;
}