aboutsummaryrefslogtreecommitdiff
path: root/parse/parse.go
blob: eb67e8a0fb1cfd91ee656f419bf36d881081c395 (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
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))
		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("")
	}
}