From 2d225de48c65ab0f0f38ff24a43df0c8aa33832f Mon Sep 17 00:00:00 2001 From: samkim-crypto Date: Mon, 11 Oct 2021 15:28:21 -0400 Subject: [PATCH] pod for AESCiphertext --- zk-token-sdk/src/zk_token_elgamal/convert.rs | 13 +++++++++++++ zk-token-sdk/src/zk_token_elgamal/pod.rs | 11 +++++++++++ 2 files changed, 24 insertions(+) diff --git a/zk-token-sdk/src/zk_token_elgamal/convert.rs b/zk-token-sdk/src/zk_token_elgamal/convert.rs index 777b151716..e773c72af5 100644 --- a/zk-token-sdk/src/zk_token_elgamal/convert.rs +++ b/zk-token-sdk/src/zk_token_elgamal/convert.rs @@ -15,6 +15,7 @@ mod target_arch { use { super::pod, crate::{ + encryption::aes::AESCiphertext, encryption::elgamal::{ElGamalCiphertext, ElGamalPubkey}, encryption::pedersen::{PedersenCommitment, PedersenDecryptHandle}, errors::ProofError, @@ -123,6 +124,18 @@ mod target_arch { } } + impl From for pod::AESCiphertext { + fn from(ct: AESCiphertext) -> Self { + Self(ct.0) + } + } + + impl From for AESCiphertext { + fn from(ct: pod::AESCiphertext) -> Self { + Self(ct.0) + } + } + impl TryFrom for pod::RangeProof64 { type Error = ProofError; diff --git a/zk-token-sdk/src/zk_token_elgamal/pod.rs b/zk-token-sdk/src/zk_token_elgamal/pod.rs index 31ede5684f..2ae931c611 100644 --- a/zk-token-sdk/src/zk_token_elgamal/pod.rs +++ b/zk-token-sdk/src/zk_token_elgamal/pod.rs @@ -69,3 +69,14 @@ pub struct RangeProof128(pub [u8; 736]); // Add the marker traits manually because `bytemuck` only adds them for some `u8` arrays unsafe impl Zeroable for RangeProof128 {} unsafe impl Pod for RangeProof128 {} + +/// Serialization for AESCiphertext +#[derive(Clone, Copy, Pod, Zeroable, PartialEq)] +#[repr(transparent)] +pub struct AESCiphertext(pub [u8; 16]); + +impl fmt::Debug for AESCiphertext { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{:?}", self.0) + } +}