1 /* Author : Rahul G rahul@smartbridges.com */
8 /* This function takes the oid in dot format ( 1.3.6.1.4.410.... ) and encodes
9 * the oid using ber rules. oid_out should be allocated by the application..
10 * encode_oid returns the length of the encoded buffer.
12 int encode_oid(char* oid, unsigned char* oid_out)
15 int count=0, oct_count=2;
16 int num_val=0, oct1=0;
20 oid_out[0]=0x06 ; /* 00000110 */
21 while(( (ptr=strchr(oid,'.')) != 0) || last == 0 )
31 /*get the first two sub id's*/
42 oid_out[oct_count]=oct1;
53 unsigned int mask= (num_val>>(i)) & ~(~0x0000<<1);
61 for(j=loop; j>= 0; j--)
63 oid_out[oct_count]= (num_val >> (j*7)) & ~(~0x0000 << 7);
64 oid_out[oct_count] |= 0x80; /* turn the msb to 1 */
67 oid_out[oct_count - 1] &= 0x7f; /* turn the msb back to zero for the last octect */
79 //Insert the octect length
80 oid_out[1]=oct_count-2;
89 unsigned char oid_ut[512];
91 // ret=encode_oid("1.3.6.1.4.1.410.1.1.1.1.0",oid_ut);
92 ret=encode_oid("1.2.840.113549.1",oid_ut);
95 printf("%.2x ",oid_ut[k]);