Skip to content

Commit

Permalink
impl Display, FromStr, From<[u8; _]> for decrypt handle pod type
Browse files Browse the repository at this point in the history
  • Loading branch information
samkim-crypto committed Sep 3, 2024
1 parent 5cbc181 commit d598eb2
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions zk-sdk/src/encryption/pod/elgamal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -150,6 +153,20 @@ impl TryFrom<PodDecryptHandle> 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};
Expand Down

0 comments on commit d598eb2

Please sign in to comment.