Skip to content

Commit 002b1c2

Browse files
committed
der: deprecate ErrorKind::SetDuplicate
Followup to #2272 which addressed #2271 by allowing duplicates, as they are allowed per X.680 and X.690. Also includes some small logic cleanups.
1 parent 223f522 commit 002b1c2

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

der/src/asn1/set_of.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -488,10 +488,11 @@ where
488488

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

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

511512
while j > 0 {
512-
match slice[j - 1].der_cmp(&slice[j])? {
513-
Ordering::Less | Ordering::Equal => break,
514-
Ordering::Greater => {
515-
slice.swap(j - 1, j);
516-
j -= 1;
517-
}
513+
if slice[j - 1].der_cmp(&slice[j])? == Ordering::Greater {
514+
slice.swap(j - 1, j);
515+
j -= 1;
516+
} else {
517+
break;
518518
}
519519
}
520520
}

der/src/error.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,11 @@ pub enum ErrorKind {
265265
},
266266

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

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

0 commit comments

Comments
 (0)