[−][src]Enum encon::Encryptable
A value that can either be encrypted or plain, functionality to transition between the two states, and a pretty serde representation. In either variant, it represents an arbitrary JSON value.
Example
The serialized form of Encryptable::Plain
is transparent (equivalent to the underlying
serde_json::Value
). The encrypted form uses an array of fixed width hex strings to keep
lines short and nicely formatted, even if the encrypted blob is kilobytes in size.
use encon::Encryptable; use serde_json::to_string_pretty; let encrypted = Encryptable::Encrypted((0..255).collect()); let json = to_string_pretty(&encrypted).unwrap(); assert_eq!(json.as_str(), r#"{ "_encrypted": [ "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122", "232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445", "464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768", "696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b", "8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadae", "afb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1", "d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4", "f5f6f7f8f9fafbfcfdfe" ] }"#);
Variants
Plain(Value)
Implementations
impl Encryptable
[src]
pub fn kind(&self) -> EncryptableKind
[src]
Returns the variant kind.
pub fn is_encrypted(&self) -> bool
[src]
pub fn as_encrypted(&self) -> Option<&[u8]>
[src]
If this is the encrypted variant, returns a the encrypted blob.
pub fn as_plain(&self) -> Option<&Value>
[src]
If this is the plain variant, returns the serde_json Value
.
pub fn to_encrypted(&self, password: &Password) -> Result<Self, EncryptError>
[src]
If not already encrypted, this will return an encrypted copy of the Encryptable
.
See Password::encrypt
for details.
pub fn to_decrypted(&self, password: &Password) -> Result<Self, DecryptError>
[src]
If not already in the plain variant, this will return a decrypted/plain copy of
the Encryptable
. Will return an error if the password is invalid, or the encrypted
blob is invalid.
See Password::decrypt
for details.
pub fn encrypt(&self, password: &Password) -> Result<Vec<u8>, EncryptError>
[src]
Produces the encryption output as a Vec
of bytes. This encrypts the value if not
already encrypted.
See Password::encrypt
for details.
pub fn decrypt(&self, password: &Password) -> Result<Value, DecryptError>
[src]
Produces the decrypted JSON value. This decrypts the value if already encrypted.
See Password::decrypt
for details.
pub fn with_intent_encrypted(self) -> WithIntent
[src]
Wrap this in a WithIntent
with the encrypted variant
pub fn with_intent_plain(self) -> WithIntent
[src]
Wrap this in a WithIntent
with the plain variant
Trait Implementations
impl Clone for Encryptable
[src]
fn clone(&self) -> Encryptable
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Debug for Encryptable
[src]
impl<'de> Deserialize<'de> for Encryptable
[src]
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
D: Deserializer<'de>,
[src]
D: Deserializer<'de>,
impl From<Encryptable> for WithIntent
[src]
fn from(inner: Encryptable) -> Self
[src]
impl Serialize for Encryptable
[src]
Auto Trait Implementations
impl RefUnwindSafe for Encryptable
impl Send for Encryptable
impl Sync for Encryptable
impl Unpin for Encryptable
impl UnwindSafe for Encryptable
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,