strong_box/
strong_box.rs

1use super::Error;
2
3/// Core trait that all the various forms of encrypting StrongBoxes implement to provide encryption
4/// / decryption functionality.
5pub trait StrongBox {
6	/// Encrypt secret data using the [`StrongBox`]'s encryption key, within the [`StrongBox`]'s specified context.
7	///
8	/// # Errors
9	///
10	/// Will return [`Error::Encryption`] or [`Error::Encoding`] in the (extremely
11	/// unlikely) event something goes horribly wrong.
12	fn encrypt(
13		&self,
14		plaintext: impl AsRef<[u8]>,
15		context: impl AsRef<[u8]> + std::fmt::Debug,
16	) -> Result<Vec<u8>, Error>;
17
18	/// Decrypt a ciphertext, using any valid key for the [`StrongBox`], and validate that the ciphertext
19	/// was encrypted with the specified context.
20	///
21	/// # Errors
22	///
23	/// Will return one of the following:
24	/// * [`Error::Decryption`] if the ciphertext was encrypted with a different
25	///   key, or a different context.
26	/// * [`Error::Decoding`] if the ciphertext was malformed, which means that either the
27	///   ciphertext was corrupted in storage or transit, or the data provided was never a
28	///   ciphertext.
29	fn decrypt(
30		&self,
31		ciphertext: impl AsRef<[u8]>,
32		context: impl AsRef<[u8]> + std::fmt::Debug,
33	) -> Result<Vec<u8>, Error>;
34}