aboutsummaryrefslogtreecommitdiff
path: root/ber/bitstring.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-09-26 12:04:34 +0200
committerDimitri Sokolyuk <demon@dim13.org>2015-09-26 12:04:34 +0200
commit54caa4e7e085e177ff05b719ae247d21fe8c257e (patch)
tree363400fe1c6c1e7b696c72caaabc4882756355fa /ber/bitstring.go
parent1fcefc99a82bac6ce725b6f11277e4aa291a7f51 (diff)
Replace with new implementation
Diffstat (limited to 'ber/bitstring.go')
-rw-r--r--ber/bitstring.go93
1 files changed, 0 insertions, 93 deletions
diff --git a/ber/bitstring.go b/ber/bitstring.go
deleted file mode 100644
index eabc354..0000000
--- a/ber/bitstring.go
+++ /dev/null
@@ -1,93 +0,0 @@
-package ber
-
-// BitString
-type BitString []bool
-
-func UnmarshalBitString(b []byte) (bs BitString) {
- padding := int(b[0])
- length := (len(b)-1)*8 - padding
- for i := 0; i < length; i++ {
- x := 1 + i/8
- y := 7 - uint(i%8)
- bit := b[x]&(1<<y) != 0
- bs = append(bs, bit)
- }
- return
-}
-
-func MarshalBitString(bs BitString) (b []byte) {
- padding := (8 - len(bs)%8) % 8
- length := len(bs) / 8
- if padding != 0 {
- length++
- }
- b = make([]byte, length+1)
- b[0] = byte(padding)
- for i, bi := range bs {
- x := 1 + i/8
- y := 7 - uint(i%8)
- if bi {
- b[x] |= 1 << y
- }
- }
- return
-}
-
-func (bs BitString) String() (s string) {
- bmap := map[bool]string{
- true: "1",
- false: "0",
- }
- for i, bit := range bs {
- if i > 0 && i%4 == 0 {
- s += " "
- }
- s += bmap[bit]
- }
- return
-}
-
-func (bs BitString) IsSet(n int) bool {
- if n > len(bs) {
- return false
- }
- return bs[n]
-}
-
-func pow2(n int) int {
- i := 1
- for i < n+1 {
- i <<= 1
- }
- return i
-}
-
-func (bs *BitString) Set(n int) {
- if len(*bs) < n {
- nbs := make(BitString, pow2(n))
- copy(nbs, *bs)
- *bs = nbs
- }
- (*bs)[n] = true
-}
-
-func (bs *BitString) Clear(n int) {
- if len(*bs) < n {
- nbs := make(BitString, pow2(n))
- copy(nbs, *bs)
- *bs = nbs
- }
- (*bs)[n] = false
-}
-
-func (bs BitString) Equal(s BitString) bool {
- if len(bs) != len(s) {
- return false
- }
- for i := 0; i < len(bs); i++ {
- if bs[i] != s[i] {
- return false
- }
- }
- return true
-}