-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathjson_metadata.go
More file actions
103 lines (90 loc) · 2.97 KB
/
json_metadata.go
File metadata and controls
103 lines (90 loc) · 2.97 KB
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
package luks
import (
"encoding/json"
"fmt"
)
type keyslot struct {
Type string `json:"type"`
KeySize uint `json:"key_size"`
Af antiForensic `json:"af"`
Area area `json:"area"`
Kdf kdf `json:"kdf"`
// Priority is a pointer to distinguish three states:
// nil = normal priority (default), 0 = ignore (skip slot), 1 = normal, 2 = high (prefer)
Priority *int `json:"priority"`
}
type antiForensic struct {
Type string `json:"type"`
Stripes uint `json:"stripes"`
Hash string `json:"hash"`
}
type area struct {
Type string `json:"type"`
Encryption string `json:"encryption"`
KeySize uint `json:"key_size"`
Offset json.Number `json:"offset"`
Size json.Number `json:"size"`
}
type kdf struct {
Type string `json:"type"`
Salt string `json:"salt"`
// pbkdf2 specific fields
Hash string `json:"hash"`
Iterations uint `json:"iterations"`
// argon2i fields
Time uint `json:"time"`
Memory uint `json:"memory"`
Cpus uint `json:"cpus"`
}
type segment struct {
Type string `json:"type"`
Offset json.Number `json:"offset"`
IvTweak json.Number `json:"iv_tweak"`
Size string `json:"size"` // "dynamic" (fill remaining space) or a decimal byte count
Encryption string `json:"encryption"`
SectorSize uint `json:"sector_size"`
Flags []string `json:"flags"`
}
type digest struct {
Type string `json:"type"`
Keyslots []json.Number `json:"keyslots"`
Segments []json.Number `json:"segments"`
Hash string `json:"hash"`
Iterations uint `json:"iterations"`
Salt string `json:"salt"`
Digest string `json:"digest"`
}
// configRequirements handles the LUKS2 config requirements field, which may be
// either a JSON array of strings (["opal"]) as per spec, or a JSON object
// ({"mandatory": ["opal"]}) as emitted by cryptsetup in practice.
type configRequirements []string
func (r *configRequirements) UnmarshalJSON(data []byte) error {
// Try the spec-compliant array form: ["opal", ...]
var arr []string
if err := json.Unmarshal(data, &arr); err == nil {
*r = arr
return nil
}
// Try the cryptsetup object form: {"mandatory": ["opal", ...]}
var obj struct {
Mandatory []string `json:"mandatory"`
}
if err := json.Unmarshal(data, &obj); err != nil {
return fmt.Errorf("config.requirements: cannot parse as array or object: %w", err)
}
*r = obj.Mandatory
return nil
}
type config struct {
JSONSize json.Number `json:"json_size"`
KeyslotsSize json.Number `json:"keyslots_size"`
Flags []string `json:"flags"`
Requirements configRequirements `json:"requirements"`
}
type metadata struct {
Keyslots map[int]keyslot `json:"keyslots"`
Tokens map[int]json.RawMessage `json:"tokens"`
Segments map[int]segment `json:"segments"`
Digests map[int]digest `json:"digests"`
Config config `json:"config"`
}