Debian Codegraph @

ietf-cms/protocol/any_set_test.go

raw symbols SCIP
1 package protocol
2
3 import (
4 "bytes"
5 "encoding/asn1"
6 "encoding/hex"
7 "testing"
8 )
9
10 func TestAnySet(t *testing.T) {
11 // OpenSSL::ASN1::Set.new([
12 // OpenSSL::ASN1::Integer.new(OpenSSL::BN.new(5)),
13 // OpenSSL::ASN1::Integer.new(OpenSSL::BN.new(6))
14 // ])
15 der := []byte{49, 6, 2, 1, 5, 2, 1, 6}
16
17 var rv asn1.RawValue
18 if rest, err := asn1.Unmarshal(der, &rv); err != nil {
19 t.Fatal(err)
20 } else if len(rest) > 0 {
21 t.Fatal("trailing data")
22 }
23
24 as, err := DecodeAnySet(rv)
25 if err != nil {
26 t.Fatal(err)
27 }
28
29 if len(as.Elements) != 2 {
30 t.Fatal("bad decoded values")
31 }
32
33 var i int
34 if rest, err := asn1.Unmarshal(as.Elements[0].FullBytes, &i); err != nil {
35 t.Fatal(err)
36 } else if len(rest) > 0 {
37 t.Fatal("trailing data")
38 }
39 if i != 5 {
40 t.Fatalf("bad decoded value: %d", i)
41 }
42
43 if rest, err := asn1.Unmarshal(as.Elements[1].FullBytes, &i); err != nil {
44 t.Fatal(err)
45 } else if len(rest) > 0 {
46 t.Fatal("trailing data")
47 }
48 if i != 6 {
49 t.Fatalf("bad decoded value: %d", i)
50 }
51
52 var rv2 asn1.RawValue
53 if err := as.Encode(&rv2); err != nil {
54 t.Fatal(err)
55 }
56 if !bytes.Equal(rv.FullBytes, rv2.FullBytes) {
57 t.Fatal(hex.EncodeToString(rv2.FullBytes), " != ", hex.EncodeToString(rv.FullBytes))
58 }
59 }