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("") } }