Skip to content
Merged
Show file tree
Hide file tree
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
18 changes: 9 additions & 9 deletions der/src/asn1/set_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,10 +488,11 @@ where

/// Ensure set elements are lexicographically ordered using [`DerOrd`].
fn check_der_ordering<T: DerOrd>(a: &T, b: &T) -> Result<(), Error> {
match a.der_cmp(b)? {
Ordering::Less | Ordering::Equal => Ok(()),
Ordering::Greater => Err(ErrorKind::SetOrdering.into()),
if a.der_cmp(b)? == Ordering::Greater {
return Err(ErrorKind::SetOrdering.into());
}

Ok(())
}

/// Sort a mut slice according to its [`DerOrd`], returning any errors which
Expand All @@ -509,12 +510,11 @@ fn der_sort<T: DerOrd>(slice: &mut [T]) -> Result<(), Error> {
let mut j = i;

while j > 0 {
match slice[j - 1].der_cmp(&slice[j])? {
Ordering::Less | Ordering::Equal => break,
Ordering::Greater => {
slice.swap(j - 1, j);
j -= 1;
}
if slice[j - 1].der_cmp(&slice[j])? == Ordering::Greater {
slice.swap(j - 1, j);
j -= 1;
} else {
break;
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions der/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,11 @@ pub enum ErrorKind {
},

/// `SET` cannot contain duplicates.
// TODO(tarcieri): remove this in the next breaking release
#[deprecated(
since = "0.8.1",
note = "per X.680, 27.3 NOTE 3 duplicates are allowed"
)]
SetDuplicate,

/// `SET` ordering error: items not in canonical order.
Expand Down Expand Up @@ -376,6 +381,7 @@ impl fmt::Display for ErrorKind {
ErrorKind::OidUnknown { oid } => {
write!(f, "unknown/unsupported OID: {oid}")
}
#[allow(deprecated)]
ErrorKind::SetDuplicate => write!(f, "SET OF contains duplicate"),
ErrorKind::SetOrdering => write!(f, "SET OF ordering error"),
ErrorKind::Overflow => write!(f, "integer overflow"),
Expand Down