pub struct EncryptedMessage<P: Debug + DeserializeOwned + Serialize, C: Config> { /* private fields */ }
Expand description
Used to safely handle & transport encrypted data within your application. It contains an encrypted payload, along with a nonce & tag that are used in the encryption & decryption processes.
Implementations§
Source§impl<P: Debug + DeserializeOwned + Serialize, C: Config> EncryptedMessage<P, C>
impl<P: Debug + DeserializeOwned + Serialize, C: Config> EncryptedMessage<P, C>
Sourcepub fn encrypt_with_config(
payload: P,
config: &C,
) -> Result<Self, EncryptionError>
pub fn encrypt_with_config( payload: P, config: &C, ) -> Result<Self, EncryptionError>
Creates an EncryptedMessage
from a payload, using the AES-256-GCM encryption cipher.
§Errors
- Returns an
EncryptionError::Serialization
error if the payload cannot be serialized into a JSON string. Seeserde_json::to_vec
for more information.
Sourcepub fn decrypt_with_config(&self, config: &C) -> Result<P, DecryptionError>
pub fn decrypt_with_config(&self, config: &C) -> Result<P, DecryptionError>
Decrypts the payload of the EncryptedMessage
, trying all available keys in order until it finds one that works.
§Errors
- Returns a
DecryptionError::Base64Decoding
error if the base64-decoding of the payload, nonce, or tag fails. - Returns a
DecryptionError::Decryption
error if the payload cannot be decrypted with any of the available keys. - Returns a
DecryptionError::Deserialization
error if the payload cannot be deserialized into the expected type. Seeserde_json::from_slice
for more information.
Source§impl<P: Debug + DeserializeOwned + Serialize, C: Config + Default> EncryptedMessage<P, C>
impl<P: Debug + DeserializeOwned + Serialize, C: Config + Default> EncryptedMessage<P, C>
Sourcepub fn encrypt(payload: P) -> Result<Self, EncryptionError>
pub fn encrypt(payload: P) -> Result<Self, EncryptionError>
This method is a shorthand for EncryptedMessage::encrypt_with_config
,
passing &C::default()
as the configuration.
Sourcepub fn decrypt(&self) -> Result<P, DecryptionError>
pub fn decrypt(&self) -> Result<P, DecryptionError>
This method is a shorthand for EncryptedMessage::decrypt_with_config
,
passing &C::default()
as the configuration.
Trait Implementations§
Source§impl<P: Debug + Debug + DeserializeOwned + Serialize, C: Debug + Config> Debug for EncryptedMessage<P, C>
impl<P: Debug + Debug + DeserializeOwned + Serialize, C: Debug + Config> Debug for EncryptedMessage<P, C>
Source§impl<'de, P: Debug + DeserializeOwned + Serialize, C: Config> Deserialize<'de> for EncryptedMessage<P, C>
impl<'de, P: Debug + DeserializeOwned + Serialize, C: Config> Deserialize<'de> for EncryptedMessage<P, C>
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl<P: PartialEq + Debug + DeserializeOwned + Serialize, C: PartialEq + Config> PartialEq for EncryptedMessage<P, C>
impl<P: PartialEq + Debug + DeserializeOwned + Serialize, C: PartialEq + Config> PartialEq for EncryptedMessage<P, C>
Source§impl<P: Debug + DeserializeOwned + Serialize, C: Config> Serialize for EncryptedMessage<P, C>
impl<P: Debug + DeserializeOwned + Serialize, C: Config> Serialize for EncryptedMessage<P, C>
impl<P: Eq + Debug + DeserializeOwned + Serialize, C: Eq + Config> Eq for EncryptedMessage<P, C>
impl<P: Debug + DeserializeOwned + Serialize, C: Config> StructuralPartialEq for EncryptedMessage<P, C>
Auto Trait Implementations§
impl<P, C> Freeze for EncryptedMessage<P, C>
impl<P, C> RefUnwindSafe for EncryptedMessage<P, C>where
P: RefUnwindSafe,
C: RefUnwindSafe,
impl<P, C> Send for EncryptedMessage<P, C>
impl<P, C> Sync for EncryptedMessage<P, C>
impl<P, C> Unpin for EncryptedMessage<P, C>
impl<P, C> UnwindSafe for EncryptedMessage<P, C>where
P: UnwindSafe,
C: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more