Skip to content

Commit 6a16b72

Browse files
committed
dsa: compare key sizes aligned to limb
This allows to compare key sizes after a back and forth through serialization which could lose the exact key size.
1 parent 99b2bcb commit 6a16b72

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

dsa/src/size.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
use core::cmp::Ordering;
12
use crypto_bigint::Limb;
23

34
/// DSA key size
4-
#[derive(Clone, Debug, Copy, PartialEq, PartialOrd)]
5+
#[derive(Clone, Debug, Copy)]
56
pub struct KeySize {
67
/// Bit size of p
78
pub(crate) l: u32,
@@ -48,3 +49,18 @@ impl KeySize {
4849
l == self.l_aligned() && n == self.n_aligned()
4950
}
5051
}
52+
53+
impl PartialEq for KeySize {
54+
fn eq(&self, other: &Self) -> bool {
55+
self.l_aligned() == other.l_aligned() && self.n_aligned() == other.n_aligned()
56+
}
57+
}
58+
59+
impl PartialOrd for KeySize {
60+
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
61+
let l = self.l_aligned().partial_cmp(&other.l_aligned())?;
62+
let n = self.n_aligned().partial_cmp(&other.n_aligned())?;
63+
64+
Some(l.then(n))
65+
}
66+
}

0 commit comments

Comments
 (0)