-
Notifications
You must be signed in to change notification settings - Fork 0
/
iswcomponent.go
52 lines (41 loc) · 1.45 KB
/
iswcomponent.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
// Copyright 2024 Contributors to the Veraison project.
// SPDX-License-Identifier: Apache-2.0
package psatoken
import "fmt"
// ISwComponent defines the interface for the software component composite
// claim.
type ISwComponent interface {
Validate() error
GetMeasurementType() (string, error)
GetMeasurementValue() ([]byte, error)
GetVersion() (string, error)
GetSignerID() ([]byte, error)
GetMeasurementDesc() (string, error)
SetMeasurementType(v string) error
SetMeasurementValue(v []byte) error
SetVersion(v string) error
SetSignerID(v []byte) error
SetMeasurementDesc(v string) error
}
// ValidateSwComponent returns an error if validation fails for any of the
// fields of a software component claim. This function may be used by new
// ISwComponent implementations that do not embed existing SwComponent, and so
// cannot rely on its Validate() method.
func ValidateSwComponent(c ISwComponent) error {
if err := FilterError(c.GetMeasurementType()); err != nil {
return fmt.Errorf("measurement type: %w", err)
}
if err := FilterError(c.GetMeasurementValue()); err != nil {
return fmt.Errorf("measurement value: %w", err)
}
if err := FilterError(c.GetVersion()); err != nil {
return fmt.Errorf("version: %w", err)
}
if err := FilterError(c.GetSignerID()); err != nil {
return fmt.Errorf("signer ID: %w", err)
}
if err := FilterError(c.GetMeasurementDesc()); err != nil {
return fmt.Errorf("measurement description: %w", err)
}
return nil
}