diff options
Diffstat (limited to 'ber/obj.go')
-rw-r--r-- | ber/obj.go | 18 |
1 files changed, 9 insertions, 9 deletions
@@ -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 } |