aboutsummaryrefslogtreecommitdiff
path: root/ber
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-06-30 19:47:04 +0200
committerDimitri Sokolyuk <demon@dim13.org>2015-06-30 19:47:04 +0200
commit6c8904606f6455b82e5ec9fad5f18f1cd587d5ef (patch)
tree32f39df25afbf4d1d83636e2ce7925d7a14acb9c /ber
parent6905df6e3b4f00786311a07f30ad32c9a9de7213 (diff)
Add uint
Diffstat (limited to 'ber')
-rw-r--r--ber/class.go10
-rw-r--r--ber/int.go7
2 files changed, 17 insertions, 0 deletions
diff --git a/ber/class.go b/ber/class.go
index f2915fe..0839c05 100644
--- a/ber/class.go
+++ b/ber/class.go
@@ -116,3 +116,13 @@ func Ident(b []byte) (Class, Kind, Tag, int) {
}
return c, k, t, n + 1
}
+
+func Length(b []byte) (int, int) {
+ if b[0] & 0x80 != 0 {
+ l := b[0] & 0x7f
+ i := unmarshalUint(b[1:l+1])
+ return int(i), int(l+1)
+ } else {
+ return int(b[0]), 1
+ }
+}
diff --git a/ber/int.go b/ber/int.go
index a8fe19c..5bfcd89 100644
--- a/ber/int.go
+++ b/ber/int.go
@@ -32,6 +32,13 @@ func unmarshalInt(b []byte) (i int64) {
return
}
+func unmarshalUint(b []byte) (i int64) {
+ for n, v := range b {
+ i += int64(v) << uint((n-1)*8)
+ }
+ return
+}
+
func marshalInt(i int64) (b []byte) {
for n := intLen(i); n > 0; n-- {
b = append(b, byte(i>>uint((n-1)*8)))