-
Notifications
You must be signed in to change notification settings - Fork 3
/
file_test.go
94 lines (87 loc) · 3.07 KB
/
file_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
// Copyright 2020 Contributors to the Veraison project.
// SPDX-License-Identifier: Apache-2.0
package swid
import (
"testing"
)
var (
key = true
size = int64(1024)
testFileSystemItemFull = FileSystemItem{
Key: &key,
Location: "bin/firmware.bin",
FsName: "firmware.bin",
Root: "/",
}
testFileSystemItemMinSet = FileSystemItem{
Location: "bin/firmware.bin",
FsName: "firmware.bin",
}
testFileFull = File{
FileSystemItem: testFileSystemItemFull,
Size: &size,
FileVersion: "v1.2",
Hash: &HashEntry{
HashAlgID: 1,
HashValue: []byte{0x00, 0x01},
},
}
testFileMinSet = File{
FileSystemItem: testFileSystemItemMinSet,
}
)
func TestFile_RoundtripFull(t *testing.T) {
tv := testFileFull
/*
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{
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 TestFile_RoundtripMinset(t *testing.T) {
tv := testFileMinSet
/*
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{
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)
}