pub struct Encrypted(pub String);Expand description
A column encrypted with a random nonce: reads decrypt, writes encrypt.
Use it as the type of an encrypted column in the row struct: reading a
row decrypts the stored text with the installed keys (a failure is a
deserialization error, so the query fails with a 500). Input structs
(New/Changes, forms, JSON bodies) keep a plain String and the
model binds Encrypted::from(value), which stores a new ciphertext.
Serializing (JSON responses, templates) writes the plain value; Debug
hides it.
§Examples
use ocre::{IntoParam, encryption::{self, Encrypted, Encryptor}};
encryption::install(Encryptor::new(&"t".repeat(64), &[]).unwrap());
let ssn = Encrypted::from("123-45-6789");
assert_eq!(serde_json::to_string(&ssn).unwrap(), r#""123-45-6789""#);
assert_ne!(ssn.clone().into_param(), "123-45-6789".into_param());
assert_eq!(format!("{ssn:?}"), "Encrypted(..)");Tuple Fields§
§0: StringImplementations§
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Encrypted
impl<'de> Deserialize<'de> for Encrypted
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Deserialize this value from the given Serde deserializer. Read more
impl Eq for Encrypted
Source§impl IntoParam for Encrypted
Binds the encrypted text. Without installed keys (no valid
SECRET_KEY_BASE) it binds NULL, which a NOT NULL column
refuses; the error is logged.
impl IntoParam for Encrypted
Binds the encrypted text. Without installed keys (no valid
SECRET_KEY_BASE) it binds NULL, which a NOT NULL column
refuses; the error is logged.
Source§fn into_param(self) -> Param
fn into_param(self) -> Param
Converts the value into a bound parameter.
impl StructuralPartialEq for Encrypted
Auto Trait Implementations§
impl Freeze for Encrypted
impl RefUnwindSafe for Encrypted
impl Send for Encrypted
impl Sync for Encrypted
impl Unpin for Encrypted
impl UnsafeUnpin for Encrypted
impl UnwindSafe for Encrypted
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Checks if this value is equivalent to the given key. Read more
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.