-
Notifications
You must be signed in to change notification settings - Fork 2
/
asn1.c
65 lines (51 loc) · 800 Bytes
/
asn1.c
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
/*
asn1.c
Copyright (c) 2000 Dug Song <[email protected]>
$Id: asn1.c,v 1.3 2000/11/15 17:54:46 dugsong Exp $
*/
#include "config.h"
#include <sys/types.h>
#include <arpa/nameser.h>
#include <unistd.h>
#include "buf.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);
}