#include #include #include #include "dat.h" #include "fns.h" enum { Bits5 = 0x1F, Bits7 = 0x7F, }; static uchar* gbuint7(uchar *p, uchar* ep, int* pv) { uint u,v,go; v = 0; go = 1; while(go){ if(p >= ep){ werrstr(Eshort); return nil; } u = *p; v = (v<<7) | (u&Bits7); if(v&(Bits7<<24)){ werrstr(Ebignum); return nil; } go = u&(1<<7); p++; } *pv = v; return p; } uchar* gbtag(uchar *p, uchar* ep, int* ptag) { if(p >= ep){ werrstr(Eshort); return nil; } *ptag = p[0] & Bits5; p += 1; if(*ptag == Bits5) p = gbuint7(p, ep, ptag); return p; } uchar* gblen(uchar *p, uchar* ep, int* plen) { int c,v; if(p >= ep){ werrstr(Eshort); return nil; } v = *p++; if(v < (1<<7)){ *plen = v; return p; } c = v&Bits7; if(p+c >= ep){ werrstr(Eshort); return nil; } switch(c){ default: werrstr(Ebignum); return nil; case 0: *plen = 0; break; case 1: *plen = p[0]; break; case 2: *plen = GSHORTB(p); break; case 3: *plen = (GSHORTB(p)<<8)|p[2]; break; case 4: *plen = GLONGB(p); break; } return p+c; } void pbshort(uchar* p, int v) { p[0]=2; p[1]=2; PSHORTB(p+2,v); }