aboutsummaryrefslogtreecommitdiff
path: root/parse/parse.go
blob: f921a8b4ece85354eaf2110518239588967245fc (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
package main

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

func dump(b []byte, indent int) {
	class, kind, tag, _, value, rest := ber.Split(b)

	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))
		case ber.BitString:
			fmt.Println(tag, ber.UnmarshalBitString(value), value)
		default:
			if len(value) > 5 {
				fmt.Println(tag, kind, value[:5], "...")
			} else {
				fmt.Println(tag, kind, value)
			}
		}
	default:
		if len(value) > 5 {
			fmt.Println(class, kind, byte(tag), value[:5], "...")
		} else {
			fmt.Println(class, kind, byte(tag), value)
		}
	}

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

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

func main() {
	for n, s := range session {
		fmt.Println(">>> packet", n)
		dump(s, 0)
		fmt.Println("")
	}
}