aboutsummaryrefslogtreecommitdiff
path: root/ber/new/dump.go
blob: 9fc206e18e90bab1042fbe60b4156f2d54b78e80 (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
package ber

import (
	"fmt"
)

func Dump(b []byte) string {
	return newState(b).dump(0)
}

func (s *state) dump(indent int) string {
	if s.Len() == 0 {
		return ""
	}
	//fmt.Printf("%*s%x %x\n", 2*indent, "", s.Len(), s.Bytes())
	for s.Len() > 0 {
		h := s.ident()
		fmt.Printf("%*s%v: ", 2*indent, "", h)
		if h.Class == classUniversal && h.Kind == kindPrimitive {
			switch h.Tag {
			case tagInteger, tagEnumerated:
				fmt.Println(s.unmarshalInt())
			case tagBoolean:
				fmt.Println(s.unmarshalBool())
			case tagObjectIdentifier:
				fmt.Println(s.unmarshalOID())
			case tagBitString:
				fmt.Println(s.unmarshalBitString())
			case tagIA5String, tagOctetString:
				fmt.Println(s.unmarshalString())
			default:
				fmt.Println("")
				s.next()
			}
		} else {
			fmt.Println("")
			s.subState().dump(indent + 1)
		}
	}
	return s.dump(indent)
}