aboutsummaryrefslogtreecommitdiff
path: root/ber
diff options
context:
space:
mode:
Diffstat (limited to 'ber')
-rw-r--r--ber/int.go5
-rw-r--r--ber/len.go5
2 files changed, 6 insertions, 4 deletions
diff --git a/ber/int.go b/ber/int.go
index 41defc8..a29e7dd 100644
--- a/ber/int.go
+++ b/ber/int.go
@@ -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
diff --git a/ber/len.go b/ber/len.go
index e1d7933..52bae63 100644
--- a/ber/len.go
+++ b/ber/len.go
@@ -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
}