Skip to content

Commit

Permalink
Hoist general_subtree() helper out of loops
Browse files Browse the repository at this point in the history
  • Loading branch information
djc committed Jul 31, 2023
1 parent a0e6434 commit b7434a2
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/subject_name/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ fn check_presented_id_conforms_to_constraints(
(Subtrees::ExcludedSubtrees, excluded_subtrees),
];

fn general_subtree<'b>(input: &mut untrusted::Reader<'b>) -> Result<GeneralName<'b>, Error> {
der::expect_tag_and_get_value(input, der::Tag::Sequence)?
.read_all(Error::BadDer, GeneralName::from_der)
}

for (subtrees, constraints) in subtrees {
let mut constraints = match constraints {
Some(constraints) => untrusted::Reader::new(constraints),
Expand All @@ -176,13 +181,6 @@ fn check_presented_id_conforms_to_constraints(
// Since the default value isn't allowed to be encoded according to the
// DER encoding rules for DEFAULT, this is equivalent to saying that
// neither minimum or maximum must be encoded.
fn general_subtree<'b>(
input: &mut untrusted::Reader<'b>,
) -> Result<GeneralName<'b>, Error> {
let general_subtree = der::expect_tag_and_get_value(input, der::Tag::Sequence)?;
general_subtree.read_all(Error::BadDer, GeneralName::from_der)
}

let base = match general_subtree(&mut constraints) {
Ok(base) => base,
Err(err) => return Some(Err(err)),
Expand Down

0 comments on commit b7434a2

Please sign in to comment.