@@ -36,30 +36,27 @@ impl PublicKey {
36
36
role : KeyRole ,
37
37
payload : & PayloadBytes < ' _ > ,
38
38
signature : & SignatureBytes < ' _ > ,
39
- signed_revocation_info : Option < SignedPayload < RevocationInfo > > ,
39
+ signed_revocation_info : SignedPayload < RevocationInfo > ,
40
40
) -> Result < ( ) , Error > {
41
41
// We need to check if there is revoked content. If the following checks pass, then bail out
42
42
// early with an error.
43
43
// 1. Check if the expiration date has passed.
44
44
// 2. Check whether the `signature` is inside the vector
45
45
// `RevocationInfo.revoked_content_sha256`.
46
- if let Some ( revoked_hashes) = signed_revocation_info {
47
- let verified_revoked_content = revoked_hashes. get_verified ( self ) ?;
48
-
49
- let expiration_in_days =
50
- ( verified_revoked_content. expires_at - OffsetDateTime :: now_utc ( ) ) . whole_days ( ) ;
51
- if expiration_in_days < MAX_REVOCATION_INFO_EXPIRATION_DURATION {
52
- return Err ( Error :: VerificationFailed ) ;
53
- }
46
+ let verified_revoked_content = signed_revocation_info. get_verified ( self ) ?;
47
+ let expiration_in_days =
48
+ ( verified_revoked_content. expires_at - OffsetDateTime :: now_utc ( ) ) . whole_days ( ) ;
49
+ if expiration_in_days < MAX_REVOCATION_INFO_EXPIRATION_DURATION {
50
+ return Err ( Error :: VerificationFailed ) ;
51
+ }
54
52
55
- let based_signature =
56
- base64:: engine:: general_purpose:: STANDARD . encode ( signature. as_bytes ( ) ) ;
57
- if verified_revoked_content
58
- . revoked_content_sha256
59
- . contains ( & based_signature)
60
- {
61
- return Err ( Error :: VerificationFailed ) ;
62
- }
53
+ let based_signature =
54
+ base64:: engine:: general_purpose:: STANDARD . encode ( signature. as_bytes ( ) ) ;
55
+ if verified_revoked_content
56
+ . revoked_content_sha256
57
+ . contains ( & based_signature)
58
+ {
59
+ return Err ( Error :: VerificationFailed ) ;
63
60
}
64
61
65
62
self . verify_without_checking_revocations ( role, payload, signature) ?;
@@ -166,7 +163,7 @@ mod tests {
166
163
167
164
assert ! ( key
168
165
. public( )
169
- . verify ( KeyRole :: Root , & SAMPLE_PAYLOAD , & signature, None )
166
+ . verify_without_checking_revocations ( KeyRole :: Root , & SAMPLE_PAYLOAD , & signature)
170
167
. is_ok( ) )
171
168
}
172
169
@@ -177,7 +174,7 @@ mod tests {
177
174
178
175
assert ! ( key
179
176
. public( )
180
- . verify ( KeyRole :: Root , & SAMPLE_PAYLOAD , & signature, None )
177
+ . verify_without_checking_revocations ( KeyRole :: Root , & SAMPLE_PAYLOAD , & signature)
181
178
. is_ok( ) ) ;
182
179
}
183
180
@@ -187,8 +184,11 @@ mod tests {
187
184
let signature = key. sign ( & SAMPLE_PAYLOAD ) . unwrap ( ) ;
188
185
189
186
assert ! ( matches!(
190
- key. public( )
191
- . verify( KeyRole :: Packages , & SAMPLE_PAYLOAD , & signature, None ) ,
187
+ key. public( ) . verify_without_checking_revocations(
188
+ KeyRole :: Packages ,
189
+ & SAMPLE_PAYLOAD ,
190
+ & signature
191
+ ) ,
192
192
Err ( Error :: VerificationFailed )
193
193
) ) ;
194
194
}
@@ -199,8 +199,11 @@ mod tests {
199
199
let signature = key. sign ( & SAMPLE_PAYLOAD ) . unwrap ( ) ;
200
200
201
201
assert ! ( matches!(
202
- key. public( )
203
- . verify( KeyRole :: Unknown , & SAMPLE_PAYLOAD , & signature, None ) ,
202
+ key. public( ) . verify_without_checking_revocations(
203
+ KeyRole :: Unknown ,
204
+ & SAMPLE_PAYLOAD ,
205
+ & signature
206
+ ) ,
204
207
Err ( Error :: VerificationFailed )
205
208
) ) ;
206
209
}
@@ -211,8 +214,11 @@ mod tests {
211
214
let signature = key. sign ( & SAMPLE_PAYLOAD ) . unwrap ( ) ;
212
215
213
216
assert ! ( matches!(
214
- key. public( )
215
- . verify( KeyRole :: Root , & SAMPLE_PAYLOAD , & signature, None ) ,
217
+ key. public( ) . verify_without_checking_revocations(
218
+ KeyRole :: Root ,
219
+ & SAMPLE_PAYLOAD ,
220
+ & signature
221
+ ) ,
216
222
Err ( Error :: VerificationFailed )
217
223
) ) ;
218
224
}
@@ -226,11 +232,10 @@ mod tests {
226
232
* bad_signature. last_mut ( ) . unwrap ( ) = bad_signature. last ( ) . unwrap ( ) . wrapping_add ( 1 ) ;
227
233
228
234
assert ! ( matches!(
229
- key. public( ) . verify (
235
+ key. public( ) . verify_without_checking_revocations (
230
236
KeyRole :: Root ,
231
237
& SAMPLE_PAYLOAD ,
232
238
& SignatureBytes :: owned( bad_signature) ,
233
- None
234
239
) ,
235
240
Err ( Error :: VerificationFailed )
236
241
) ) ;
@@ -242,11 +247,10 @@ mod tests {
242
247
let signature = key. sign ( & SAMPLE_PAYLOAD ) . unwrap ( ) ;
243
248
244
249
assert ! ( matches!(
245
- key. public( ) . verify (
250
+ key. public( ) . verify_without_checking_revocations (
246
251
KeyRole :: Root ,
247
252
& PayloadBytes :: borrowed( "Hello world!" . as_bytes( ) ) ,
248
253
& signature,
249
- None
250
254
) ,
251
255
Err ( Error :: VerificationFailed )
252
256
) ) ;
@@ -257,11 +261,10 @@ mod tests {
257
261
let key = generate ( KeyRole :: Root , None ) ;
258
262
259
263
assert ! ( matches!(
260
- key. public( ) . verify (
264
+ key. public( ) . verify_without_checking_revocations (
261
265
KeyRole :: Root ,
262
266
& SAMPLE_PAYLOAD ,
263
267
& SignatureBytes :: borrowed( & [ ] ) ,
264
- None
265
268
) ,
266
269
Err ( Error :: VerificationFailed )
267
270
) ) ;
@@ -275,8 +278,11 @@ mod tests {
275
278
let signature = key1. sign ( & SAMPLE_PAYLOAD ) . unwrap ( ) ;
276
279
277
280
assert ! ( matches!(
278
- key2. public( )
279
- . verify( KeyRole :: Root , & SAMPLE_PAYLOAD , & signature, None ) ,
281
+ key2. public( ) . verify_without_checking_revocations(
282
+ KeyRole :: Root ,
283
+ & SAMPLE_PAYLOAD ,
284
+ & signature
285
+ ) ,
280
286
Err ( Error :: VerificationFailed )
281
287
) ) ;
282
288
}
@@ -290,7 +296,7 @@ mod tests {
290
296
public. algorithm = KeyAlgorithm :: Unknown ;
291
297
292
298
assert ! ( matches!(
293
- public. verify ( KeyRole :: Root , & SAMPLE_PAYLOAD , & signature, None ) ,
299
+ public. verify_without_checking_revocations ( KeyRole :: Root , & SAMPLE_PAYLOAD , & signature) ,
294
300
Err ( Error :: UnsupportedKey )
295
301
) ) ;
296
302
}
@@ -342,11 +348,10 @@ mod tests {
342
348
. unwrap ( ) ;
343
349
344
350
// Ensure the key can verify messages signed with the corresponding private key.
345
- key. verify (
351
+ key. verify_without_checking_revocations (
346
352
KeyRole :: Root ,
347
353
& SAMPLE_PAYLOAD ,
348
354
& SignatureBytes :: owned ( base64_decode ( SAMPLE_SIGNATURE ) . unwrap ( ) ) ,
349
- None ,
350
355
)
351
356
. unwrap ( ) ;
352
357
}
@@ -465,7 +470,7 @@ mod tests {
465
470
KeyRole :: Root ,
466
471
& SAMPLE_PAYLOAD ,
467
472
& signature,
468
- Some ( signed_revocation_info)
473
+ signed_revocation_info
469
474
) ,
470
475
Err ( Error :: VerificationFailed )
471
476
) ) ;
@@ -496,7 +501,7 @@ mod tests {
496
501
KeyRole :: Root ,
497
502
& SAMPLE_PAYLOAD ,
498
503
& signature,
499
- Some ( signed_revocation_info. clone( ) )
504
+ signed_revocation_info. clone( )
500
505
) ,
501
506
Err ( Error :: VerificationFailed )
502
507
) ) ;
@@ -506,7 +511,7 @@ mod tests {
506
511
KeyRole :: Revocation ,
507
512
& SAMPLE_PAYLOAD ,
508
513
& signature,
509
- Some ( signed_revocation_info)
514
+ signed_revocation_info
510
515
) ,
511
516
Err ( Error :: VerificationFailed )
512
517
) ) ;
0 commit comments