aboutsummaryrefslogtreecommitdiff
path: root/ber/dump.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-07-13 18:58:56 +0200
committerDimitri Sokolyuk <demon@dim13.org>2015-07-13 18:58:56 +0200
commit7dcb8578b66e107c6485057ef8800ab788ca5c37 (patch)
tree4138d7f277b0d15cc9e5dc5addb7af5092c4ea5c /ber/dump.go
parentefaf089f597a41beccae1ad1b61df29d1548a7fd (diff)
Move dump into package
Diffstat (limited to 'ber/dump.go')
-rw-r--r--ber/dump.go48
1 files changed, 48 insertions, 0 deletions
diff --git a/ber/dump.go b/ber/dump.go
new file mode 100644
index 0000000..18976bd
--- /dev/null
+++ b/ber/dump.go
@@ -0,0 +1,48 @@
+package ber
+
+import "fmt"
+
+func Dump(b []byte) {
+ dump(b, 0)
+}
+
+func dump(b []byte, indent int) {
+ class, kind, tag, _, value, rest := Split(b)
+
+ for i := indent; i > 0; i-- {
+ fmt.Print("\t")
+ }
+
+ switch class {
+ case classUniversal:
+ switch tag {
+ case tagInteger:
+ fmt.Println(tag, UnmarshalInt(value))
+ case tagObjectIdentifier:
+ fmt.Println(tag, UnmarshalOID(value))
+ case tagBitString:
+ fmt.Println(tag, 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 != kindPrimitive {
+ dump(value, indent+1)
+ }
+
+ if len(rest) > 0 {
+ dump(rest, indent)
+ }
+
+}