aboutsummaryrefslogtreecommitdiff
path: root/ber/common.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-09-26 12:04:34 +0200
committerDimitri Sokolyuk <demon@dim13.org>2015-09-26 12:04:34 +0200
commit54caa4e7e085e177ff05b719ae247d21fe8c257e (patch)
tree363400fe1c6c1e7b696c72caaabc4882756355fa /ber/common.go
parent1fcefc99a82bac6ce725b6f11277e4aa291a7f51 (diff)
Replace with new implementation
Diffstat (limited to 'ber/common.go')
-rw-r--r--ber/common.go77
1 files changed, 77 insertions, 0 deletions
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
+}