Skip to content

Commit 90d2d58

Browse files
committed
Fix high level serialization
1 parent 85c6bd3 commit 90d2d58

File tree

3 files changed

+44
-5
lines changed

3 files changed

+44
-5
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "libpep"
33
edition = "2021"
4-
version = "0.6.1"
4+
version = "0.6.2"
55
authors = ["Bernard van Gastel <bvgastel@bitpowder.com>", "Job Doesburg <job@jobdoesburg.nl>"]
66
homepage = "https://github.com/NOLAI/libpep"
77
repository = "https://github.com/NOLAI/libpep"

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nolai/libpep-wasm",
3-
"version": "0.6.1",
3+
"version": "0.6.2",
44
"description": "The WebAssembly version of the libpep library",
55
"repository": {
66
"type": "git",

src/lib/high_level/data_types.rs

+42-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::internal::arithmetic::GroupElement;
55
use crate::low_level::elgamal::{ElGamal, ELGAMAL_LENGTH};
66
use derive_more::{Deref, From};
77
use rand_core::{CryptoRng, RngCore};
8-
use serde::{Deserialize, Serialize};
8+
use serde::{Deserialize, Deserializer, Serialize, Serializer};
99

1010
/// A pseudonym (in the background, this is a [`GroupElement`]) that can be used to identify a user
1111
/// within a specific context, which can be encrypted, rekeyed and reshuffled.
@@ -20,15 +20,54 @@ pub struct DataPoint {
2020
pub(crate) value: GroupElement,
2121
}
2222
/// An encrypted pseudonym, which is an [`ElGamal`] encryption of a [`Pseudonym`].
23-
#[derive(Copy, Clone, Eq, PartialEq, Debug, Deref, From, Serialize, Deserialize)]
23+
#[derive(Copy, Clone, Eq, PartialEq, Debug, Deref, From)]
2424
pub struct EncryptedPseudonym {
2525
pub value: ElGamal,
2626
}
2727
/// An encrypted data point, which is an [`ElGamal`] encryption of a [`DataPoint`].
28-
#[derive(Copy, Clone, Eq, PartialEq, Debug, Deref, From, Serialize, Deserialize)]
28+
#[derive(Copy, Clone, Eq, PartialEq, Debug, Deref, From)]
2929
pub struct EncryptedDataPoint {
3030
pub value: ElGamal,
3131
}
32+
33+
impl Serialize for EncryptedDataPoint {
34+
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
35+
where
36+
S: Serializer,
37+
{
38+
self.value.serialize(serializer)
39+
}
40+
}
41+
42+
impl<'de> Deserialize<'de> for EncryptedDataPoint {
43+
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
44+
where
45+
D: Deserializer<'de>,
46+
{
47+
let value = ElGamal::deserialize(deserializer)?;
48+
Ok(Self { value })
49+
}
50+
}
51+
52+
impl Serialize for EncryptedPseudonym {
53+
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
54+
where
55+
S: Serializer,
56+
{
57+
self.value.serialize(serializer)
58+
}
59+
}
60+
61+
impl<'de> Deserialize<'de> for EncryptedPseudonym {
62+
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
63+
where
64+
D: Deserializer<'de>,
65+
{
66+
let value = ElGamal::deserialize(deserializer)?;
67+
Ok(Self { value })
68+
}
69+
}
70+
3271
/// A trait for encrypted data types, that can be encrypted and decrypted from and into [`Encryptable`] types.
3372
pub trait Encrypted {
3473
type UnencryptedType: Encryptable;

0 commit comments

Comments
 (0)