Skip to content

Commit

Permalink
fix SignatureShare and Identifier serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
conradoplg committed Jun 19, 2024
1 parent efa9294 commit d46f68a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
27 changes: 26 additions & 1 deletion frost-core/src/identifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ use crate::{
#[derive(Copy, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(bound = "C: Ciphersuite"))]
#[cfg_attr(feature = "serde", serde(transparent))]
// We use these to add a validation step since zero scalars should cause an
// error when deserializing.
#[cfg_attr(feature = "serde", serde(try_from = "SerializableScalar<C>"))]
#[cfg_attr(feature = "serde", serde(into = "SerializableScalar<C>"))]
pub struct Identifier<C: Ciphersuite>(SerializableScalar<C>);

impl<C> Identifier<C>
Expand Down Expand Up @@ -68,6 +71,28 @@ where
}
}

#[cfg(feature = "serde")]
impl<C> TryFrom<SerializableScalar<C>> for Identifier<C>
where
C: Ciphersuite,
{
type Error = Error<C>;

fn try_from(s: SerializableScalar<C>) -> Result<Self, Self::Error> {
Self::new(s.0)
}
}

#[cfg(feature = "serde")]
impl<C> From<Identifier<C>> for SerializableScalar<C>
where
C: Ciphersuite,
{
fn from(i: Identifier<C>) -> Self {
i.0
}
}

impl<C> Eq for Identifier<C> where C: Ciphersuite {}

impl<C> Debug for Identifier<C>
Expand Down
6 changes: 5 additions & 1 deletion frost-core/src/round2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ use crate::{
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(bound = "C: Ciphersuite"))]
#[cfg_attr(feature = "serde", serde(deny_unknown_fields))]
#[cfg_attr(feature = "serde", serde(transparent))]
pub struct SignatureShare<C: Ciphersuite> {
/// Serialization header
#[getter(skip)]
pub(crate) header: Header<C>,
/// This participant's signature over the message.
pub(crate) share: SerializableScalar<C>,
}
Expand All @@ -27,6 +29,7 @@ where
scalar: <<<C as Ciphersuite>::Group as Group>::Field as Field>::Scalar,
) -> Self {
Self {
header: Header::default(),
share: SerializableScalar(scalar),
}
}
Expand All @@ -40,6 +43,7 @@ where
/// Deserialize [`SignatureShare`] from bytes
pub fn deserialize(bytes: &[u8]) -> Result<Self, Error<C>> {
Ok(Self {
header: Header::default(),
share: SerializableScalar::deserialize(bytes)?,
})
}
Expand Down

0 comments on commit d46f68a

Please sign in to comment.