@@ -211,7 +211,7 @@ fn check_crls(
211
211
. map_err ( crl_signature_err) ?;
212
212
213
213
// Verify that if the issuer has a KeyUsage bitstring it asserts cRLSign.
214
- check_key_usage ( issuer_ku , KeyUsageMode :: CrlSign ) ?;
214
+ KeyUsageMode :: CrlSign . check ( issuer_ku ) ?;
215
215
216
216
// Try to find the cert serial in the verified CRL contents.
217
217
let cert_serial = cert. serial . as_slice_less_safe ( ) ;
@@ -430,6 +430,7 @@ pub(crate) static EKU_OCSP_SIGNING: KeyPurposeId =
430
430
431
431
// https://www.rfc-editor.org/rfc/rfc5280#section-4.2.1.3
432
432
#[ repr( u8 ) ]
433
+ #[ derive( Clone , Copy ) ]
433
434
enum KeyUsageMode {
434
435
// DigitalSignature = 0,
435
436
// ContentCommitment = 1,
@@ -442,24 +443,23 @@ enum KeyUsageMode {
442
443
// DecipherOnly = 8,
443
444
}
444
445
445
- // https://www.rfc-editor.org/rfc/rfc5280#section-4.2.1.3
446
- fn check_key_usage (
447
- input : Option < untrusted:: Input > ,
448
- required_ku_bit_if_present : KeyUsageMode ,
449
- ) -> Result < ( ) , Error > {
450
- let bit_string = match input {
451
- Some ( input) => input,
452
- // While RFC 5280 requires KeyUsage be present, historically the absence of a KeyUsage
453
- // has been treated as "Any Usage". We follow that convention here and assume the absence
454
- // of KeyUsage implies the required_ku_bit_if_present we're checking for.
455
- None => return Ok ( ( ) ) ,
456
- } ;
446
+ impl KeyUsageMode {
447
+ // https://www.rfc-editor.org/rfc/rfc5280#section-4.2.1.3
448
+ fn check ( self , input : Option < untrusted:: Input > ) -> Result < ( ) , Error > {
449
+ let bit_string = match input {
450
+ Some ( input) => input,
451
+ // While RFC 5280 requires KeyUsage be present, historically the absence of a KeyUsage
452
+ // has been treated as "Any Usage". We follow that convention here and assume the absence
453
+ // of KeyUsage implies the required_ku_bit_if_present we're checking for.
454
+ None => return Ok ( ( ) ) ,
455
+ } ;
457
456
458
- let flags = der:: bit_string_flags ( & mut untrusted:: Reader :: new ( bit_string) ) ?;
459
- #[ allow( clippy:: as_conversions) ] // u8 always fits in usize.
460
- match flags. bit_set ( required_ku_bit_if_present as usize ) {
461
- true => Ok ( ( ) ) ,
462
- false => Err ( Error :: IssuerNotCrlSigner ) ,
457
+ let flags = der:: bit_string_flags ( & mut untrusted:: Reader :: new ( bit_string) ) ?;
458
+ #[ allow( clippy:: as_conversions) ] // u8 always fits in usize.
459
+ match flags. bit_set ( self as usize ) {
460
+ true => Ok ( ( ) ) ,
461
+ false => Err ( Error :: IssuerNotCrlSigner ) ,
462
+ }
463
463
}
464
464
}
465
465
0 commit comments