-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdirectory_test.go
121 lines (115 loc) · 4.87 KB
/
directory_test.go
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// Copyright 2020 Contributors to the Veraison project.
// SPDX-License-Identifier: Apache-2.0
package swid
import "testing"
func TestDirectory_RoundtripFlat(t *testing.T) {
tv := Directory{
FileSystemItem: testFileSystemItemMinSet,
PathElements: &PathElements{
Files: &Files{testFileFull},
},
}
/*
a3 # map(3)
17 # unsigned(23)
70 # text(16)
62696e2f6669726d776172652e62696e # "bin/firmware.bin"
18 18 # unsigned(24)
6c # text(12)
6669726d776172652e62696e # "firmware.bin"
18 1a # unsigned(26)
a1 # map(1)
11 # unsigned(17)
a7 # map(7)
16 # unsigned(22)
f5 # primitive(21)
17 # unsigned(23)
70 # text(16)
62696e2f6669726d776172652e62696e # "bin/firmware.bin"
18 18 # unsigned(24)
6c # text(12)
6669726d776172652e62696e # "firmware.bin"
18 19 # unsigned(25)
61 # text(1)
2f # "/"
14 # unsigned(20)
19 0400 # unsigned(1024)
15 # unsigned(21)
64 # text(4)
76312e32 # "v1.2"
07 # unsigned(7)
82 # array(2)
01 # unsigned(1)
42 # bytes(2)
0001 # "\x00\x01"
*/
expectedCBOR := []byte{
0xa3, 0x17, 0x70, 0x62, 0x69, 0x6e, 0x2f, 0x66, 0x69, 0x72, 0x6d,
0x77, 0x61, 0x72, 0x65, 0x2e, 0x62, 0x69, 0x6e, 0x18, 0x18, 0x6c,
0x66, 0x69, 0x72, 0x6d, 0x77, 0x61, 0x72, 0x65, 0x2e, 0x62, 0x69,
0x6e, 0x18, 0x1a, 0xa1, 0x11, 0xa7, 0x16, 0xf5, 0x17, 0x70, 0x62,
0x69, 0x6e, 0x2f, 0x66, 0x69, 0x72, 0x6d, 0x77, 0x61, 0x72, 0x65,
0x2e, 0x62, 0x69, 0x6e, 0x18, 0x18, 0x6c, 0x66, 0x69, 0x72, 0x6d,
0x77, 0x61, 0x72, 0x65, 0x2e, 0x62, 0x69, 0x6e, 0x18, 0x19, 0x61,
0x2f, 0x14, 0x19, 0x04, 0x00, 0x15, 0x64, 0x76, 0x31, 0x2e, 0x32,
0x07, 0x82, 0x01, 0x42, 0x00, 0x01,
}
roundTripper(t, tv, expectedCBOR)
}
func TestDirectory_RoundtripNested(t *testing.T) {
tv := Directory{
FileSystemItem: testFileSystemItemMinSet,
PathElements: &PathElements{
Directories: &Directories{
Directory{
FileSystemItem: testFileSystemItemMinSet,
PathElements: &PathElements{
Files: &Files{testFileMinSet},
},
},
},
},
}
/*
a3 # map(3)
17 # unsigned(23)
70 # text(16)
62696e2f6669726d776172652e62696e # "bin/firmware.bin"
18 18 # unsigned(24)
6c # text(12)
6669726d776172652e62696e # "firmware.bin"
18 1a # unsigned(26)
a1 # map(1)
10 # unsigned(16)
a3 # map(3)
17 # unsigned(23)
70 # text(16)
62696e2f6669726d776172652e62696e # "bin/firmware.bin"
18 18 # unsigned(24)
6c # text(12)
6669726d776172652e62696e # "firmware.bin"
18 1a # unsigned(26)
a1 # map(1)
11 # unsigned(17)
a2 # map(2)
17 # unsigned(23)
70 # text(16)
62696e2f6669726d776172652e62696e # "bin/firmware.bin"
18 18 # unsigned(24)
6c # text(12)
6669726d776172652e62696e # "firmware.bin"
*/
expectedCBOR := []byte{
0xa3, 0x17, 0x70, 0x62, 0x69, 0x6e, 0x2f, 0x66, 0x69, 0x72, 0x6d,
0x77, 0x61, 0x72, 0x65, 0x2e, 0x62, 0x69, 0x6e, 0x18, 0x18, 0x6c,
0x66, 0x69, 0x72, 0x6d, 0x77, 0x61, 0x72, 0x65, 0x2e, 0x62, 0x69,
0x6e, 0x18, 0x1a, 0xa1, 0x10, 0xa3, 0x17, 0x70, 0x62, 0x69, 0x6e,
0x2f, 0x66, 0x69, 0x72, 0x6d, 0x77, 0x61, 0x72, 0x65, 0x2e, 0x62,
0x69, 0x6e, 0x18, 0x18, 0x6c, 0x66, 0x69, 0x72, 0x6d, 0x77, 0x61,
0x72, 0x65, 0x2e, 0x62, 0x69, 0x6e, 0x18, 0x1a, 0xa1, 0x11, 0xa2,
0x17, 0x70, 0x62, 0x69, 0x6e, 0x2f, 0x66, 0x69, 0x72, 0x6d, 0x77,
0x61, 0x72, 0x65, 0x2e, 0x62, 0x69, 0x6e, 0x18, 0x18, 0x6c, 0x66,
0x69, 0x72, 0x6d, 0x77, 0x61, 0x72, 0x65, 0x2e, 0x62, 0x69, 0x6e,
}
roundTripper(t, tv, expectedCBOR)
}