Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 1 addition & 23 deletions der/src/asn1/set_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ where
result.inner.push(T::decode(reader)?)?;
}

// Ensure elements of the `SetOf` are sorted and will serialize as valid DER
der_sort(result.inner.as_mut())?;
validate(result.inner.as_ref())?;
Ok(result)
})
}
Expand Down Expand Up @@ -339,7 +339,6 @@ where
}

der_sort(inner.as_mut())?;
validate(inner.as_ref())?;
Ok(Self { inner })
})
}
Expand Down Expand Up @@ -473,27 +472,6 @@ fn der_sort<T: DerOrd>(slice: &mut [T]) -> Result<(), Error> {
Ok(())
}

/// Validate the elements of a `SET OF`, ensuring that they are all in order
/// and that there are no duplicates.
fn validate<T: DerOrd>(slice: &[T]) -> Result<(), Error> {
if let Some(len) = slice.len().checked_sub(1) {
for i in 0..len {
let j = i.checked_add(1).ok_or(ErrorKind::Overflow)?;

match slice.get(i..=j) {
Some([a, b]) => {
if a.der_cmp(b)? != Ordering::Less {
return Err(ErrorKind::SetOrdering.into());
}
}
_ => return Err(Tag::Set.value_error()),
}
}
}

Ok(())
}

#[cfg(test)]
#[allow(clippy::unwrap_used)]
mod tests {
Expand Down