ProtocolMsg

Trait ProtocolMsg 

Source
pub trait ProtocolMsg: Sized {
    // Required method
    fn round(&self) -> u16;
}
Expand description

Message of MPC protocol

MPC protocols typically consist of several rounds, each round has differently typed message. ProtocolMsg and RoundMsg traits are used to examine received message: ProtocolMsg::round determines which round message belongs to, and then RoundMsg trait can be used to retrieve actual round-specific message.

You should derive these traits using proc macro (requires derive feature):

use round_based::ProtocolMsg;

#[derive(ProtocolMsg)]
pub enum Message {
    Round1(Msg1),
    Round2(Msg2),
    // ...
}

pub struct Msg1 { /* ... */ }
pub struct Msg2 { /* ... */ }

This desugars into:

use round_based::{ProtocolMsg, RoundMsg};

pub enum Message {
    Round1(Msg1),
    Round2(Msg2),
    // ...
}

pub struct Msg1 { /* ... */ }
pub struct Msg2 { /* ... */ }

impl ProtocolMsg for Message {
    fn round(&self) -> u16 {
        match self {
            Message::Round1(_) => 1,
            Message::Round2(_) => 2,
            // ...
        }
    }
}
impl RoundMsg<Msg1> for Message {
    const ROUND: u16 = 1;
    fn to_protocol_msg(round_msg: Msg1) -> Self {
        Message::Round1(round_msg)
    }
    fn from_protocol_msg(protocol_msg: Self) -> Result<Msg1, Self> {
        match protocol_msg {
            Message::Round1(msg) => Ok(msg),
            msg => Err(msg),
        }
    }
}
impl RoundMsg<Msg2> for Message {
    const ROUND: u16 = 2;
    fn to_protocol_msg(round_msg: Msg2) -> Self {
        Message::Round2(round_msg)
    }
    fn from_protocol_msg(protocol_msg: Self) -> Result<Msg2, Self> {
        match protocol_msg {
            Message::Round2(msg) => Ok(msg),
            msg => Err(msg),
        }
    }
}

Required Methods§

Source

fn round(&self) -> u16

Number of the round that this message originates from

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<D: Digest, M: ProtocolMsg> ProtocolMsg for Msg<D, M>

Available on crate feature echo-broadcast only.