pub struct ClearText { /* private fields */ }
Expand description
An unencrypted blob of plaintext.
This type exists to facilitate marshaling data to a serialized, encrypted, representation
Implementations§
Source§impl ClearText
impl ClearText
Sourcepub fn new<T>(item: &T) -> Result<Self, BackendError>where
T: Serialize,
pub fn new<T>(item: &T) -> Result<Self, BackendError>where
T: Serialize,
Creates a new Cleartext
from a serializeable object
§Errors
Will return an error if serialization fails
Sourcepub fn encrypt<K>(
self,
key: &K,
compression: Option<i32>,
) -> Result<CipherText<'static>, BackendError>where
K: Key,
pub fn encrypt<K>(
self,
key: &K,
compression: Option<i32>,
) -> Result<CipherText<'static>, BackendError>where
K: Key,
Attempts to create an encrypted version of this Cleartext
using the provided key. ZStd
compression will be applied to the plain text before encryption with the provided level, if the
compression option is set with a Some
value.
§DANGER
Compression can be incredibly dangerous when combined with encryption, do not set the compression flag unless you know what you are doing, and you are 100% sure that compression related attacks do not fall into your threat model.
§Errors
Will return an error if encryption fails.
Sourcepub fn deserialize<T>(&self) -> Result<T, BackendError>where
T: DeserializeOwned,
pub fn deserialize<T>(&self) -> Result<T, BackendError>where
T: DeserializeOwned,
Converts this Cleartext
back into its original type.
§Errors
Will return Err(Error::ItemDeserialization)
if the serialization. Be warned, since this
intentionally erases the underlying serde
error, it can be difficult to tell if this is due to
data corruption, or simply calling this method with the wrong type argument.