Skip to content

implement PartialOrd<Uint> for BoxedUint #803

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/uint/boxed/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
pub(super) use core::cmp::{Ordering, max};

use super::BoxedUint;
use crate::{ConstChoice, Limb};
use crate::{ConstChoice, Limb, Uint};
use subtle::{
Choice, ConditionallySelectable, ConstantTimeEq, ConstantTimeGreater, ConstantTimeLess,
};
Expand Down Expand Up @@ -73,6 +73,12 @@ impl PartialEq for BoxedUint {
}
}

impl<const LIMBS: usize> PartialEq<Uint<LIMBS>> for BoxedUint {
fn eq(&self, other: &Uint<LIMBS>) -> bool {
self.eq(&Self::from(other))
}
}

impl Ord for BoxedUint {
fn cmp(&self, other: &Self) -> Ordering {
let mut ret = Ordering::Equal;
Expand All @@ -94,6 +100,12 @@ impl PartialOrd for BoxedUint {
}
}

impl<const LIMBS: usize> PartialOrd<Uint<LIMBS>> for BoxedUint {
fn partial_cmp(&self, other: &Uint<LIMBS>) -> Option<Ordering> {
self.partial_cmp(&Self::from(other))
}
}

#[cfg(test)]
mod tests {
use super::BoxedUint;
Expand Down