diff --git a/zk-sdk/src/encryption/pod/elgamal.rs b/zk-sdk/src/encryption/pod/elgamal.rs index 7a53d88a8741a9..6b30f27a127e3a 100644 --- a/zk-sdk/src/encryption/pod/elgamal.rs +++ b/zk-sdk/src/encryption/pod/elgamal.rs @@ -24,6 +24,9 @@ const ELGAMAL_PUBKEY_MAX_BASE64_LEN: usize = 44; /// Maximum length of a base64 encoded ElGamal ciphertext const ELGAMAL_CIPHERTEXT_MAX_BASE64_LEN: usize = 88; +/// Maximum length of a base64 encoded ElGamal decrypt handle +const DECRYPT_HANDLE_MAX_BASE64_LEN: usize = 44; + /// The `ElGamalCiphertext` type as a `Pod`. #[derive(Clone, Copy, bytemuck_derive::Pod, bytemuck_derive::Zeroable, PartialEq, Eq)] #[repr(transparent)] @@ -150,6 +153,20 @@ impl TryFrom for DecryptHandle { } } +impl fmt::Display for PodDecryptHandle { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{}", BASE64_STANDARD.encode(self.0)) + } +} + +impl_from_str!( + TYPE = PodDecryptHandle, + BYTES_LEN = DECRYPT_HANDLE_LEN, + BASE64_LEN = DECRYPT_HANDLE_MAX_BASE64_LEN +); + +impl_from_bytes!(TYPE = PodDecryptHandle, BYTES_LEN = DECRYPT_HANDLE_LEN); + #[cfg(test)] mod tests { use {super::*, crate::encryption::elgamal::ElGamalKeypair, std::str::FromStr};