-
Notifications
You must be signed in to change notification settings - Fork 2
/
entities.go
31 lines (22 loc) · 695 Bytes
/
entities.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
// Copyright 2020 Contributors to the Veraison project.
// SPDX-License-Identifier: Apache-2.0
package swid
import "reflect"
// Entities models entity-entry / [ 2* entity-entry ]
type Entities []Entity
// MarshalCBOR provides the custom CBOR marshaler for entity entries
func (ea Entities) MarshalCBOR() ([]byte, error) {
return arrayToCBOR(reflect.ValueOf(ea))
}
// UnmarshalCBOR provides the custom CBOR unmarshaler for entity entries
func (ea *Entities) UnmarshalCBOR(data []byte) error {
if (data[0] & 0xe0) == 0x80 {
return dm.Unmarshal(data, (*[]Entity)(ea))
}
var e Entity
if err := dm.Unmarshal(data, &e); err != nil {
return err
}
*ea = append(*ea, e)
return nil
}