/[radius]/radius/snmplib/asn1.c
ViewVC logotype

Diff of /radius/snmplib/asn1.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.6 by gray, Tue May 14 11:08:22 2002 UTC revision 1.7 by gray, Wed Apr 30 08:44:33 2003 UTC
# Line 1  Line 1 
1  /*  /*
2     Copyright (C) 2001, Sergey Poznyakoff.     Copyright (C) 2001,2003 Sergey Poznyakoff.
3    
4     This file is part of GNU Radius SNMP Library.     This file is part of GNU Radius SNMP Library.
5    
# Line 34  Line 34 
34     Return: pointer to the first byte of the object.       Return: pointer to the first byte of the object.  
35     Error:  Returns NULL, does not change args */       Error:  Returns NULL, does not change args */  
36  u_char *  u_char *
37  asn_decode_length(data, length)  asn_decode_length(u_char *data, u_int *length)
         u_char *data;  
         u_int  *length;  
38  {  {
39          u_char size = *data++;          u_char size = *data++;
40                    
# Line 68  asn_decode_length(data, length) Line 66  asn_decode_length(data, length)
66     Return:Pointer to the byte immediately past the encoded length     Return:Pointer to the byte immediately past the encoded length
67     Error: NULL */     Error: NULL */
68  u_char *  u_char *
69  asn_encode_length(data, datalength, length)  asn_encode_length(u_char *data, int *datalength, u_int length)
         u_char *data;  
         int *datalength;  
         u_int length;  
70  {  {
71          if (*datalength < 1) {          if (*datalength < 1) {
72                  SNMP_SET_ERRNO(E_ASN_ENCODE);                  SNMP_SET_ERRNO(E_ASN_ENCODE);
# Line 103  asn_encode_length(data, datalength, leng Line 98  asn_encode_length(data, datalength, leng
98  }  }
99    
100  u_char *  u_char *
101  asn_recode_length(data, length)  asn_recode_length(u_char *data, u_int length)
         u_char *data;  
         u_int length;  
102  {  {
103          /*length can be at most 0xffff */          /*length can be at most 0xffff */
104          *data++ = (u_char)(ASN_LONG_LEN|0x02);          *data++ = (u_char)(ASN_LONG_LEN|0x02);
# Line 124  asn_recode_length(data, length) Line 117  asn_recode_length(data, length)
117            data).            data).
118     Error: NULL */     Error: NULL */
119  u_char *  u_char *
120  asn_encode_header(data, datalength, type, length)  asn_encode_header(u_char *data, int *datalength, u_char type, int length)
         u_char *data;  
         int *datalength;  
         u_char type;  
         int length;  
121  {  {
122          if (*datalength < 1) {          if (*datalength < 1) {
123                  SNMP_SET_ERRNO(E_ASN_ENCODE);                  SNMP_SET_ERRNO(E_ASN_ENCODE);
# Line 140  asn_encode_header(data, datalength, type Line 129  asn_encode_header(data, datalength, type
129  }  }
130    
131  u_char *  u_char *
132  asn_decode_header(data, datalength, type)  asn_decode_header(u_char *data, int *datalength, u_char *type)
         u_char *data;  
         int *datalength;  
         u_char *type;  
133  {  {
134          if (*datalength < 1) {          if (*datalength < 1) {
135                  SNMP_SET_ERRNO(E_ASN_DECODE);                  SNMP_SET_ERRNO(E_ASN_DECODE);
# Line 155  asn_decode_header(data, datalength, type Line 141  asn_decode_header(data, datalength, type
141  }  }
142    
143  u_char *  u_char *
144  asn_encode_null(data, datalength, type)  asn_encode_null(u_char *data, int *datalength, u_char type)
                 u_char *data;  
                 int *datalength;  
                 u_char type;  
145  {  {
146          return asn_encode_header(data, datalength, type, 0);          return asn_encode_header(data, datalength, type, 0);
147  }  }
# Line 178  asn_encode_null(data, datalength, type) Line 161  asn_encode_null(data, datalength, type)
161     Return:Pointer to the byte immediately past the decoded object.     Return:Pointer to the byte immediately past the decoded object.
162     Error: NULL */     Error: NULL */
163  u_char *  u_char *
164  asn_decode_int(data, datalength, type, intp, intsize)  asn_decode_int(u_char *data, int *datalength, u_char *type,
165          u_char *data;                 int *intp, int intsize)
         int *datalength;  
         u_char *type;  
         int *intp;  
         int intsize;  
166  {  {
167          u_int count;          u_int count;
168          u_char *buf = data;          u_char *buf = data;
# Line 229  asn_decode_int(data, datalength, type, i Line 208  asn_decode_int(data, datalength, type, i
208     Error: NULL */     Error: NULL */
209        
210  u_char *  u_char *
211  asn_encode_int(data, datalength, type, intval)  asn_encode_int(u_char *data, int *datalength, u_char type, int intval)
         u_char *data;  
         int *datalength;  
         u_char type;  
         int intval;  
212  {  {
213          u_int mask;          u_int mask;
214          u_int intsize = sizeof(int);          u_int intsize = sizeof(int);
# Line 286  asn_encode_int(data, datalength, type, i Line 261  asn_encode_int(data, datalength, type, i
261     Return:Pointer to the byte immediately past the decoded object.     Return:Pointer to the byte immediately past the decoded object.
262     Error: NULL */     Error: NULL */
263  u_char *  u_char *
264  asn_decode_string(data, datalength, type, string, strlength)  asn_decode_string(u_char *data, int *datalength, u_char *type,
265          u_char *data;                    u_char *string, int *strlength)
         int *datalength;  
         u_char *type;  
         u_char *string;  
         int *strlength;  
266  {  {
267          u_char *buf = data;          u_char *buf = data;
268          int count;          int count;
# Line 321  asn_decode_string(data, datalength, type Line 292  asn_decode_string(data, datalength, type
292     Return:Pointer to the byte immediately past the encoded object.     Return:Pointer to the byte immediately past the encoded object.
293     Error: NULL */     Error: NULL */
294  u_char *  u_char *
295  asn_encode_string(data, datalength, type, string, strlength)  asn_encode_string(u_char *data, int *datalength, u_char type,
296          u_char *data;                    u_char *string, int strlength)
         int *datalength;  
         u_char type;  
         u_char *string;  
         int strlength;  
297  {  {
298          data = asn_encode_header(data, datalength, type, strlength);          data = asn_encode_header(data, datalength, type, strlength);
299          if (!data || *datalength < strlength) {          if (!data || *datalength < strlength) {
# Line 361  asn_encode_string(data, datalength, type Line 328  asn_encode_string(data, datalength, type
328     Return:Pointer to the byte immediately past the decoded object.     Return:Pointer to the byte immediately past the decoded object.
329     Error: NULL */     Error: NULL */
330  u_char *  u_char *
331  asn_decode_oid(data, datalength, type, obid, obidlength)  asn_decode_oid(u_char *data, int *datalength, u_char *type,
332          u_char *data;                 oid_t obid, int *obidlength)
         int *datalength;  
         u_char *type;  
         oid_t obid;  
         int *obidlength;  
333  {  {
334          u_char *buf = data;          u_char *buf = data;
335          u_int count;          u_int count;
# Line 421  asn_decode_oid(data, datalength, type, o Line 384  asn_decode_oid(data, datalength, type, o
384     Return:Pointer to the byte immediately past the encoded object.     Return:Pointer to the byte immediately past the encoded object.
385     Error: NULL */     Error: NULL */
386  u_char *  u_char *
387  asn_encode_oid(data, datalength, type, obid, obidlength)  asn_encode_oid(u_char *data, int *datalength, u_char type,
388          u_char *data;                 oid_t obid, int obidlength)
         int *datalength;  
         u_char type;  
         oid_t obid;  
         int obidlength;  
389  {  {
390          int length;          int length;
391          u_char *buf, *bp;          u_char *buf, *bp;

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.7

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26