[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: going back to stone axes



At 12:23 PM 2/29/96 -0500, David P. Kemp wrote:
>/*************************************************************************
> * Get an ASN.1 item, which includes: 1) Tag, 2) Length, and 3) Contents.
> ************************************************************************/
>struct Item *
>get_item(u_char *b)
>{
>        int  i, n;
>        static struct Item a;
>
>        if ((a.id = *b++) == 0)
>            return ((struct Item *)0);
>        if ((n = *b++) & LEN_XTND) {
>            n &= LEN_MASK;
>            if (n > 4) {
>                printf("get_item: length too big! n=%d bytes\n", n);
>                exit(1);
>            }
>            a.len = 0;
>            for (i=0; i<n; i++)
>                a.len = a.len << 8 | *b++;
>        } else {
>            a.len = n;
>        }
>        a.next = a.data = b;
>        if ((a.id & CONSTRUCTED) == 0)
>            a.next += a.len;
>        return(&a);
>}

Assuming:
  #define LEN_XTND 0x80
  #define LEN_MASK 0x7f
  struct Item {
    u_char id;
    uint32 len;
    u_char *data;
    u_char *next;
  };
  /* BTSOOM what CONSTRUCTED means */

This code assumes that either: (1) All the data will be in memory, so the
system which uses it should have a packet buffer whose length is greater
than 0x7fffffff, or (2) The calling code will be willing to continue to
fill a shorter buffer from the network while it is parsing *data.

Setting a.next, indicates that the entire structure (of which this is
parsing just a part) is in memory, to the restriction of (1) would apply. 
The coding of routines under assumption (2) can be quite difficult and
baroque.

Regards - Bill


------------------------------------------------------------------------
Bill Frantz       | The CDA means  | Periwinkle  --  Computer Consulting
(408)356-8506     | lost jobs and  | 16345 Englewood Ave.
frantz@netcom.com | dead teenagers | Los Gatos, CA 95032, USA