Skip to content

Commit

Permalink
Merge pull request #965 from andyleiserson/reveal
Browse files Browse the repository at this point in the history
RPITIT and address a TODO for reveal
  • Loading branch information
andyleiserson authored Mar 12, 2024
2 parents 276f06d + 096179e commit cc5d71c
Show file tree
Hide file tree
Showing 6 changed files with 207 additions and 172 deletions.
44 changes: 44 additions & 0 deletions ipa-core/src/helpers/futures.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use std::{
future::Future,
pin::Pin,
task::{Context, Poll},
};

use pin_project::pin_project;

#[pin_project(project = MaybeFutureProj)]
pub enum MaybeFuture<Fut: Future> {
Future(#[pin] Fut),
Value(Option<Fut::Output>),
}

impl<Fut: Future> Future for MaybeFuture<Fut> {
type Output = Fut::Output;

fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
match self.project() {
MaybeFutureProj::Future(fut) => fut.poll(cx),
MaybeFutureProj::Value(val) => Poll::Ready(val.take().unwrap()),
}
}
}

impl<Fut: Future> MaybeFuture<Fut> {
pub fn future(fut: Fut) -> Self {
MaybeFuture::Future(fut)
}

pub fn value(val: Fut::Output) -> Self {
MaybeFuture::Value(Some(val))
}
}

impl<Fut: Future<Output = Result<(), E>>, E> MaybeFuture<Fut> {
pub fn future_or_ok<F: FnOnce() -> Fut>(condition: bool, f: F) -> Self {
if condition {
MaybeFuture::Future(f())
} else {
MaybeFuture::Value(Some(Ok(())))
}
}
}
2 changes: 2 additions & 0 deletions ipa-core/src/helpers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use generic_array::GenericArray;

mod buffers;
mod error;
mod futures;
mod gateway;
pub(crate) mod prss_protocol;
mod transport;
Expand All @@ -18,6 +19,7 @@ use std::ops::{Index, IndexMut};
#[cfg(test)]
pub use buffers::OrderingSender;
pub use error::{Error, Result};
pub use futures::MaybeFuture;

#[cfg(feature = "stall-detection")]
mod gateway_exports {
Expand Down
2 changes: 1 addition & 1 deletion ipa-core/src/protocol/basics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub use check_zero::check_zero;
pub use if_else::{if_else, select};
pub use mul::{BooleanArrayMul, MultiplyZeroPositions, SecureMul, ZeroPositions};
pub use reshare::Reshare;
pub use reveal::Reveal;
pub use reveal::{reveal, Reveal};
pub use share_known_value::ShareKnownValue;
pub use sum_of_product::SumOfProducts;

Expand Down
Loading

0 comments on commit cc5d71c

Please sign in to comment.