From fc52fdee7f26d9c6eacc481d7d3f07db466141f6 Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Fri, 3 Apr 2026 14:22:52 -0600 Subject: [PATCH] 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. --- der/src/asn1/set_of.rs | 18 +++++++++--------- der/src/error.rs | 6 ++++++ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/der/src/asn1/set_of.rs b/der/src/asn1/set_of.rs index 576600013..3264c2d41 100644 --- a/der/src/asn1/set_of.rs +++ b/der/src/asn1/set_of.rs @@ -488,10 +488,11 @@ where /// Ensure set elements are lexicographically ordered using [`DerOrd`]. fn check_der_ordering(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 @@ -509,12 +510,11 @@ fn der_sort(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; } } } diff --git a/der/src/error.rs b/der/src/error.rs index 9f48c5014..e9f914695 100644 --- a/der/src/error.rs +++ b/der/src/error.rs @@ -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. @@ -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"),