From defdf8da7296a3e9dccc1885557f75c0a9e9aedf Mon Sep 17 00:00:00 2001 From: Sam Kim Date: Sun, 17 Oct 2021 11:45:41 -0400 Subject: [PATCH] change AESCiphertext to AesCiphertext --- zk-token-sdk/src/encryption/aes.rs | 9 +++++++++ zk-token-sdk/src/zk_token_elgamal/pod.rs | 13 +++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/zk-token-sdk/src/encryption/aes.rs b/zk-token-sdk/src/encryption/aes.rs index 28c245a273..fd5e1801ad 100644 --- a/zk-token-sdk/src/encryption/aes.rs +++ b/zk-token-sdk/src/encryption/aes.rs @@ -106,6 +106,15 @@ impl AesCiphertext { } } +impl Default for AesCiphertext { + fn default() -> Self { + AesCiphertext { + nonce: [0_u8; 12], + ciphertext: [0_u8; 24], + } + } +} + #[cfg(test)] mod tests { use super::*; diff --git a/zk-token-sdk/src/zk_token_elgamal/pod.rs b/zk-token-sdk/src/zk_token_elgamal/pod.rs index 2ae931c611..e8b28e2b9d 100644 --- a/zk-token-sdk/src/zk_token_elgamal/pod.rs +++ b/zk-token-sdk/src/zk_token_elgamal/pod.rs @@ -70,12 +70,17 @@ pub struct RangeProof128(pub [u8; 736]); unsafe impl Zeroable for RangeProof128 {} unsafe impl Pod for RangeProof128 {} -/// Serialization for AESCiphertext -#[derive(Clone, Copy, Pod, Zeroable, PartialEq)] +/// Serialization for AesCiphertext +#[derive(Clone, Copy, PartialEq)] #[repr(transparent)] -pub struct AESCiphertext(pub [u8; 16]); +pub struct AesCiphertext(pub [u8; 36]); -impl fmt::Debug for AESCiphertext { +// `AesCiphertext` is a Pod and Zeroable. +// Add the marker traits manually because `bytemuck` only adds them for some `u8` arrays +unsafe impl Zeroable for AesCiphertext {} +unsafe impl Pod for AesCiphertext {} + +impl fmt::Debug for AesCiphertext { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{:?}", self.0) }