aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-07-07 23:05:19 +0200
committerDimitri Sokolyuk <demon@dim13.org>2015-07-07 23:05:19 +0200
commit67214db30959788af713ab6e165dd3fc56fa6d2e (patch)
tree16bf6c6cf652939f979d45c587e96353eaab1e37
parent8b2ca579d8274fe8ce3b2d30165c99066762c73a (diff)
Display BitString
-rw-r--r--ber/bits.go13
-rw-r--r--parse/parse.go2
2 files changed, 14 insertions, 1 deletions
diff --git a/ber/bits.go b/ber/bits.go
index 42474e5..107cd6b 100644
--- a/ber/bits.go
+++ b/ber/bits.go
@@ -16,3 +16,16 @@ func parseBitString(b []byte) (bs Bits) {
func UnmarshalBitString(b []byte) Bits {
return parseBitString(b)
}
+
+func (bs Bits) String() (s string) {
+ for i := 0; i < bs.Length; i++ {
+ x := i / 8
+ y := 7 - uint(i%8)
+ if bs.Bytes[x]&(1<<y) != 0 {
+ s += "1"
+ } else {
+ s += "0"
+ }
+ }
+ return
+}
diff --git a/parse/parse.go b/parse/parse.go
index 1a6a77f..f921a8b 100644
--- a/parse/parse.go
+++ b/parse/parse.go
@@ -20,7 +20,7 @@ func dump(b []byte, indent int) {
case ber.ObjectIdentifier:
fmt.Println(tag, ber.UnmarshalOID(value))
case ber.BitString:
- fmt.Println(tag, ber.UnmarshalBitString(value))
+ fmt.Println(tag, ber.UnmarshalBitString(value), value)
default:
if len(value) > 5 {
fmt.Println(tag, kind, value[:5], "...")