aboutsummaryrefslogtreecommitdiff
path: root/ber/obj.go
diff options
context:
space:
mode:
Diffstat (limited to 'ber/obj.go')
-rw-r--r--ber/obj.go18
1 files changed, 9 insertions, 9 deletions
diff --git a/ber/obj.go b/ber/obj.go
index 9b475c7..3de31b7 100644
--- a/ber/obj.go
+++ b/ber/obj.go
@@ -2,6 +2,7 @@ package ber
import (
"bytes"
+ "io"
"strconv"
"strings"
)
@@ -15,7 +16,9 @@ func MarshalOID(obj OID) []byte {
if obj[0] < 2 && obj[1] > 39 {
return nil
}
- buf := bytes.NewBuffer(base128(obj[0]*40 + obj[1]))
+ buf := &bytes.Buffer{}
+ MarshalLen(buf, len(obj))
+ buf.Write(base128(obj[0]*40 + obj[1]))
for _, o := range obj[2:] {
buf.Write(base128(o))
}
@@ -26,20 +29,17 @@ func (o OID) Marshal() ([]byte, error) {
return MarshalOID(o), nil
}
-func UnmarshalOID(b []byte) (o OID) {
- if len(b) < 1 {
- return
- }
- v, n := debase128(b)
+func UnmarshalOID(r io.ByteReader) (o OID) {
+ l := UnmarshalLen(r)
+ v := Debase128(r)
if v < 80 {
o = OID{v / 40, v % 40}
} else {
o = OID{2, v - 80}
}
- for i := n; i < len(b); i += n {
- v, n = debase128(b[i:])
- o = append(o, v)
+ for i := 0; i < l; i++ {
+ o = append(o, Debase128(r))
}
return
}