pub(crate) trait DeRecShareExt {
fn validate(&self, secret_id: u64, version: u32) -> Result<(), crate::Error>;
}
impl DeRecShareExt for derec_proto::DeRecShare {
fn validate(&self, secret_id: u64, version: u32) -> Result<(), crate::Error> {
use crate::primitives::recovery::RecoveryError;
if self.secret_id != secret_id {
#[cfg(feature = "logging")]
tracing::warn!("secret_id mismatch between request and stored share");
return Err(RecoveryError::SecretIdMismatch.into());
}
if self.version != version {
#[cfg(feature = "logging")]
tracing::warn!(
expected = version,
got = self.version,
"version mismatch between request and stored share"
);
return Err(RecoveryError::VersionMismatch {
expected: version,
got: self.version,
}
.into());
}
Ok(())
}
}
pub(crate) fn into_vss_subshares(
subshares: Vec<derec_proto::de_rec_share::Subshare>,
) -> Vec<derec_cryptography::vss::Subshare> {
subshares
.into_iter()
.map(|p| derec_cryptography::vss::Subshare { x: p.x, y: p.y })
.collect()
}
pub(crate) fn to_wire_subshares(
subshares: &[derec_cryptography::vss::Subshare],
) -> Vec<derec_proto::de_rec_share::Subshare> {
subshares
.iter()
.map(|p| derec_proto::de_rec_share::Subshare {
x: p.x.clone(),
y: p.y.clone(),
})
.collect()
}