aboutsummaryrefslogtreecommitdiff
path: root/src/passwordmaker
diff options
context:
space:
mode:
Diffstat (limited to 'src/passwordmaker')
-rw-r--r--src/passwordmaker/base_conversion/iterative_conversion_impl/mod.rs10
-rw-r--r--src/passwordmaker/base_conversion/iterative_conversion_impl/precomputed_constants.rs14
-rw-r--r--src/passwordmaker/base_conversion/mod.rs1
-rw-r--r--src/passwordmaker/mod.rs18
4 files changed, 27 insertions, 16 deletions
diff --git a/src/passwordmaker/base_conversion/iterative_conversion_impl/mod.rs b/src/passwordmaker/base_conversion/iterative_conversion_impl/mod.rs
index 3d5351a..b805272 100644
--- a/src/passwordmaker/base_conversion/iterative_conversion_impl/mod.rs
+++ b/src/passwordmaker/base_conversion/iterative_conversion_impl/mod.rs
@@ -476,7 +476,7 @@ impl<const N : usize> ArbitraryBytes<N>{
}
fn find_first_nonzero_digit(&self) -> usize{
- self.0.iter().enumerate().skip_while(|(_,v)| **v == 0).next().map(|(x,_)| x).unwrap_or(N)
+ self.0.iter().enumerate().find(|(_,v)| **v != 0).map_or(N,|(x,_)| x)
}
fn get_digit_from_right(&self, i : usize) -> u32{
@@ -504,7 +504,7 @@ impl<const N : usize> ArbitraryBytes<N>{
fn slice_overflowing_sub_assign(lhs : &mut [u32], rhs: &[u32]) -> bool{
debug_assert_eq!(lhs.len(), rhs.len());
lhs.iter_mut().zip(rhs.iter()).rev().fold(false,|carry,(a,b)| {
- let r = b.overflowing_add(carry as u32);
+ let r = b.overflowing_add(u32::from(carry));
let s = a.overflowing_sub(r.0);
*a = s.0;
r.1 || s.1
@@ -514,7 +514,7 @@ fn slice_overflowing_sub_assign(lhs : &mut [u32], rhs: &[u32]) -> bool{
fn slice_overflowing_add_assign(lhs : &mut [u32], rhs : &[u32]) -> bool {
debug_assert_eq!(lhs.len(), rhs.len());
lhs.iter_mut().zip(rhs.iter()).rev().fold(false, |carry, (a, b)| {
- let r = b.overflowing_add(carry as u32);
+ let r = b.overflowing_add(u32::from(carry));
let s = a.overflowing_add(r.0);
*a = s.0;
r.1 || s.1
@@ -522,8 +522,8 @@ fn slice_overflowing_add_assign(lhs : &mut [u32], rhs : &[u32]) -> bool {
}
fn u64_from_u32s(m : u32, l : u32) -> u64{
- let m = m as u64;
- let l = l as u64;
+ let m = u64::from(m);
+ let l = u64::from(l);
(m << 32) | l
}
diff --git a/src/passwordmaker/base_conversion/iterative_conversion_impl/precomputed_constants.rs b/src/passwordmaker/base_conversion/iterative_conversion_impl/precomputed_constants.rs
index e845176..1127692 100644
--- a/src/passwordmaker/base_conversion/iterative_conversion_impl/precomputed_constants.rs
+++ b/src/passwordmaker/base_conversion/iterative_conversion_impl/precomputed_constants.rs
@@ -4,17 +4,17 @@ use super::super::iterative_conversion::PrecomputedMaxPowers;
impl PrecomputedMaxPowers<usize> for ArbitraryBytes<5>{
fn lookup(base : &usize) -> Option<(Self, usize)> {
- get_from_cache(base, &CONSTANT_MAX_POWER_CACHE_5)
+ get_from_cache(*base, &CONSTANT_MAX_POWER_CACHE_5)
}
}
impl PrecomputedMaxPowers<usize> for ArbitraryBytes<8>{
fn lookup(base : &usize) -> Option<(Self, usize)> {
- get_from_cache(base, &CONSTANT_MAX_POWER_CACHE_8)
+ get_from_cache(*base, &CONSTANT_MAX_POWER_CACHE_8)
}
}
-fn get_from_cache<const N : usize>(base : &usize, cache : &[([u32;N], usize)]) -> Option<(ArbitraryBytes<N>, usize)>{
+fn get_from_cache<const N : usize>(base : usize, cache : &[([u32;N], usize)]) -> Option<(ArbitraryBytes<N>, usize)>{
base.checked_sub(2).and_then(|idx|cache.get(idx))
.map(|c| (ArbitraryBytes(c.0), c.1))
}
@@ -24,9 +24,9 @@ const CONSTANT_MAX_POWER_CACHE_8 : [([u32;8],usize);128] = gen_const_max_power_c
//-----------------------------------------------------------------------------------------
-/// This version of find_highest_fitting_power is not optimized. But it can run in const contexts. Only use it there, use the normal one everywhere else.
+/// This version of `find_highest_fitting_power` is not optimized. But it can run in const contexts. Only use it there, use the normal one everywhere else.
const fn const_find_highest_fitting_power<const N : usize>(base : usize) -> ([u32;N],usize){
- let start = super::from_usize(&base);
+ let start = super::from_usize(base);
let mut x = (start, 1);
while let Some(next) = const_mul_usize(const_clone(&x.0),base) {
@@ -81,7 +81,7 @@ mod iterative_conversion_constants_tests{
for (base, mut power, exponent) in entries {
//exponent is the largest fitting exponent. Soo, if we divide exponent times, we should end up with 1.
for _i in 0..exponent {
- let remainder = power.div_assign_with_remainder_usize(&base);
+ let remainder = power.div_assign_with_remainder_usize(base);
assert_eq!(remainder, 0);
}
assert_eq!(power, (&1usize).into());
@@ -95,7 +95,7 @@ mod iterative_conversion_constants_tests{
for (base, mut power, exponent) in entries {
//exponent is the largest fitting exponent. Soo, if we divide exponent times, we should end up with 1.
for _i in 0..exponent {
- let remainder = power.div_assign_with_remainder_usize(&base);
+ let remainder = power.div_assign_with_remainder_usize(base);
assert_eq!(remainder, 0);
}
assert_eq!(power, (&1usize).into());
diff --git a/src/passwordmaker/base_conversion/mod.rs b/src/passwordmaker/base_conversion/mod.rs
index 6640880..6415904 100644
--- a/src/passwordmaker/base_conversion/mod.rs
+++ b/src/passwordmaker/base_conversion/mod.rs
@@ -14,6 +14,7 @@ pub(super) trait BaseConversion {
fn convert_to_base(self, base : usize) -> Self::Output;
}
+#[allow(clippy::trait_duplication_in_bounds)] //False positive in clippy. usize != u32.
impl<T, const N : usize, const M : usize> BaseConversion for T
where T : ToArbitraryBytes<Output = ArbitraryBytes<N>>,
for<'a> T::Output: From<&'a usize> + From<&'a u32> + PaddedShiftLeft<Output = ArbitraryBytes<M>> + PrecomputedMaxPowers<usize>,
diff --git a/src/passwordmaker/mod.rs b/src/passwordmaker/mod.rs
index 61a0a95..c9ec1e3 100644
--- a/src/passwordmaker/mod.rs
+++ b/src/passwordmaker/mod.rs
@@ -201,15 +201,25 @@ fn combine_prefix_password_suffix<'a, T : Iterator<Item=Grapheme<'a>>>(password:
result
}
+#[allow(clippy::trivially_copy_pass_by_ref)] //signature is actually determined by Iterator::skip_while(). There's simply no choice.
fn is_zero(i : &usize) -> bool {
*i == 0
}
+type BaseConversion16 = IterativeBaseConversion<SixteenBytes,usize>;
+type BaseConversion16Modern = SkipWhile<BaseConversion16,fn(&usize)->bool>;
+
+type BaseConversion20 = IterativeBaseConversion<ArbitraryBytes<5>,usize>;
+type BaseConversion20Modern = SkipWhile<BaseConversion20,fn(&usize)->bool>;
+
+type BaseConversion32 = IterativeBaseConversion<ArbitraryBytes<8>,usize>;
+type BaseConversion32Modern = SkipWhile<BaseConversion32,fn(&usize)->bool>;
+
enum GetGraphemesIteratorInner {
- Modern16(SkipWhile<IterativeBaseConversion<SixteenBytes,usize>,fn(&usize)->bool>),
- Modern20(SkipWhile<IterativeBaseConversion<ArbitraryBytes<5>,usize>,fn(&usize)->bool>),
- Modern32(SkipWhile<IterativeBaseConversion<ArbitraryBytes<8>,usize>,fn(&usize)->bool>),
- V06(IterativeBaseConversion<SixteenBytes,usize>)
+ Modern16(BaseConversion16Modern),
+ Modern20(BaseConversion20Modern),
+ Modern32(BaseConversion32Modern),
+ V06(BaseConversion16)
}
struct GetGraphemesIterator<'a> {
graphemes : &'a Vec<Grapheme<'a>>,