Skip to content

Commit a3acd6c

Browse files
committed
Change ConditionallySelectable supertrait
To resolve dalek-cryptography#94, removes the `Copy` supertrait bound on `ConditionallySelectable`, replacing it with `Sized` instead. It turns out the bound is only used in the default implementation of `ConditionallySelectable::conditional_swap`, and is easy to replace by slightly changing that default implementation. Removing this supertrait bound is arguably a breaking change since it means types which impl `ConditionallySelectable` can no longer be assumed to be `Copy`, so also bumps the version to `3.0.0-pre`.
1 parent f1f8e53 commit a3acd6c

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ name = "subtle"
55
# - update html_root_url
66
# - update README if necessary by semver
77
# - if any updates were made to the README, also update the module documentation in src/lib.rs
8-
version = "2.6.0"
8+
version = "3.0.0-pre"
99
edition = "2018"
1010
authors = ["Isis Lovecruft <[email protected]>",
1111
"Henry de Valence <[email protected]>"]

src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ impl ConstantTimeEq for cmp::Ordering {
390390
//
391391
// #[inline] is specified on these function prototypes to signify that they
392392
#[allow(unused_attributes)] // should be in the actual implementation
393-
pub trait ConditionallySelectable: Copy {
393+
pub trait ConditionallySelectable: Sized {
394394
/// Select `a` or `b` according to `choice`.
395395
///
396396
/// # Returns
@@ -467,9 +467,9 @@ pub trait ConditionallySelectable: Copy {
467467
/// ```
468468
#[inline]
469469
fn conditional_swap(a: &mut Self, b: &mut Self, choice: Choice) {
470-
let t: Self = *a;
471-
a.conditional_assign(&b, choice);
472-
b.conditional_assign(&t, choice);
470+
let t = Self::conditional_select(a, b, choice);
471+
*b = Self::conditional_select(b, a, choice);
472+
*a = t;
473473
}
474474
}
475475

@@ -575,7 +575,7 @@ impl ConditionallySelectable for Choice {
575575
#[cfg(feature = "const-generics")]
576576
impl<T, const N: usize> ConditionallySelectable for [T; N]
577577
where
578-
T: ConditionallySelectable,
578+
T: ConditionallySelectable + Copy,
579579
{
580580
#[inline]
581581
fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self {

0 commit comments

Comments
 (0)