File: marshal_test.go

package info (click to toggle)
golang-github-geoffgarside-ber 1.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 180 kB
  • sloc: makefile: 2
file content (40 lines) | stat: -rw-r--r-- 949 bytes parent folder | download
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
package ber

import (
	"bytes"
	"encoding/asn1"
	"encoding/hex"
	"testing"
)

type marshalTest struct {
	in  interface{}
	out string // hex encoded
}

var marshalTests = []marshalTest{
	{asn1.ObjectIdentifier([]int{1, 2, 3, 4}), "06032a0304"},
	{asn1.ObjectIdentifier([]int{1, 2, 840, 133549, 1, 1, 5}), "06092a864888932d010105"},
	{asn1.ObjectIdentifier([]int{2, 100, 3}), "0603813403"},

	// Ensure large OID suboids are marshalled correctly
	// See ber_64bit_test.go for none 32-bit compatible examples.
	{
		asn1.ObjectIdentifier([]int{1, 3, 6, 1, 2, 1, 31, 1, 1, 1, 1, 1090781219}),
		"060f2b060102011f010101018488908023",
	},
}

func TestMarshal(t *testing.T) {
	for i, test := range marshalTests {
		data, err := Marshal(test.in)
		if err != nil {
			t.Errorf("#%d failed: %s", i, err)
		}
		out, _ := hex.DecodeString(test.out)
		if !bytes.Equal(out, data) {
			t.Errorf("#%d got: %x want %x\n\t%q\n\t%q", i, data, out, data, out)

		}
	}
}