Skip to content

Commit

Permalink
Tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
ryardley committed Aug 26, 2024
1 parent 14552fd commit f21e0e9
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions packages/ciphernode/core/src/fhe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl<'de> serde::Deserialize<'de> for WrappedPublicKeyShare {
where
D: serde::Deserializer<'de>,
{
// Intermediate struct for deserialization
// Intermediate struct of bytes for deserialization
#[derive(serde::Deserialize)]
struct PublicKeyShareBytes {
par_bytes: Vec<u8>,
Expand All @@ -99,11 +99,12 @@ impl<'de> serde::Deserialize<'de> for WrappedPublicKeyShare {
CommonRandomPoly::deserialize(&crp_bytes, &params).map_err(serde::de::Error::custom)?;
let inner = PublicKeyShare::deserialize(&bytes, &params, crp.clone())
.map_err(serde::de::Error::custom)?;
// TODO: how do we create an invariant that the deserialized params match the global params?
std::result::Result::Ok(WrappedPublicKeyShare::from_fhe_rs(inner, params, crp))
}
}

/// Serialize to intermediate struct
/// Serialize to serde bytes representation
impl serde::Serialize for WrappedPublicKeyShare {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
Expand All @@ -113,6 +114,7 @@ impl serde::Serialize for WrappedPublicKeyShare {
let bytes = self.inner.to_bytes();
let par_bytes = self.params.to_bytes();
let crp_bytes = self.params.to_bytes();
// Intermediate struct of bytes
let mut state = serializer.serialize_struct("PublicKeyShare", 2)?;
state.serialize_field("par_bytes", &par_bytes)?;
state.serialize_field("crp_bytes", &crp_bytes)?;
Expand Down Expand Up @@ -148,6 +150,7 @@ impl<'de> serde::Deserialize<'de> for WrappedPublicKey {
where
D: serde::Deserializer<'de>,
{
// Intermediate struct of bytes for deserialization
#[derive(serde::Deserialize)]
struct PublicKeyBytes {
par: Vec<u8>,
Expand All @@ -161,16 +164,16 @@ impl<'de> serde::Deserialize<'de> for WrappedPublicKey {
}
}

/// Serialize to bytes representation
/// Serialize to serde bytes representation
impl serde::Serialize for WrappedPublicKey {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
use serde::ser::SerializeStruct;
// let par = self.0.
let bytes = self.inner.to_bytes();
let par_bytes = self.params.to_bytes();
// Intermediate struct of bytes
let mut state = serializer.serialize_struct("PublicKey", 2)?;
state.serialize_field("par_bytes", &par_bytes)?;
state.serialize_field("bytes", &bytes)?;
Expand Down

0 comments on commit f21e0e9

Please sign in to comment.