pub struct ConfigEncryptor { /* private fields */ }Expand description
Encryptor for configuration values. 配置值加密器。
Implementations§
Source§impl ConfigEncryptor
impl ConfigEncryptor
Sourcepub fn new(password: &str) -> Self
pub fn new(password: &str) -> Self
Create a new encryptor from a password string. 从密码字符串创建加密器。
The password is derived into a 256-bit key via HMAC-SHA256.
Sourcepub fn encrypt(&self, plaintext: &str) -> Result<String, EncryptError>
pub fn encrypt(&self, plaintext: &str) -> Result<String, EncryptError>
Encrypt a plaintext string and return ENC(base64).
加密明文字符串并返回 ENC(base64) 格式。
Sourcepub fn decrypt(&self, encrypted: &str) -> Result<String, EncryptError>
pub fn decrypt(&self, encrypted: &str) -> Result<String, EncryptError>
Decrypt an encrypted value, handling both ENC(...) wrapped and raw base64.
解密加密值,支持 ENC(...) 包裹和纯 base64 格式。
Sourcepub fn is_encrypted(value: &str) -> bool
pub fn is_encrypted(value: &str) -> bool
Check if a value looks like an encrypted ENC(...) value.
检查值是否为 ENC(...) 加密格式。
Sourcepub fn maybe_decrypt(&self, value: &str) -> Result<String, EncryptError>
pub fn maybe_decrypt(&self, value: &str) -> Result<String, EncryptError>
Decrypt a value if it’s ENC(...), otherwise return as-is.
如果值是 ENC(...) 则解密,否则原样返回。
Sourcepub fn decrypt_json_value(&self, value: &mut Value) -> Result<(), EncryptError>
pub fn decrypt_json_value(&self, value: &mut Value) -> Result<(), EncryptError>
Recursively decrypt all ENC(...) values in a JSON value.
递归解密 JSON 值中的所有 ENC(...) 值。
Auto Trait Implementations§
impl Freeze for ConfigEncryptor
impl RefUnwindSafe for ConfigEncryptor
impl Send for ConfigEncryptor
impl Sync for ConfigEncryptor
impl Unpin for ConfigEncryptor
impl UnsafeUnpin for ConfigEncryptor
impl UnwindSafe for ConfigEncryptor
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