pub struct Encryption { /* private fields */ }Expand description
The application’s encrypter and signer, as one container-storable value.
A newtype over the two ports rather than binding them separately, so
swapping either does not change a call site — the same reason
rainier-framework’s Views wraps a view engine.
Implementations§
Source§impl Encryption
impl Encryption
Sourcepub fn new(encrypter: Arc<dyn Encrypter>, signer: Arc<dyn Signer>) -> Self
pub fn new(encrypter: Arc<dyn Encrypter>, signer: Arc<dyn Signer>) -> Self
Wrap an encrypter and a signer.
Sourcepub fn from_keys(keys: KeyRing) -> Self
pub fn from_keys(keys: KeyRing) -> Self
The default pairing — XChaCha20-Poly1305 and HMAC-SHA256 over one ring.
Sourcepub fn from_keys_with(keys: KeyRing, cipher: Cipher) -> Self
pub fn from_keys_with(keys: KeyRing, cipher: Cipher) -> Self
The same, with an explicit Cipher.
Reading is unaffected: a payload names its own algorithm, so switching this does not strand anything already written.
Sourcepub fn keys(&self) -> Option<&KeyRing>
pub fn keys(&self) -> Option<&KeyRing>
The key ring, when this was built from one.
None when the encrypter and signer were supplied separately — see
new. A caller that needs a ring of its own should ask
for one rather than assume.
Sourcepub fn encrypt_bytes(&self, plain: &[u8]) -> Result<String>
pub fn encrypt_bytes(&self, plain: &[u8]) -> Result<String>
Encrypt raw bytes.
Sourcepub fn encrypt_json<T: Serialize>(&self, value: &T) -> Result<String>
pub fn encrypt_json<T: Serialize>(&self, value: &T) -> Result<String>
Encrypt any serialisable value as JSON.
Sourcepub fn decrypt_json<T: DeserializeOwned>(&self, payload: &str) -> Result<T>
pub fn decrypt_json<T: DeserializeOwned>(&self, payload: &str) -> Result<T>
Decrypt JSON back into a value.