pub trait StringEncryptor {
// Required methods
fn encrypt(&self, plaintext: &str) -> Result<String>;
fn decrypt(&self, encoded: &str) -> Result<String>;
// Provided methods
fn encrypt_with_prefix(&self, plaintext: &str) -> Result<String> { ... }
fn decrypt_prefixed(&self, value: &str) -> Result<String> { ... }
fn decrypt_all_in_string(&self, input: &str) -> Result<String> { ... }
fn decrypt_all_in_string_lossy(&self, input: &str) -> String { ... }
fn decrypt_map(
&self,
map: &HashMap<String, String>,
) -> Result<HashMap<String, String>> { ... }
}Expand description
Common interface implemented by Encryptor,
JasyptEncryptor and
JasyptStrongEncryptor.
Every concrete encryptor also exposes these methods inherently, so you only
need to import the trait when writing code that is generic over the
encryptor (for example fn load<E: StringEncryptor>(enc: &E)), or when
working with Box<dyn StringEncryptor>.
Required Methods§
Provided Methods§
Sourcefn encrypt_with_prefix(&self, plaintext: &str) -> Result<String>
fn encrypt_with_prefix(&self, plaintext: &str) -> Result<String>
Encrypts plaintext and wraps the result as ENC(...).
Sourcefn decrypt_prefixed(&self, value: &str) -> Result<String>
fn decrypt_prefixed(&self, value: &str) -> Result<String>
Decrypts an ENC(...)-wrapped value. Surrounding whitespace is ignored.
Returns Error::InvalidEncFormat when the wrapper is missing.
Sourcefn decrypt_all_in_string(&self, input: &str) -> Result<String>
fn decrypt_all_in_string(&self, input: &str) -> Result<String>
Replaces every ENC(...) occurrence in input with its plaintext.
Matches that fail to decrypt are left untouched and, after the whole
input has been processed, the last error is returned (GoCrypt
semantics). Use decrypt_all_in_string_lossy
when you want the best-effort output regardless of failures.
Sourcefn decrypt_all_in_string_lossy(&self, input: &str) -> String
fn decrypt_all_in_string_lossy(&self, input: &str) -> String
Like decrypt_all_in_string but never
fails: matches that cannot be decrypted are kept verbatim
(NodeCrypt/PyCrypt semantics, and what the rustcrypt decrypt-file
command uses).
Sourcefn decrypt_map(
&self,
map: &HashMap<String, String>,
) -> Result<HashMap<String, String>>
fn decrypt_map( &self, map: &HashMap<String, String>, ) -> Result<HashMap<String, String>>
Decrypts every ENC(...) value in map; other values are copied as-is.
The first failure aborts with Error::KeyDecrypt naming the key.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".