Struct encrypted_message::EncryptedMessage
source · pub struct EncryptedMessage<P: Debug + DeserializeOwned + Serialize, S: Strategy, K: KeyConfig> { /* 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, S: Strategy, K: KeyConfig> EncryptedMessage<P, S, K>
impl<P: Debug + DeserializeOwned + Serialize, S: Strategy, K: KeyConfig> EncryptedMessage<P, S, K>
sourcepub fn encrypt_with_key_config(
payload: P,
key_config: &K
) -> Result<Self, EncryptionError>
pub fn encrypt_with_key_config( payload: P, key_config: &K ) -> Result<Self, EncryptionError>
Creates an EncryptedMessage from a payload, using the AES-256-GCM encryption cipher.
§Errors
- Returns an
EncryptionError::Serializationerror if the payload cannot be serialized into a JSON string. Seeserde_json::to_valuefor more information.
sourcepub fn decrypt_with_key_config(
&self,
key_config: &K
) -> Result<P, DecryptionError>
pub fn decrypt_with_key_config( &self, key_config: &K ) -> 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::Base64Decodingerror if the base64-decoding of the payload, nonce, or tag fails. - Returns a
DecryptionError::Decryptionerror if the payload cannot be decrypted with any of the available keys. - Returns a
DecryptionError::Deserializationerror if the payload cannot be deserialized into the expected type. Seeserde_json::from_slicefor more information.
sourcepub fn with_new_payload_and_key_config(
self,
payload: P,
key_config: &K
) -> Result<Self, EncryptionError>
pub fn with_new_payload_and_key_config( self, payload: P, key_config: &K ) -> Result<Self, EncryptionError>
Consumes the EncryptedMessage & returns a new one with
the same encryption strategy, but with a new encrypted payload.
See EncryptedMessage::encrypt_with_key_config for more information.
source§impl<P: Debug + DeserializeOwned + Serialize, S: Strategy, K: KeyConfig + Default> EncryptedMessage<P, S, K>
impl<P: Debug + DeserializeOwned + Serialize, S: Strategy, K: KeyConfig + Default> EncryptedMessage<P, S, K>
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_key_config,
passing &K::default() as the key configuration.
sourcepub fn decrypt(&self) -> Result<P, DecryptionError>
pub fn decrypt(&self) -> Result<P, DecryptionError>
This method is a shorthand for EncryptedMessage::decrypt_with_key_config,
passing &K::default() as the key configuration.
sourcepub fn with_new_payload(self, payload: P) -> Result<Self, EncryptionError>
pub fn with_new_payload(self, payload: P) -> Result<Self, EncryptionError>
This method is a shorthand for EncryptedMessage::with_new_payload_and_key_config,
passing &K::default() as the key configuration.
Trait Implementations§
source§impl<P: Debug + Debug + DeserializeOwned + Serialize, S: Debug + Strategy, K: Debug + KeyConfig> Debug for EncryptedMessage<P, S, K>
impl<P: Debug + Debug + DeserializeOwned + Serialize, S: Debug + Strategy, K: Debug + KeyConfig> Debug for EncryptedMessage<P, S, K>
source§impl<'de, P: Debug + DeserializeOwned + Serialize, S: Strategy, K: KeyConfig> Deserialize<'de> for EncryptedMessage<P, S, K>
impl<'de, P: Debug + DeserializeOwned + Serialize, S: Strategy, K: KeyConfig> Deserialize<'de> for EncryptedMessage<P, S, K>
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>,
source§impl<P: PartialEq + Debug + DeserializeOwned + Serialize, S: PartialEq + Strategy, K: PartialEq + KeyConfig> PartialEq for EncryptedMessage<P, S, K>
impl<P: PartialEq + Debug + DeserializeOwned + Serialize, S: PartialEq + Strategy, K: PartialEq + KeyConfig> PartialEq for EncryptedMessage<P, S, K>
source§fn eq(&self, other: &EncryptedMessage<P, S, K>) -> bool
fn eq(&self, other: &EncryptedMessage<P, S, K>) -> bool
self and other values to be equal, and is used
by ==.