//! Ciphertext produced by this library. //! //! This type doesn't map directly to any type in the Keychain Services API, //! but instead provides a newtype for ciphertexts this binding produces. use crate::key::KeyAlgorithm; /// Cryptographic signatures #[derive(Clone, Debug)] pub struct Ciphertext { alg: KeyAlgorithm, bytes: Vec, } impl Ciphertext { /// Create a new `Ciphertext` pub fn new(alg: KeyAlgorithm, bytes: Vec) -> Self { // TODO: restrict valid algorithms to encryption algorithms? Self { alg, bytes } } /// Get the algorithm which produced this signature pub fn algorithm(&self) -> KeyAlgorithm { self.alg } /// Borrow the ciphertext data as bytes pub fn as_bytes(&self) -> &[u8] { &self.bytes } /// Convert into a byte vector pub fn into_vec(self) -> Vec { self.bytes } } impl AsRef<[u8]> for Ciphertext { fn as_ref(&self) -> &[u8] { self.as_bytes() } } impl From for Vec { fn from(ciphertext: Ciphertext) -> Vec { ciphertext.into_vec() } }