Skip to content

Commit

Permalink
Add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
fjarri committed Oct 13, 2024
1 parent 26570f4 commit a255c37
Show file tree
Hide file tree
Showing 18 changed files with 324 additions and 50 deletions.
8 changes: 4 additions & 4 deletions example/src/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl Protocol for SimpleProtocol {
if round_id == RoundId::new(1) {
return message.verify_is_invalid::<Self, Round1Message>();
}
Err(MessageValidationError::Other("Invalid round number".into()))?
Err(MessageValidationError::InvalidEvidence("Invalid round number".into()))?
}
}

Expand Down Expand Up @@ -223,7 +223,7 @@ impl<Id: 'static + Debug + Clone + Ord + Send + Sync> Round<Id> for Round1<Id> {
_rng: &mut impl CryptoRngCore,
payloads: BTreeMap<Id, Payload>,
_artifacts: BTreeMap<Id, Artifact>,
) -> Result<FinalizeOutcome<Id, Self::Protocol>, FinalizeError<Id, Self::Protocol>> {
) -> Result<FinalizeOutcome<Id, Self::Protocol>, FinalizeError<Self::Protocol>> {
debug!(
"{:?}: finalizing with messages from {:?}",
self.context.id,
Expand Down Expand Up @@ -327,7 +327,7 @@ impl<Id: 'static + Debug + Clone + Ord + Send + Sync> Round<Id> for Round2<Id> {
_rng: &mut impl CryptoRngCore,
payloads: BTreeMap<Id, Payload>,
_artifacts: BTreeMap<Id, Artifact>,
) -> Result<FinalizeOutcome<Id, Self::Protocol>, FinalizeError<Id, Self::Protocol>> {
) -> Result<FinalizeOutcome<Id, Self::Protocol>, FinalizeError<Self::Protocol>> {
debug!(
"{:?}: finalizing with messages from {:?}",
self.context.id,
Expand Down Expand Up @@ -359,7 +359,7 @@ mod tests {
use alloc::collections::BTreeSet;

use manul::{
session::{Keypair, SessionOutcome},
session::{signature::Keypair, SessionOutcome},
testing::{run_sync, Signature, Signer, Verifier},
};
use rand_core::OsRng;
Expand Down
4 changes: 2 additions & 2 deletions example/src/simple_malicious.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use manul::{
protocol::{
Artifact, DirectMessage, FinalizeError, FinalizeOutcome, FirstRound, LocalError, Payload, Round, SessionId,
},
session::Keypair,
session::signature::Keypair,
testing::{round_override, run_sync, RoundOverride, RoundWrapper, Signature, Signer, Verifier},
};
use rand_core::{CryptoRngCore, OsRng};
Expand Down Expand Up @@ -85,7 +85,7 @@ impl<Id: 'static + Debug + Clone + Ord + Send + Sync> RoundOverride<Id> for Mali
artifacts: BTreeMap<Id, Artifact>,
) -> Result<
FinalizeOutcome<Id, <<Self as RoundWrapper<Id>>::InnerRound as Round<Id>>::Protocol>,
FinalizeError<Id, <<Self as RoundWrapper<Id>>::InnerRound as Round<Id>>::Protocol>,
FinalizeError<<<Self as RoundWrapper<Id>>::InnerRound as Round<Id>>::Protocol>,
> {
let behavior = self.behavior;
let outcome = self.inner_round().finalize(rng, payloads, artifacts)?;
Expand Down
4 changes: 3 additions & 1 deletion example/tests/async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use alloc::collections::{BTreeMap, BTreeSet};

use manul::{
protocol::{Protocol, Round},
session::{CanFinalize, Keypair, LocalError, MessageBundle, RoundOutcome, Session, SessionId, SessionReport},
session::{
signature::Keypair, CanFinalize, LocalError, MessageBundle, RoundOutcome, Session, SessionId, SessionReport,
},
testing::{Signature, Signer, Verifier},
};
use manul_example::simple::{Inputs, Round1};
Expand Down
4 changes: 3 additions & 1 deletion manul/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#![no_std]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
#![doc = include_str!("../../README.md")]
#![warn(
clippy::mod_module_files,
clippy::unwrap_used,
clippy::indexing_slicing,
//missing_docs,
missing_docs,
missing_copy_implementations,
rust_2018_idioms,
trivial_casts,
Expand Down
15 changes: 14 additions & 1 deletion manul/src/protocol.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
/*!
API for protocol implementors.
A protocol is a directed acyclic graph with the nodes being objects of types implementing [`Round`]
(to be specific, "acyclic" means that the values returned by [`Round::id`]
should not repeat during the protocol execution; the types might).
The starting point is a type also implementing [`FirstRound`].
All the rounds should have their associated type [`Round::Protocol`] set to the same [`Protocol`] instance
to be executed by a [`Session`](`crate::session::Session`).
For more details, see the documentation of the mentioned traits.
*/

mod error;
mod object_safe;
mod round;
Expand All @@ -13,4 +26,4 @@ pub use round::{
pub(crate) use object_safe::{ObjectSafeRound, ObjectSafeRoundWrapper};
pub(crate) use round::ReceiveErrorType;

pub use digest::Digest;
pub use digest;
2 changes: 2 additions & 0 deletions manul/src/protocol/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use core::fmt::Debug;
pub struct LocalError(String);

impl LocalError {
/// Creates a new error from anything castable to string.
pub fn new(message: impl Into<String>) -> Self {
Self(message.into())
}
Expand All @@ -18,6 +19,7 @@ impl LocalError {
pub struct RemoteError(String);

impl RemoteError {
/// Creates a new error from anything castable to string.
pub fn new(message: impl Into<String>) -> Self {
Self(message.into())
}
Expand Down
4 changes: 2 additions & 2 deletions manul/src/protocol/object_safe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub(crate) trait ObjectSafeRound<Id>: 'static + Send + Sync {
rng: &mut dyn CryptoRngCore,
payloads: BTreeMap<Id, Payload>,
artifacts: BTreeMap<Id, Artifact>,
) -> Result<FinalizeOutcome<Id, Self::Protocol>, FinalizeError<Id, Self::Protocol>>;
) -> Result<FinalizeOutcome<Id, Self::Protocol>, FinalizeError<Self::Protocol>>;

fn expecting_messages_from(&self) -> &BTreeSet<Id>;

Expand Down Expand Up @@ -145,7 +145,7 @@ where
rng: &mut dyn CryptoRngCore,
payloads: BTreeMap<Id, Payload>,
artifacts: BTreeMap<Id, Artifact>,
) -> Result<FinalizeOutcome<Id, Self::Protocol>, FinalizeError<Id, Self::Protocol>> {
) -> Result<FinalizeOutcome<Id, Self::Protocol>, FinalizeError<Self::Protocol>> {
let mut boxed_rng = BoxedRng(rng);
self.round.finalize(&mut boxed_rng, payloads, artifacts)
}
Expand Down
Loading

0 comments on commit a255c37

Please sign in to comment.