-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswcomponent.go
100 lines (76 loc) · 2.23 KB
/
swcomponent.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
// Copyright 2021-2022 Contributors to the Veraison project.
// SPDX-License-Identifier: Apache-2.0
package psatoken
// SwComponent is the internal representation of a Software Component
type SwComponent struct {
MeasurementType *string `cbor:"1,keyasint,omitempty" json:"measurement-type,omitempty"`
MeasurementValue *[]byte `cbor:"2,keyasint" json:"measurement-value"`
Version *string `cbor:"4,keyasint,omitempty" json:"version,omitempty"`
SignerID *[]byte `cbor:"5,keyasint" json:"signer-id"`
MeasurementDesc *string `cbor:"6,keyasint,omitempty" json:"measurement-description,omitempty"`
}
func (sc SwComponent) Validate() error {
return ValidateSwComponent(&sc)
}
func (sc SwComponent) GetMeasurementValue() ([]byte, error) {
if sc.MeasurementValue == nil {
return nil, ErrMandatoryFieldMissing
}
if err := ValidatePSAHashType(*sc.MeasurementValue); err != nil {
return nil, err
}
return *sc.MeasurementValue, nil
}
func (sc SwComponent) GetSignerID() ([]byte, error) {
if sc.SignerID == nil {
return nil, ErrMandatoryFieldMissing
}
if err := ValidatePSAHashType(*sc.SignerID); err != nil {
return nil, err
}
return *sc.SignerID, nil
}
func (sc SwComponent) GetMeasurementType() (string, error) {
if sc.MeasurementType == nil {
return "", ErrOptionalFieldMissing
}
return *sc.MeasurementType, nil
}
func (sc SwComponent) GetMeasurementDesc() (string, error) {
if sc.MeasurementDesc == nil {
return "", ErrOptionalFieldMissing
}
return *sc.MeasurementDesc, nil
}
func (sc SwComponent) GetVersion() (string, error) {
if sc.Version == nil {
return "", ErrOptionalFieldMissing
}
return *sc.Version, nil
}
func (sc *SwComponent) SetMeasurementType(v string) error {
sc.MeasurementType = &v
return nil
}
func (sc *SwComponent) SetMeasurementValue(v []byte) error {
if err := ValidatePSAHashType(v); err != nil {
return err
}
sc.MeasurementValue = &v
return nil
}
func (sc *SwComponent) SetVersion(v string) error {
sc.Version = &v
return nil
}
func (sc *SwComponent) SetSignerID(v []byte) error {
if err := ValidatePSAHashType(v); err != nil {
return err
}
sc.SignerID = &v
return nil
}
func (sc *SwComponent) SetMeasurementDesc(v string) error {
sc.MeasurementDesc = &v
return nil
}