Skip to content

Commit

Permalink
Add some more error stuff.
Browse files Browse the repository at this point in the history
  • Loading branch information
sgwilym committed Nov 19, 2024
1 parent e80edde commit 3db8f38
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
14 changes: 14 additions & 0 deletions wgps/src/commitment_scheme/execute_prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ use super::{
send_prelude::send_prelude,
};

/// An error which only occurs during the initial phase of a WGPS session.
pub enum ExecutePreludeError<E> {
/// There was a problem receiving their prelude.
ReceiveError(ReceivePreludeError<E>),
/// There was a problem sending our prelude.
SendError(E),
}

Expand All @@ -31,6 +34,17 @@ impl<E> From<E> for ExecutePreludeError<E> {
}
}

impl<E: core::fmt::Display> core::fmt::Display for ExecutePreludeError<E> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
ExecutePreludeError::ReceiveError(receive_prelude_error) => {
write!(f, "{}", receive_prelude_error)
}
ExecutePreludeError::SendError(error) => write!(f, "{}", error),
}
}
}

/// Given a consumer and producer, send a max payload size and commitment, and wait for the other side's corresponding `ReceivedPrelude`. Then send a `CommitmentReveal` message, before finally returning the received prelude.
///
/// Attention: waiting for the other peer's prelude means that we delay sending our first messages, even though technically we would be allowed to do that. PRs welcome.
Expand Down
9 changes: 9 additions & 0 deletions wgps/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ mod commitment_scheme;
use commitment_scheme::execute_prelude::execute_prelude;
pub use commitment_scheme::*;

/// An error which can occur during a WGPS synchronisation session.
pub enum WgpsError<E> {
Prelude(ExecutePreludeError<E>),
}
Expand All @@ -28,6 +29,14 @@ impl<E> From<ExecutePreludeError<E>> for WgpsError<E> {
}
}

impl<E: core::fmt::Display> core::fmt::Display for WgpsError<E> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
WgpsError::Prelude(execute_prelude_error) => write!(f, "{}", execute_prelude_error),
}
}
}

pub struct SyncOptions<const CHALLENGE_LENGTH: usize> {
max_payload_power: u8,
challenge_nonce: [u8; CHALLENGE_LENGTH],
Expand Down

0 comments on commit 3db8f38

Please sign in to comment.