From 56c3c56cd067a5586213aeb1fc34f2c7acb407ac Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Mon, 29 Jun 2015 20:10:06 +0200 Subject: Add package parser, broken --- parse/parse.go | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 parse/parse.go (limited to 'parse/parse.go') diff --git a/parse/parse.go b/parse/parse.go new file mode 100644 index 0000000..b816058 --- /dev/null +++ b/parse/parse.go @@ -0,0 +1,101 @@ +package main + +import ( + "dim13.org/asn1/ber" + "fmt" +) + +var associate = []byte{ + 0x60, 0x23, + 0x80, 0x02, 0x07, 0x80, + 0xA1, 0x07, + 0x06, 0x05, 0x2B, 0x0C, 0x00, 0x81, 0x5A, + 0xBE, 0x14, + 0x28, 0x12, + 0x06, 0x07, 0x2B, 0x0C, 0x00, 0x82, 0x1D, 0x81, 0x48, + 0xA0, 0x07, + 0xA0, 0x05, + 0x03, 0x03, 0x00, 0x08, 0x00, +} + +var result = []byte{ + 0x61, 0x2F, + 0x80, 0x02, 0x07, 0x80, + 0xA1, 0x07, + 0x06, 0x05, 0x2B, 0x0C, 0x00, 0x81, 0x5A, + 0xA2, 0x03, + 0x02, 0x01, 0x00, + 0xA3, 0x05, + 0xA1, 0x03, + 0x02, 0x01, 0x00, + 0xBE, 0x14, + 0x28, 0x12, + 0x06, 0x07, 0x2B, 0x0C, 0x00, 0x82, 0x1D, 0x81, 0x48, + 0xA0, 0x07, + 0xA0, 0x05, + 0x03, 0x03, 0x00, 0x08, 0x00, +} + +var reject = []byte{ + 0x61, 0x19, + 0x80, 0x02, 0x07, 0x80, + 0xA1, 0x07, + 0x06, 0x05, 0x2B, 0x0C, 0x00, 0x81, 0x5A, + 0xA2, 0x03, + 0x02, 0x01, 0x01, + 0xA3, 0x05, + 0xA1, 0x03, + 0x02, 0x01, 0x01, +} + +var release = []byte{ + 0x62, 0x00, +} + +func Chop(b []byte) (h byte, l int, v []byte, r []byte) { + if len(b) > 1 { + h = b[0] + l = int(b[1]) + v, r = b[2:2+l], b[2+l:] + } + return +} + +// broken +func dump(b []byte, indent int) { + head, _, value, rest := Chop(b) + + class, kind, tag := ber.Ident(head) + 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: + fmt.Println(tag, kind, value) + } + default: + fmt.Println(class, kind, byte(tag)) + } + + if len(value) > 0 && kind != ber.Primitive { + dump(value, indent+1) + } + + if len(rest) > 0 { + dump(rest, indent) + } +} + +func main() { + dump(associate, 0) + //dump(result, 0) + //dump(reject, 0) + //dump(release, 0) +} -- cgit v1.2.3