Skip to content

Commit 4bf6932

Browse files
authored
BoxedUint: use Integer::{is_even, is_odd} (#424)
Avoid redefining these methods by using the provided impls on the trait
1 parent 270546f commit 4bf6932

File tree

5 files changed

+4
-31
lines changed

5 files changed

+4
-31
lines changed

src/modular/boxed_residue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use super::{
1212
reduction::{montgomery_reduction_boxed, montgomery_reduction_boxed_mut},
1313
Retrieve,
1414
};
15-
use crate::{BoxedUint, Limb, NonZero, Word};
15+
use crate::{BoxedUint, Integer, Limb, NonZero, Word};
1616
use subtle::CtOption;
1717

1818
#[cfg(feature = "std")]

src/uint/boxed.rs

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -98,29 +98,6 @@ impl BoxedUint {
9898
iter.fold(choice, |acc, limb| acc & limb.is_zero())
9999
}
100100

101-
/// Is this integer value an odd number?
102-
///
103-
/// # Returns
104-
///
105-
/// If odd, returns `Choice(1)`. Otherwise, returns `Choice(0)`.
106-
// TODO(tarcieri): impl the `Integer` trait
107-
pub fn is_odd(&self) -> Choice {
108-
self.limbs
109-
.first()
110-
.map(|limb| limb.is_odd())
111-
.unwrap_or_else(|| Choice::from(0))
112-
}
113-
114-
/// Is this integer value an even number?
115-
///
116-
/// # Returns
117-
///
118-
/// If even, returns `Choice(1)`. Otherwise, returns `Choice(0)`.
119-
// TODO(tarcieri): impl the `Integer` trait
120-
pub fn is_even(&self) -> Choice {
121-
!self.is_odd()
122-
}
123-
124101
/// Get the maximum value for a `BoxedUint` created with `at_least_bits_precision`
125102
/// precision bits requested.
126103
///
@@ -415,10 +392,6 @@ impl Integer for BoxedUint {
415392
fn nlimbs(&self) -> usize {
416393
self.nlimbs()
417394
}
418-
419-
fn is_odd(&self) -> Choice {
420-
self.is_odd()
421-
}
422395
}
423396

424397
impl Zero for BoxedUint {

src/uint/boxed/inv_mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! [`BoxedUint`] modular inverse (i.e. reciprocal) operations.
22
3-
use crate::BoxedUint;
3+
use crate::{BoxedUint, Integer};
44
use subtle::{Choice, ConstantTimeEq, ConstantTimeLess, CtOption};
55

66
impl BoxedUint {

tests/boxed_residue_proptests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use crypto_bigint::{
66
modular::{BoxedResidue, BoxedResidueParams},
7-
BoxedUint, Limb, NonZero,
7+
BoxedUint, Integer, Limb, NonZero,
88
};
99
use num_bigint::{BigUint, ModInverse};
1010
use proptest::prelude::*;

tests/boxed_uint_proptests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#![cfg(feature = "alloc")]
44

55
use core::cmp::Ordering;
6-
use crypto_bigint::{BoxedUint, CheckedAdd, Limb, NonZero};
6+
use crypto_bigint::{BoxedUint, CheckedAdd, Integer, Limb, NonZero};
77
use num_bigint::{BigUint, ModInverse};
88
use num_traits::identities::One;
99
use proptest::prelude::*;

0 commit comments

Comments
 (0)