6
6
"fmt"
7
7
8
8
"github.com/veraison/eat"
9
+ "github.com/veraison/psatoken"
9
10
)
10
11
11
12
type Claims struct {
@@ -21,7 +22,7 @@ type Claims struct {
21
22
// Setters
22
23
23
24
func (c * Claims ) SetChallenge (v []byte ) error {
24
- if err := isValidChallenge (v ); err != nil {
25
+ if err := ValidateChallenge (v ); err != nil {
25
26
return err
26
27
}
27
28
@@ -35,7 +36,7 @@ func (c *Claims) SetChallenge(v []byte) error {
35
36
}
36
37
37
38
func (c * Claims ) SetPersonalizationValue (v []byte ) error {
38
- if err := isValidPersonalizationValue (v ); err != nil {
39
+ if err := ValidatePersonalizationValue (v ); err != nil {
39
40
return err
40
41
}
41
42
@@ -44,7 +45,7 @@ func (c *Claims) SetPersonalizationValue(v []byte) error {
44
45
}
45
46
46
47
func (c * Claims ) SetInitialMeasurement (v []byte ) error {
47
- if err := isValidRealmMeas (v ); err != nil {
48
+ if err := ValidateRealmMeas (v ); err != nil {
48
49
return err
49
50
}
50
51
@@ -53,7 +54,7 @@ func (c *Claims) SetInitialMeasurement(v []byte) error {
53
54
}
54
55
55
56
func (c * Claims ) SetExtensibleMeasurements (v [][]byte ) error {
56
- if err := isValidExtensibleMeas (v ); err != nil {
57
+ if err := ValidateExtensibleMeas (v ); err != nil {
57
58
return err
58
59
}
59
60
@@ -62,7 +63,7 @@ func (c *Claims) SetExtensibleMeasurements(v [][]byte) error {
62
63
}
63
64
64
65
func (c * Claims ) SetHashAlgID (v string ) error {
65
- if err := isValidHashAlgID (v ); err != nil {
66
+ if err := ValidateHashAlgID (v ); err != nil {
66
67
return err
67
68
}
68
69
@@ -71,7 +72,7 @@ func (c *Claims) SetHashAlgID(v string) error {
71
72
}
72
73
73
74
func (c * Claims ) SetPubKey (v []byte ) error {
74
- if err := isValidRealmPubKey (v ); err != nil {
75
+ if err := ValidateRealmPubKey (v ); err != nil {
75
76
return err
76
77
}
77
78
@@ -81,7 +82,7 @@ func (c *Claims) SetPubKey(v []byte) error {
81
82
82
83
func (c * Claims ) SetPubKeyHashAlgID (v string ) error {
83
84
if v == "" {
84
- return fmt .Errorf ("invalid null string set for cca- realm- pubkey- hash-algo-id " )
85
+ return fmt .Errorf ("invalid null string set for realm pubkey hash alg ID " )
85
86
}
86
87
87
88
c .PublicKeyHashAlgID = & v
@@ -91,65 +92,69 @@ func (c *Claims) SetPubKeyHashAlgID(v string) error {
91
92
// Getters
92
93
func (c Claims ) GetChallenge () ([]byte , error ) {
93
94
v := c .Challenge
94
-
95
95
if v == nil {
96
- return nil , ErrMandatoryClaimMissing
96
+ return nil , psatoken . ErrMandatoryClaimMissing
97
97
}
98
98
99
99
l := v .Len ()
100
-
101
100
if l != 1 {
102
- return nil , fmt .Errorf ("%w: got %d nonces, want 1" , ErrWrongClaimSyntax , l )
101
+ return nil , fmt .Errorf ("%w: got %d nonces, want 1" , psatoken . ErrWrongSyntax , l )
103
102
}
104
103
105
104
n := v .GetI (0 )
106
- if err := isValidChallenge (n ); err != nil {
105
+ if err := ValidateChallenge (n ); err != nil {
107
106
return nil , err
108
107
}
108
+
109
109
return n , nil
110
110
}
111
111
112
112
func (c Claims ) GetPersonalizationValue () ([]byte , error ) {
113
113
v := c .PersonalizationValue
114
114
115
115
if v == nil {
116
- return nil , ErrMandatoryClaimMissing
116
+ return nil , psatoken . ErrMandatoryClaimMissing
117
117
}
118
- if err := isValidPersonalizationValue (* v ); err != nil {
118
+
119
+ if err := ValidatePersonalizationValue (* v ); err != nil {
119
120
return nil , err
120
121
}
122
+
121
123
return * v , nil
122
124
}
123
125
124
126
func (c Claims ) GetInitialMeasurement () ([]byte , error ) {
125
-
126
127
v := c .InitialMeasurement
127
128
if v == nil {
128
- return nil , ErrMandatoryClaimMissing
129
+ return nil , psatoken . ErrMandatoryClaimMissing
129
130
}
130
- if err := isValidRealmMeas (* v ); err != nil {
131
+
132
+ if err := ValidateRealmMeas (* v ); err != nil {
131
133
return nil , err
132
134
}
135
+
133
136
return * v , nil
134
137
}
135
138
136
139
func (c Claims ) GetExtensibleMeasurements () ([][]byte , error ) {
137
140
v := c .ExtensibleMeasurements
138
141
if v == nil {
139
- return nil , ErrMandatoryClaimMissing
142
+ return nil , psatoken . ErrMandatoryClaimMissing
140
143
}
141
- if err := isValidExtensibleMeas (* v ); err != nil {
144
+
145
+ if err := ValidateExtensibleMeas (* v ); err != nil {
142
146
return nil , err
143
147
}
148
+
144
149
return * v , nil
145
150
}
146
151
147
152
func (c Claims ) GetHashAlgID () (string , error ) {
148
153
v := c .HashAlgID
149
154
if v == nil {
150
- return "" , ErrMandatoryClaimMissing
155
+ return "" , psatoken . ErrMandatoryClaimMissing
151
156
}
152
- if err := isValidHashAlgID (* v ); err != nil {
157
+ if err := ValidateHashAlgID (* v ); err != nil {
153
158
return "" , err
154
159
}
155
160
return * v , nil
@@ -159,10 +164,10 @@ func (c Claims) GetPubKey() ([]byte, error) {
159
164
v := c .PublicKey
160
165
161
166
if v == nil {
162
- return nil , ErrMandatoryClaimMissing
167
+ return nil , psatoken . ErrMandatoryClaimMissing
163
168
}
164
169
165
- if err := isValidRealmPubKey (* v ); err != nil {
170
+ if err := ValidateRealmPubKey (* v ); err != nil {
166
171
return nil , err
167
172
}
168
173
@@ -173,14 +178,15 @@ func (c Claims) GetPubKeyHashAlgID() (string, error) {
173
178
v := c .PublicKeyHashAlgID
174
179
175
180
if v == nil {
176
- return "" , ErrMandatoryClaimMissing
181
+ return "" , psatoken . ErrMandatoryClaimMissing
177
182
}
183
+
178
184
return * v , nil
179
185
}
180
186
181
187
// Semantic validation
182
188
func (c Claims ) Validate () error {
183
- return validate (& c )
189
+ return ValidateClaims (& c )
184
190
}
185
191
186
192
// Codecs
@@ -227,31 +233,27 @@ func (c Claims) ToUnvalidatedCBOR() ([]byte, error) {
227
233
}
228
234
229
235
func (c * Claims ) FromJSON (buf []byte ) error {
230
- err := c .FromUnvalidatedJSON (buf )
231
- if err != nil {
236
+ if err := c .FromUnvalidatedJSON (buf ); err != nil {
232
237
return err
233
238
}
234
239
235
- err = c .Validate ()
236
- if err != nil {
240
+ if err := c .Validate (); err != nil {
237
241
return fmt .Errorf ("validation of CCA realm claims failed: %w" , err )
238
242
}
239
243
240
244
return nil
241
245
}
242
246
243
247
func (c * Claims ) FromUnvalidatedJSON (buf []byte ) error {
244
- err := json .Unmarshal (buf , c )
245
- if err != nil {
248
+ if err := json .Unmarshal (buf , c ); err != nil {
246
249
return fmt .Errorf ("JSON decoding of CCA realm claims failed: %w" , err )
247
250
}
248
251
249
252
return nil
250
253
}
251
254
252
255
func (c Claims ) ToJSON () ([]byte , error ) {
253
- err := c .Validate ()
254
- if err != nil {
256
+ if err := c .Validate (); err != nil {
255
257
return nil , fmt .Errorf ("validation of CCA realm claims failed: %w" , err )
256
258
}
257
259
0 commit comments