From 0559b7d4eab07cacf0f005e8e756c1d04470e0c7 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Fri, 25 Sep 2015 15:07:15 +0200 Subject: Broken, but a step in right direction --- ber/class.go | 37 +++++++++---------------------------- 1 file changed, 9 insertions(+), 28 deletions(-) (limited to 'ber/class.go') diff --git a/ber/class.go b/ber/class.go index b734964..ab455f1 100644 --- a/ber/class.go +++ b/ber/class.go @@ -1,5 +1,7 @@ package ber +import "io" + type Class byte const ( @@ -105,36 +107,15 @@ var tagNames = map[Tag]string{ func (t Tag) String() string { return tagNames[t] } -func Ident(b []byte) (Class, Kind, Tag, int) { - var d, n int - c := Class(b[0]) & classMask - k := Kind(b[0]) & kindMask - t := Tag(b[0]) & tagMask +func Ident(r io.ByteReader) (Class, Kind, Tag) { + b, _ := r.ReadByte() + c := Class(b) & classMask + k := Kind(b) & kindMask + t := Tag(b) & tagMask if t == tagMask { - d, n = debase128(b[1:]) - t = Tag(d) + t = Tag(Debase128(r)) } - return c, k, t, n + 1 -} - -func Unversal(b []byte) (int, bool) { - c, _, t, _ := Ident(b) - return int(t), c == classUniversal -} - -func Application(b []byte) (int, bool) { - c, _, t, _ := Ident(b) - return int(t), c == classApplication -} - -func ContextSpecific(b []byte) (int, bool) { - c, _, t, _ := Ident(b) - return int(t), c == classContextSpecific -} - -func Private(b []byte) (int, bool) { - c, _, t, _ := Ident(b) - return int(t), c == classPrivate + return c, k, t } func MarshalClass(c Class, k Kind, t Tag) []byte { -- cgit v1.2.3