aboutsummaryrefslogtreecommitdiff
path: root/parse/parse.go
blob: b816058db64319ab05c3f171133ab6ede710477f (plain)
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package main

import (
	"dim13.org/asn1/ber"
	"fmt"
)

var associate = []byte{
	0x60, 0x23,
	0x80, 0x02, 0x07, 0x80,
	0xA1, 0x07,
	0x06, 0x05, 0x2B, 0x0C, 0x00, 0x81, 0x5A,
	0xBE, 0x14,
	0x28, 0x12,
	0x06, 0x07, 0x2B, 0x0C, 0x00, 0x82, 0x1D, 0x81, 0x48,
	0xA0, 0x07,
	0xA0, 0x05,
	0x03, 0x03, 0x00, 0x08, 0x00,
}

var result = []byte{
	0x61, 0x2F,
	0x80, 0x02, 0x07, 0x80,
	0xA1, 0x07,
	0x06, 0x05, 0x2B, 0x0C, 0x00, 0x81, 0x5A,
	0xA2, 0x03,
	0x02, 0x01, 0x00,
	0xA3, 0x05,
	0xA1, 0x03,
	0x02, 0x01, 0x00,
	0xBE, 0x14,
	0x28, 0x12,
	0x06, 0x07, 0x2B, 0x0C, 0x00, 0x82, 0x1D, 0x81, 0x48,
	0xA0, 0x07,
	0xA0, 0x05,
	0x03, 0x03, 0x00, 0x08, 0x00,
}

var reject = []byte{
	0x61, 0x19,
	0x80, 0x02, 0x07, 0x80,
	0xA1, 0x07,
	0x06, 0x05, 0x2B, 0x0C, 0x00, 0x81, 0x5A,
	0xA2, 0x03,
	0x02, 0x01, 0x01,
	0xA3, 0x05,
	0xA1, 0x03,
	0x02, 0x01, 0x01,
}

var release = []byte{
	0x62, 0x00,
}

func Chop(b []byte) (h byte, l int, v []byte, r []byte) {
	if len(b) > 1 {
		h = b[0]
		l = int(b[1])
		v, r = b[2:2+l], b[2+l:]
	}
	return
}

// broken
func dump(b []byte, indent int) {
	head, _, value, rest := Chop(b)

	class, kind, tag := ber.Ident(head)
	for i := indent; i > 0; i-- {
		fmt.Print("\t")
	}

	switch class {
	case ber.Universal:
		switch tag {
		case ber.Integer:
			fmt.Println(tag, ber.UnmarshalInt(value))
		case ber.ObjectIdentifier:
			fmt.Println(tag, ber.UnmarshalOID(value))
		default:
			fmt.Println(tag, kind, value)
		}
	default:
		fmt.Println(class, kind, byte(tag))
	}

	if len(value) > 0 && kind != ber.Primitive {
		dump(value, indent+1)
	}

	if len(rest) > 0 {
		dump(rest, indent)
	}
}

func main() {
	dump(associate, 0)
	//dump(result, 0)
	//dump(reject, 0)
	//dump(release, 0)
}