Skip to content

Commit e0ba976

Browse files
committed
Simplify logic for parsing leaf from raw chain
1 parent 60a313a commit e0ba976

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

crates/x509_util/src/lib.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -217,15 +217,13 @@ pub fn validate_chain_lax<T, E, F>(
217217
where
218218
F: FnOnce(Certificate, Vec<&Certificate>, Vec<[u8; 32]>, Option<usize>) -> Result<T, E>,
219219
{
220-
if raw_chain.is_empty() {
221-
return Err(ValidationError::EmptyChain.into());
222-
}
223-
224-
// Parse the first element of the chain, i.e., the leaf
225-
// The first element exists because we just checked the chain is not empty
226-
let leaf = Certificate::from_der(&raw_chain[0]).map_err(ValidationError::from)?;
220+
// Parse the first element of the chain, i.e., the leaf.
221+
let leaf = match raw_chain.first() {
222+
Some(cert) => Certificate::from_der(cert).map_err(ValidationError::from)?,
223+
None => return Err(ValidationError::EmptyChain.into()),
224+
};
227225

228-
// Check whether the expiry date is within the acceptable range
226+
// Check whether the expiry date is within the acceptable range.
229227
let not_after = u64::try_from(
230228
leaf.tbs_certificate
231229
.validity

0 commit comments

Comments
 (0)