From 54caa4e7e085e177ff05b719ae247d21fe8c257e Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Sat, 26 Sep 2015 12:04:34 +0200 Subject: Replace with new implementation --- ber/common.go | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 ber/common.go (limited to 'ber/common.go') diff --git a/ber/common.go b/ber/common.go new file mode 100644 index 0000000..7c4f496 --- /dev/null +++ b/ber/common.go @@ -0,0 +1,77 @@ +package ber + +import ( + "bytes" + "strconv" + "strings" +) + +type state struct{ bytes.Buffer } + +func newState(b []byte) *state { + s := &state{} + s.Write(b) + return s +} + +func (s *state) subState() *state { + ss := state{} + ss.Write(s.next()) + return &ss +} + +func (s *state) next() []byte { + l := s.unmarshalLen() + return s.Next(l) +} + +type OID []int + +func (o OID) Equal(p OID) bool { + if len(o) != len(p) { + return false + } + for i := range o { + if o[i] != p[i] { + return false + } + } + return true +} + +func (o OID) String() string { + s := make([]string, len(o)) + for i, v := range o { + s[i] = strconv.Itoa(v) + } + return strings.Join(s, ".") +} + +type BitString []bool + +func (o BitString) Equal(p BitString) bool { + if len(o) != len(p) { + return false + } + for i := range o { + if o[i] != p[i] { + return false + } + } + return true +} + +func (o BitString) String() string { + bmap := map[bool]string{ + true: "1", + false: "0", + } + var s string + for i, bit := range o { + if i != 0 && i%4 == 0 { + s += " " + } + s += bmap[bit] + } + return s +} -- cgit v1.2.3