Skip to content

Commit

Permalink
Fix high level serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
JobDoesburg committed Jan 27, 2025
1 parent 85c6bd3 commit 90d2d58
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "libpep"
edition = "2021"
version = "0.6.1"
version = "0.6.2"
authors = ["Bernard van Gastel <bvgastel@bitpowder.com>", "Job Doesburg <job@jobdoesburg.nl>"]
homepage = "https://github.com/NOLAI/libpep"
repository = "https://github.com/NOLAI/libpep"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nolai/libpep-wasm",
"version": "0.6.1",
"version": "0.6.2",
"description": "The WebAssembly version of the libpep library",
"repository": {
"type": "git",
Expand Down
45 changes: 42 additions & 3 deletions src/lib/high_level/data_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::internal::arithmetic::GroupElement;
use crate::low_level::elgamal::{ElGamal, ELGAMAL_LENGTH};
use derive_more::{Deref, From};
use rand_core::{CryptoRng, RngCore};
use serde::{Deserialize, Serialize};
use serde::{Deserialize, Deserializer, Serialize, Serializer};

/// A pseudonym (in the background, this is a [`GroupElement`]) that can be used to identify a user
/// within a specific context, which can be encrypted, rekeyed and reshuffled.
Expand All @@ -20,15 +20,54 @@ pub struct DataPoint {
pub(crate) value: GroupElement,
}
/// An encrypted pseudonym, which is an [`ElGamal`] encryption of a [`Pseudonym`].
#[derive(Copy, Clone, Eq, PartialEq, Debug, Deref, From, Serialize, Deserialize)]
#[derive(Copy, Clone, Eq, PartialEq, Debug, Deref, From)]
pub struct EncryptedPseudonym {
pub value: ElGamal,
}
/// An encrypted data point, which is an [`ElGamal`] encryption of a [`DataPoint`].
#[derive(Copy, Clone, Eq, PartialEq, Debug, Deref, From, Serialize, Deserialize)]
#[derive(Copy, Clone, Eq, PartialEq, Debug, Deref, From)]
pub struct EncryptedDataPoint {
pub value: ElGamal,
}

impl Serialize for EncryptedDataPoint {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
self.value.serialize(serializer)
}
}

impl<'de> Deserialize<'de> for EncryptedDataPoint {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
let value = ElGamal::deserialize(deserializer)?;
Ok(Self { value })
}
}

impl Serialize for EncryptedPseudonym {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
self.value.serialize(serializer)
}
}

impl<'de> Deserialize<'de> for EncryptedPseudonym {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
let value = ElGamal::deserialize(deserializer)?;
Ok(Self { value })
}
}

/// A trait for encrypted data types, that can be encrypted and decrypted from and into [`Encryptable`] types.
pub trait Encrypted {
type UnencryptedType: Encryptable;
Expand Down

0 comments on commit 90d2d58

Please sign in to comment.