Skip to content

Commit 41ba936

Browse files
authored
BoxedUint: rename conditional_* methods for consistency (#397)
Some were previously named `cond_*` instead
1 parent 22aa6dd commit 41ba936

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

src/uint/boxed/ct.rs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,17 @@ impl BoxedUint {
6060
/// intermediate [`CtOption`] value and therefore isn't fully constant time, but the best we can
6161
/// do without upstream changes to `subtle` (see dalek-cryptography/subtle#94).
6262
///
63-
/// Workaround due to `Copy` in [`subtle::ConditionallySelectable`] supertrait bounds.
64-
pub fn cond_map<C, F, T>(&self, condition: C, f: F) -> CtOption<T>
63+
/// Workaround due to `Copy` in [`ConditionallySelectable`] supertrait bounds.
64+
pub fn conditional_map<C, F, T>(&self, condition: C, f: F) -> CtOption<T>
6565
where
6666
C: Fn(&Self) -> CtOption<Self>,
6767
F: Fn(Self) -> T,
6868
{
69-
let cond_val = condition(self);
70-
let is_some = cond_val.is_some();
69+
let conditional_val = condition(self);
70+
let is_some = conditional_val.is_some();
7171

7272
let placeholder = Self::zero_with_precision(self.bits_precision());
73-
let value = Option::<Self>::from(cond_val).unwrap_or(placeholder);
73+
let value = Option::<Self>::from(conditional_val).unwrap_or(placeholder);
7474
debug_assert_eq!(self.bits_precision(), value.bits_precision());
7575
CtOption::new(f(value), is_some)
7676
}
@@ -82,24 +82,24 @@ impl BoxedUint {
8282
/// intermediate [`CtOption`] value and therefore isn't fully constant time, but the best we can
8383
/// do without upstream changes to `subtle` (see dalek-cryptography/subtle#94).
8484
///
85-
/// Workaround due to `Copy` in [`subtle::ConditionallySelectable`] supertrait bounds.
86-
pub fn cond_and_then<C, F>(&self, condition: C, f: F) -> CtOption<Self>
85+
/// Workaround due to `Copy` in [`ConditionallySelectable`] supertrait bounds.
86+
pub fn conditional_and_then<C, F>(&self, condition: C, f: F) -> CtOption<Self>
8787
where
8888
C: Fn(&Self) -> CtOption<Self>,
8989
F: Fn(Self) -> CtOption<Self>,
9090
{
91-
let cond_val = condition(self);
92-
let mut is_some = cond_val.is_some();
91+
let conditional_val = condition(self);
92+
let mut is_some = conditional_val.is_some();
9393

9494
let placeholder = Self::zero_with_precision(self.bits_precision());
95-
let value = Option::<Self>::from(cond_val).unwrap_or(placeholder);
95+
let value = Option::<Self>::from(conditional_val).unwrap_or(placeholder);
9696
debug_assert_eq!(self.bits_precision(), value.bits_precision());
9797

98-
let cond_val = f(value);
99-
is_some &= cond_val.is_some();
98+
let conditional_val = f(value);
99+
is_some &= conditional_val.is_some();
100100

101101
let placeholder = Self::zero_with_precision(self.bits_precision());
102-
let value = Option::from(cond_val).unwrap_or(placeholder);
102+
let value = Option::from(conditional_val).unwrap_or(placeholder);
103103
debug_assert_eq!(self.bits_precision(), value.bits_precision());
104104

105105
CtOption::new(value, is_some)
@@ -121,11 +121,11 @@ mod tests {
121121
}
122122

123123
#[test]
124-
fn cond_map_some() {
124+
fn conditional_map_some() {
125125
let n = BoxedUint::one();
126126

127127
let ret = n
128-
.cond_map(
128+
.conditional_map(
129129
|n| CtOption::new(n.clone(), 1u8.into()),
130130
|n| n.wrapping_add(&BoxedUint::one()),
131131
)
@@ -135,10 +135,10 @@ mod tests {
135135
}
136136

137137
#[test]
138-
fn cond_map_none() {
138+
fn conditional_map_none() {
139139
let n = BoxedUint::one();
140140

141-
let ret = n.cond_map(
141+
let ret = n.conditional_map(
142142
|n| CtOption::new(n.clone(), 0u8.into()),
143143
|n| n.wrapping_add(&BoxedUint::one()),
144144
);
@@ -147,11 +147,11 @@ mod tests {
147147
}
148148

149149
#[test]
150-
fn cond_and_then_all_some() {
150+
fn conditional_and_then_all_some() {
151151
let n = BoxedUint::one();
152152

153153
let ret = n
154-
.cond_and_then(
154+
.conditional_and_then(
155155
|n| CtOption::new(n.clone(), 1u8.into()),
156156
|n| CtOption::new(n.wrapping_add(&BoxedUint::one()), 1u8.into()),
157157
)
@@ -160,13 +160,13 @@ mod tests {
160160
assert_eq!(ret, BoxedUint::from(2u8));
161161
}
162162

163-
macro_rules! cond_and_then_none_test {
163+
macro_rules! conditional_and_then_none_test {
164164
($name:ident, $a:expr, $b:expr) => {
165165
#[test]
166166
fn $name() {
167167
let n = BoxedUint::one();
168168

169-
let ret = n.cond_and_then(
169+
let ret = n.conditional_and_then(
170170
|n| CtOption::new(n.clone(), $a.into()),
171171
|n| CtOption::new(n.wrapping_add(&BoxedUint::one()), $b.into()),
172172
);
@@ -176,7 +176,7 @@ mod tests {
176176
};
177177
}
178178

179-
cond_and_then_none_test!(cond_and_then_none_some, 0, 1);
180-
cond_and_then_none_test!(cond_and_then_some_none, 1, 0);
181-
cond_and_then_none_test!(cond_and_then_none_none, 0, 0);
179+
conditional_and_then_none_test!(conditional_and_then_none_some, 0, 1);
180+
conditional_and_then_none_test!(conditional_and_then_some_none, 1, 0);
181+
conditional_and_then_none_test!(conditional_and_then_none_none, 0, 0);
182182
}

0 commit comments

Comments
 (0)