forked from veraison/swid
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresources.go
More file actions
31 lines (22 loc) · 720 Bytes
/
resources.go
File metadata and controls
31 lines (22 loc) · 720 Bytes
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
// Copyright 2020 Contributors to the Veraison project.
// SPDX-License-Identifier: Apache-2.0
package swid
import "reflect"
// Resources models CoSWID resource-entry / [ 2* resource-entry ]
type Resources []Resource
// MarshalCBOR provides the custom CBOR marshaler for resource entries
func (ra Resources) MarshalCBOR() ([]byte, error) {
return arrayToCBOR(reflect.ValueOf(ra))
}
// UnmarshalCBOR provides the custom CBOR unmarshaler for resource entries
func (ra *Resources) UnmarshalCBOR(data []byte) error {
if (data[0] & 0xe0) == 0x80 {
return dm.Unmarshal(data, (*[]Resource)(ra))
}
var r Resource
if err := dm.Unmarshal(data, &r); err != nil {
return err
}
*ra = append(*ra, r)
return nil
}