aboutsummaryrefslogtreecommitdiff
path: root/ber
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-09-26 11:00:49 +0200
committerDimitri Sokolyuk <demon@dim13.org>2015-09-26 11:00:49 +0200
commit10072d47dc644623e5d68add486371764d1a2823 (patch)
tree1db868cfeb43f2385669b213dfac96316489ad4a /ber
parent06867ef872b0726492a0aeeefbcc3baef4e3b076 (diff)
Fix Equal method
Diffstat (limited to 'ber')
-rw-r--r--ber/new/ber_test.go42
-rw-r--r--ber/new/common.go6
2 files changed, 31 insertions, 17 deletions
diff --git a/ber/new/ber_test.go b/ber/new/ber_test.go
index 40118db..8365987 100644
--- a/ber/new/ber_test.go
+++ b/ber/new/ber_test.go
@@ -73,38 +73,46 @@ func TestString(t *testing.T) {
}
type oidTest struct {
- val OID
- out []byte
+ val OID
+ out []byte
+ valid bool
}
var oidTestData = []oidTest{
{
- val: OID{1, 3, 12, 0, 218},
- out: []byte{0x05, 0x2B, 0x0C, 0x00, 0x81, 0x5A},
+ val: OID{1, 3, 12, 0, 218},
+ out: []byte{0x05, 0x2B, 0x0C, 0x00, 0x81, 0x5A},
+ valid: true,
},
{
- val: OID{1, 3, 12, 0, 285, 200},
- out: []byte{0x07, 0x2B, 0x0C, 0x00, 0x82, 0x1D, 0x81, 0x48},
+ val: OID{1, 3, 12, 0, 285, 200},
+ out: []byte{0x07, 0x2B, 0x0C, 0x00, 0x82, 0x1D, 0x81, 0x48},
+ valid: true,
},
{
- val: OID{0, 39},
- out: []byte{0x01, 0x27},
+ val: OID{0, 39},
+ out: []byte{0x01, 0x27},
+ valid: true,
},
{
- val: OID{1, 39},
- out: []byte{0x01, 0x4f},
+ val: OID{1, 39},
+ out: []byte{0x01, 0x4f},
+ valid: true,
},
{
- val: OID{2, 40},
- out: []byte{0x01, 0x78},
+ val: OID{2, 40},
+ out: []byte{0x01, 0x78},
+ valid: true,
},
{
- val: OID{},
- out: []byte{},
+ val: OID{},
+ out: []byte{},
+ valid: true,
},
{
- val: OID{1, 40},
- out: []byte{},
+ val: OID{1, 40},
+ out: []byte{},
+ valid: false,
},
}
@@ -117,7 +125,7 @@ func TestOID(t *testing.T) {
t.Error(test.val, "expected", test.out, "got", o)
}
v := s.unmarshalOID()
- if !v.Equal(test.val) {
+ if !v.Equal(test.val) && test.valid {
t.Error(test.out, "expected", test.val, "got", v)
}
}
diff --git a/ber/new/common.go b/ber/new/common.go
index b5884ae..7c4f496 100644
--- a/ber/new/common.go
+++ b/ber/new/common.go
@@ -28,6 +28,9 @@ func (s *state) next() []byte {
type OID []int
func (o OID) Equal(p OID) bool {
+ if len(o) != len(p) {
+ return false
+ }
for i := range o {
if o[i] != p[i] {
return false
@@ -47,6 +50,9 @@ func (o OID) String() string {
type BitString []bool
func (o BitString) Equal(p BitString) bool {
+ if len(o) != len(p) {
+ return false
+ }
for i := range o {
if o[i] != p[i] {
return false