aboutsummaryrefslogtreecommitdiff
path: root/ber/obj_test.go
blob: 53ea7f5bbd883e054d27e05b318ad56eccd94b0a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package ber

import (
	"bytes"
	"testing"
)

type oidTest struct {
	oid   OID
	out   []byte
	valid bool
}

var oidTestData = []oidTest{
	{OID{1, 3, 12, 0, 218},
		[]byte{0x2B, 0x0C, 0x00, 0x81, 0x5A}, true},
	{OID{1, 3, 12, 0, 285, 200},
		[]byte{0x2B, 0x0C, 0x00, 0x82, 0x1D, 0x81, 0x48}, true},
	{OID{}, []byte{}, false},
	{OID{0, 39}, []byte{0x27}, true},
	{OID{1, 39}, []byte{0x4f}, true},
	{OID{1, 40}, []byte{}, false},
	{OID{2, 40}, []byte{0x78}, true},
}

func TestOID(t *testing.T) {
	for _, test := range oidTestData {
		oid := MarshalOID(test.oid)
		if !bytes.Equal(oid, test.out) {
			t.Error(test.oid, "expected", test.out, "got", oid)
		}
		out := UnmarshalOID(test.out)
		if test.valid && !out.Equal(test.oid) {
			t.Error(test.out, "expected", test.oid, "got", out)
		}
	}
}