Skip to content

Commit

Permalink
Simplify X.509 certificate validity check (#247)
Browse files Browse the repository at this point in the history
This is now 5 lines of code, but I feel they’re simpler lines than
what came before.
  • Loading branch information
mgeisler authored Jan 23, 2025
1 parent c198d38 commit 0e6faa4
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions mls-rs-crypto-rustcrypto/src/x509/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,11 @@ fn verify_time(cert: &Certificate, time: MlsTime) -> Result<(), X509Error> {
let not_before = validity.not_before.to_unix_duration().as_secs();
let not_after = validity.not_after.to_unix_duration().as_secs();

(not_before <= now && now <= not_after)
.then_some(())
.ok_or_else(|| X509Error::ValidityError(now, format!("{cert:?}")))
if not_before <= now && now <= not_after {
Ok(())
} else {
Err(X509Error::ValidityError(now, format!("{cert:?}")))
}
}

fn verify_cert(
Expand Down

0 comments on commit 0e6faa4

Please sign in to comment.