#![allow(non_snake_case)]
use num_bigint::BigInt;
use num_traits::identities::Zero;
use std::collections::HashMap;
use std::vec::Vec;
use crate::group::Group;
#[derive(Debug, Clone)]
pub struct GenericShareBox<G: Group> {
pub publickey: G::Element,
pub share: G::Element,
pub challenge: G::Scalar,
pub response: G::Scalar,
}
impl<G: Group> Default for GenericShareBox<G>
where
G::Element: Default,
G::Scalar: Default,
{
fn default() -> Self {
GenericShareBox {
publickey: Default::default(),
share: Default::default(),
challenge: Default::default(),
response: Default::default(),
}
}
}
impl<G: Group> GenericShareBox<G> {
pub fn new() -> Self
where
G::Element: Default,
G::Scalar: Default,
{
Self::default()
}
pub fn init(
&mut self,
publickey: G::Element,
share: G::Element,
challenge: G::Scalar,
response: G::Scalar,
) {
self.publickey = publickey;
self.share = share;
self.challenge = challenge;
self.response = response;
}
}
#[derive(Debug, Clone)]
pub struct GenericDistributionSharesBox<G: Group> {
pub commitments: Vec<G::Element>,
pub positions: HashMap<Vec<u8>, i64>,
pub shares: HashMap<Vec<u8>, G::Element>,
pub publickeys: Vec<G::Element>,
pub challenge: G::Scalar,
pub responses: HashMap<Vec<u8>, G::Scalar>,
pub U: BigInt, }
impl<G: Group> Default for GenericDistributionSharesBox<G>
where
G::Scalar: Default,
{
fn default() -> Self {
GenericDistributionSharesBox {
commitments: Vec::new(),
positions: HashMap::new(),
shares: HashMap::new(),
publickeys: Vec::new(),
challenge: Default::default(),
responses: HashMap::new(),
U: BigInt::zero(),
}
}
}
impl<G: Group> GenericDistributionSharesBox<G> {
pub fn new() -> Self
where
G::Scalar: Default,
{
Self::default()
}
#[allow(clippy::too_many_arguments)]
pub fn init(
&mut self,
commitments: &[G::Element],
positions: HashMap<Vec<u8>, i64>,
shares: HashMap<Vec<u8>, G::Element>,
publickeys: &[G::Element],
challenge: &G::Scalar,
responses: HashMap<Vec<u8>, G::Scalar>,
U: &BigInt,
) {
self.commitments = commitments.to_vec();
self.positions = positions;
self.shares = shares;
self.publickeys = publickeys.to_vec();
self.challenge = challenge.clone();
self.responses = responses;
self.U = U.clone();
}
}
pub type ShareBox<G> = GenericShareBox<G>;
pub type DistributionSharesBox<G> = GenericDistributionSharesBox<G>;