1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
/*
* asn1.c
*
* Copyright (c) 2000 Dug Song <dugsong@monkey.org>
*
* $Id: asn1.c,v 1.4 2001/03/15 08:32:58 dugsong Exp $
*/
#include "config.h"
#include <sys/types.h>
#include <arpa/nameser.h>
#include <unistd.h>
#include "buf.h"
#include "asn1.h"
int
asn1_type(buf_t buf)
{
u_char c;
if (buf_get(buf, &c, 1) != 1)
return (-1);
return (c & 0x1f);
}
int
asn1_len(buf_t buf)
{
u_char *p, c;
int num;
if (buf_get(buf, &c, 1) != 1)
return (-1);
if (c >= 128) {
c &= ~128;
p = buf_ptr(buf);
if (buf_skip(buf, c) < 0)
return (-1);
switch (c) {
case 1:
num = *p;
break;
case 2:
GETSHORT(num, p);
break;
case 3:
p--; GETLONG(num, p);
num &= 0xfff;
break;
case 4:
GETLONG(num, p);
break;
default:
return (-1);
}
}
else num = c;
return (num);
}
|