Skip to content

Commit e5a6cb9

Browse files
committed
doc: add missing docstrings
Signed-off-by: Sergei Trofimov <[email protected]>
1 parent 45fb702 commit e5a6cb9

File tree

7 files changed

+43
-1
lines changed

7 files changed

+43
-1
lines changed

evidence.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,15 @@ import (
2020
cose "github.com/veraison/go-cose"
2121
)
2222

23+
// CBORCollection is a wrapper containing the CBOR data for both platform and
24+
// realm tokens.
2325
type CBORCollection struct {
2426
PlatformToken *[]byte `cbor:"44234,keyasint"`
2527
RealmToken *[]byte `cbor:"44241,keyasint"`
2628
}
2729

30+
// JSONCollection is a wrapper containing the JSON data for both platform and
31+
// realm tokens.
2832
type JSONCollection struct {
2933
PlatformToken json.RawMessage `json:"cca-platform-token,omitempty"`
3034
RealmToken json.RawMessage `json:"cca-realm-delegated-token,omitempty"`

platform/claims.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ import (
1313

1414
const ProfileName = "http://arm.com/CCA-SSD/1.0.0"
1515

16+
// Profile is the psatoken.IProfile implementation for CCA claims. It is
17+
// registered to associate the claims with the profile name, so that it can be
18+
// automatically used during unmarshaling.
1619
type Profile struct{}
1720

1821
func (o Profile) GetName() string {
@@ -23,6 +26,8 @@ func (o Profile) GetClaims() psatoken.IClaims {
2326
return NewClaims()
2427
}
2528

29+
// Claims contains the CCA platform claims. It implements IClaims, which is an
30+
// extension of psatoken.IClaims.
2631
type Claims struct {
2732
Profile *eat.Profile `cbor:"265,keyasint" json:"cca-platform-profile"`
2833
Challenge *eat.Nonce `cbor:"10,keyasint" json:"cca-platform-challenge"`
@@ -38,6 +43,7 @@ type Claims struct {
3843
CanonicalProfile string `cbor:"-" json:"-"`
3944
}
4045

46+
// NewClaims claims returns a new instance of Claims.
4147
func NewClaims() IClaims {
4248
p := eat.Profile{}
4349
if err := p.Set(ProfileName); err != nil {

platform/iclaims.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/veraison/psatoken"
1010
)
1111

12+
// IClaims extends psatoken.IClaims to add accessors for CCA claims.
1213
type IClaims interface {
1314
psatoken.IClaims
1415

@@ -19,6 +20,7 @@ type IClaims interface {
1920
SetHashAlgID(string) error
2021
}
2122

23+
// DecodeClaims unmarshals CCA platform claims from provided CBOR data.
2224
func DecodeClaims(buf []byte) (IClaims, error) {
2325
cl := NewClaims()
2426

@@ -29,6 +31,8 @@ func DecodeClaims(buf []byte) (IClaims, error) {
2931
return cl, nil
3032
}
3133

34+
// ValidateClaims returns an error if the provided IClaims instance does not
35+
// contain a valid set of CCA platform claims.
3236
func ValidateClaims(c IClaims) error {
3337
if err := psatoken.ValidateClaims(c); err != nil {
3438
return err

platform/lifecycle.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ const (
2626
LifecycleDecommissionedMax = 0x60ff
2727
)
2828

29+
// LifeCycleState indicates the life cycle state of attested device. The state
30+
// is derived from the life cycle claim value, with a range of values mapping
31+
// onto each state.
2932
type LifeCycleState uint16
3033

3134
const (
@@ -40,10 +43,12 @@ const (
4043
StateInvalid // must be last
4144
)
4245

46+
// IsValid returns true if the LifeCycleState has a valid value.
4347
func (o LifeCycleState) IsValid() bool {
4448
return o < StateInvalid
4549
}
4650

51+
// String returns a string representation of the life cycle state.
4752
func (o LifeCycleState) String() string {
4853
switch o {
4954
case StateUnknown:
@@ -65,6 +70,9 @@ func (o LifeCycleState) String() string {
6570
}
6671
}
6772

73+
// LifeCycleToState translates the provide life cycle claim value into
74+
// corresponding LifeCycleState.If the value is not within valid range, then
75+
// StateInvalid is returned.
6876
func LifeCycleToState(v uint16) LifeCycleState {
6977
if v >= LifecycleUnknownMin &&
7078
v <= LifecycleUnknownMax {
@@ -104,6 +112,8 @@ func LifeCycleToState(v uint16) LifeCycleState {
104112
return StateInvalid
105113
}
106114

115+
// ValidateSecurityLifeCycle returns an error if the provided value does not
116+
// correspond to a valid LifeCycleState.
107117
func ValidateSecurityLifeCycle(v uint16) error {
108118
if !LifeCycleToState(v).IsValid() {
109119
return fmt.Errorf("%w: value %d is invalid", psatoken.ErrWrongSyntax, v)

realm/claims.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"github.com/veraison/psatoken"
1010
)
1111

12+
// Claims contains the CCA realm claims. It implements IClaims, which is an
13+
// extension of psatoken.IClaimBase.
1214
type Claims struct {
1315
Challenge *eat.Nonce `cbor:"10,keyasint" json:"cca-realm-challenge"`
1416
PersonalizationValue *[]byte `cbor:"44235,keyasint" json:"cca-realm-personalization-value"`

realm/common.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ const (
1313
MaxLenRealmExtendedMeas = 4
1414
)
1515

16+
// ValidateChallenge returns an error if the provided value does not contain a
17+
// valid CCA challenge.
1618
func ValidateChallenge(v []byte) error {
1719
l := len(v)
1820

@@ -26,6 +28,8 @@ func ValidateChallenge(v []byte) error {
2628
return nil
2729
}
2830

31+
// ValidatePersonalizationValue returns an error if the provided value is not a
32+
// valid personalization value (must be exactly 64 bytes long).
2933
func ValidatePersonalizationValue(b []byte) error {
3034
l := len(b)
3135

@@ -38,8 +42,9 @@ func ValidatePersonalizationValue(b []byte) error {
3842
return nil
3943
}
4044

45+
// ValidateRealmPubKey returns an error if the provided value does not contain
46+
// a valid realm public key (must 97-byte ECC-P384).
4147
func ValidateRealmPubKey(b []byte) error {
42-
// Realm Public Key is ECC Public key of type ECC-P384 of size 97 bytes
4348
l := len(b)
4449

4550
if l != 97 {
@@ -59,6 +64,8 @@ func ValidateRealmPubKey(b []byte) error {
5964
return nil
6065
}
6166

67+
// ValidateRealmMeas returns an error if the provided value does not contain a
68+
// valid realm measurement (must be 32, 48, or 64 bytes long).
6269
func ValidateRealmMeas(b []byte) error {
6370
l := len(b)
6471

@@ -72,6 +79,8 @@ func ValidateRealmMeas(b []byte) error {
7279
return nil
7380
}
7481

82+
// ValidateHashAlgID returns an error if the provided value is not a valid
83+
// hash algorithm string.
7584
func ValidateHashAlgID(v string) error {
7685
if v == "" {
7786
return fmt.Errorf("%w: empty string", psatoken.ErrWrongSyntax)
@@ -80,6 +89,9 @@ func ValidateHashAlgID(v string) error {
8089
return nil
8190
}
8291

92+
// ValidateExtendedMeas returns an error if the provided slice does not contain
93+
// valid realm extended measurements (it must be non-empty, and each value must
94+
// be a valid ream measurement).
8395
func ValidateExtendedMeas(v [][]byte) error {
8496
if len(v) == 0 {
8597
return fmt.Errorf("%w realm extended measurements",

realm/iclaims.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@ type IClaims interface {
3232
SetPubKeyHashAlgID(string) error
3333
}
3434

35+
// NewClaims returns a new instance of platform Claims.
3536
func NewClaims() IClaims {
3637
return &Claims{}
3738
}
3839

40+
// DecodeClaims unmarshals CCA realm claims from provided CBOR data.
3941
func DecodeClaims(buf []byte) (IClaims, error) {
4042
cl := &Claims{}
4143

@@ -46,6 +48,8 @@ func DecodeClaims(buf []byte) (IClaims, error) {
4648
return cl, nil
4749
}
4850

51+
// ValidateClaims returns an error if the provided IClaims instance does not
52+
// contain a valid set of CCA realm claims.
4953
func ValidateClaims(c IClaims) error {
5054
if err := psatoken.FilterError(c.GetChallenge()); err != nil {
5155
return fmt.Errorf("validating realm challenge claim: %w", err)

0 commit comments

Comments
 (0)