aboutsummaryrefslogtreecommitdiff
path: root/ber/obj_test.go
blob: 27fd8e6ec7799f0079560f71133d4a72e3f1a185 (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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package ber

import (
	"bytes"
	"testing"
)

type base128Test struct {
	in  int
	out []byte
}

var base128TestData = []base128Test{
	{643, []byte{0x85, 0x03}},
	{113549, []byte{0x86, 0xF7, 0x0D}},
	{49152, []byte{0x83, 0x80, 0x00}},
}

func TestBase128(t *testing.T) {
	for _, test := range base128TestData {
		n := base128(test.in)
		if !bytes.Equal(n, test.out) {
			t.Error(test.in, "expected", test.out, "got", n)
		}
	}
}

type oidTest struct {
	oid OID
	out []byte
}

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

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)
		}
	}
}