2018-07-31 13:27:22 -07:00
|
|
|
use rand::Rand;
|
2018-10-29 07:36:56 -07:00
|
|
|
use rand_derive::Rand;
|
|
|
|
use serde_derive::{Deserialize, Serialize};
|
2018-07-31 13:27:22 -07:00
|
|
|
|
2018-08-14 06:06:51 -07:00
|
|
|
use subset;
|
2018-11-07 08:13:10 -08:00
|
|
|
use threshold_decrypt;
|
2018-07-31 13:27:22 -07:00
|
|
|
|
|
|
|
/// The content of a `HoneyBadger` message. It should be further annotated with an epoch.
|
2018-10-09 07:07:56 -07:00
|
|
|
#[derive(Clone, Debug, Deserialize, Rand, Serialize)]
|
2018-11-12 03:24:29 -08:00
|
|
|
// `threshold_sign::Message` triggers this Clippy lint, but `Box<T>` doesn't implement `Rand`.
|
|
|
|
#[cfg_attr(feature = "cargo-clippy", allow(large_enum_variant))]
|
2018-08-02 14:27:55 -07:00
|
|
|
pub enum MessageContent<N: Rand> {
|
2018-08-14 06:06:51 -07:00
|
|
|
/// A message belonging to the subset algorithm in the given epoch.
|
|
|
|
Subset(subset::Message<N>),
|
2018-07-31 13:27:22 -07:00
|
|
|
/// A decrypted share of the output of `proposer_id`.
|
|
|
|
DecryptionShare {
|
2018-08-02 14:27:55 -07:00
|
|
|
proposer_id: N,
|
2018-11-07 08:13:10 -08:00
|
|
|
share: threshold_decrypt::Message,
|
2018-07-31 13:27:22 -07:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2018-08-02 14:27:55 -07:00
|
|
|
impl<N: Rand> MessageContent<N> {
|
|
|
|
pub fn with_epoch(self, epoch: u64) -> Message<N> {
|
2018-10-09 07:07:56 -07:00
|
|
|
Message {
|
2018-07-31 13:27:22 -07:00
|
|
|
epoch,
|
|
|
|
content: self,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// A message sent to or received from another node's Honey Badger instance.
|
|
|
|
#[derive(Clone, Debug, Deserialize, Rand, Serialize)]
|
2018-10-09 07:07:56 -07:00
|
|
|
pub struct Message<N: Rand> {
|
|
|
|
pub(super) epoch: u64,
|
|
|
|
pub(super) content: MessageContent<N>,
|
2018-07-31 13:27:22 -07:00
|
|
|
}
|
|
|
|
|
2018-11-07 08:21:24 -08:00
|
|
|
impl<N: Rand> Message<N> {
|
|
|
|
/// Returns this message's Honey Badger epoch.
|
|
|
|
pub fn epoch(&self) -> u64 {
|
2018-10-09 07:07:56 -07:00
|
|
|
self.epoch
|
2018-07-31 13:27:22 -07:00
|
|
|
}
|
|
|
|
}
|