diff options
Diffstat (limited to 'ber')
-rw-r--r-- | ber/int.go | 5 | ||||
-rw-r--r-- | ber/len.go | 5 |
2 files changed, 6 insertions, 4 deletions
@@ -2,11 +2,12 @@ package ber func UnmarshalInt(b []byte) (i int) { neg := b[0]&0x80 != 0 - for n, v := range b { + for _, v := range b { if neg { v = ^v } - i += int(v) << uint((len(b)-n-1)*8) + i <<= 8 + i |= int(v) } if neg { i = ^i @@ -23,9 +23,10 @@ func MarshalLen(i int) (b []byte) { if i < 0x80 { return []byte{byte(i)} } - for n := lenLen(i); n > 0; n-- { + n := lenLen(i) + b = append(b, byte(n)|0x80) + for ; n > 0; n-- { b = append(b, byte(i>>uint((n-1)*8))) } - b = append([]byte{byte(len(b) | 0x80)}, b...) return } |