Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
andyleiserson committed Jan 11, 2024
1 parent a8b96fa commit 7b8ab48
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions ipa-core/src/protocol/prss/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl UsedSet {
let raw_index = u128::from(index);
if raw_index > usize::MAX as u128 {
// This is unreachable with the current PRSS index encoding.
tracing::warn!("Index '{index}' is not supported by PRSS verification.");
tracing::warn!("PRSS index is too large: {index} > usize::MAX");
} else {
assert!(
self.used.lock().unwrap().insert(raw_index as usize),
Expand Down Expand Up @@ -91,9 +91,7 @@ impl Display for PrssIndex128 {
impl From<u64> for PrssIndex128 {
fn from(value: u64) -> Self {
Self {
index: u32::try_from((value >> 32) & u64::from(u32::MAX))
.unwrap()
.into(),
index: u32::try_from(value >> 32).unwrap().into(),
offset: u32::try_from(value & u64::from(u32::MAX)).unwrap(),
}
}
Expand Down Expand Up @@ -122,7 +120,10 @@ impl From<u32> for PrssIndex {
// It would be nice for this to be TryFrom, but there's a lot of places where we use u128s as PRSS indexes.
impl From<u128> for PrssIndex {
fn from(value: u128) -> Self {
Self(value.try_into().expect("PRSS index out of range"))
let Ok(v) = u32::try_from(value) else {
panic!("PRSS indices need to be smaller: {value} > u32::MAX");
};
Self(v)
}
}

Expand Down

0 comments on commit 7b8ab48

Please sign in to comment.