Struct fog_crypto::stream::StreamKey [−][src]
Stream Key that allows encrypting data into a Lockbox and decrypting it later.
This acts as a wrapper for a specific cryptographic symmetric key, which can only be used with the corresponding symmetric encryption algorithm. The underlying key may be located in a hardware module or some other private keystore; in this case, it may be impossible to export the key.
// Make a new temporary key let mut csprng = rand::rngs::OsRng {}; let key = StreamKey::new_temp(&mut csprng); let id = key.id().clone(); // Encrypt some data with the key, then turn it into a byte vector let data = b"I am sensitive information, about to be encrypted"; let lockbox = key.encrypt_data(&mut csprng, data.as_ref()); let mut encoded = Vec::new(); encoded.extend_from_slice(lockbox.as_bytes()); // Decrypt that data with the same key let dec_lockbox = DataLockboxRef::from_bytes(encoded.as_ref())?; let dec_data = key.decrypt_data(dec_lockbox)?;
Implementations
impl StreamKey[src]
pub fn new_temp<R>(csprng: &mut R) -> StreamKey where
R: CryptoRng + RngCore, [src]
R: CryptoRng + RngCore,
Generate a temporary StreamKey that exists only in program memory.
pub fn new_temp_with_version<R>(
csprng: &mut R,
version: u8
) -> Result<StreamKey, CryptoError> where
R: CryptoRng + RngCore, [src]
csprng: &mut R,
version: u8
) -> Result<StreamKey, CryptoError> where
R: CryptoRng + RngCore,
Generate a temporary StreamKey that exists only in program memory. Uses the specified
version instead of the default, and fails if the version is unsupported.
pub fn version(&self) -> u8[src]
Version of symmetric encryption algorithm used by this key.
pub fn id(&self) -> &StreamId[src]
The publically shareable identifier for this key.
pub fn encrypt_data<R: CryptoRng + RngCore>(
&self,
csprng: &mut R,
content: &[u8]
) -> DataLockbox[src]
&self,
csprng: &mut R,
content: &[u8]
) -> DataLockbox
Encrypt a byte slice into a DataLockbox. Requires a cryptographic RNG to generate the
needed nonce.
pub fn decrypt_lock_key(
&self,
lockbox: &LockLockboxRef
) -> Result<LockKey, CryptoError>[src]
&self,
lockbox: &LockLockboxRef
) -> Result<LockKey, CryptoError>
Attempt to decrypt a LockLockboxRef with this key. On success, the returned LockKey is
temporary and not associated with any Vault.
pub fn decrypt_identity_key(
&self,
lockbox: &IdentityLockboxRef
) -> Result<IdentityKey, CryptoError>[src]
&self,
lockbox: &IdentityLockboxRef
) -> Result<IdentityKey, CryptoError>
Attempt to decrypt a IdentityLockboxRef with this key. On success, the returned
IdentityKey is temporary and not associated with any Vault.
pub fn decrypt_stream_key(
&self,
lockbox: &StreamLockboxRef
) -> Result<StreamKey, CryptoError>[src]
&self,
lockbox: &StreamLockboxRef
) -> Result<StreamKey, CryptoError>
Attempt to decrypt a StreamLockboxRef with this key. On success, the returned
StreamKey is temporary and not associated with any Vault.
pub fn decrypt_data(
&self,
lockbox: &DataLockboxRef
) -> Result<Vec<u8>, CryptoError>[src]
&self,
lockbox: &DataLockboxRef
) -> Result<Vec<u8>, CryptoError>
Attempt to decrypt a DataLockboxRef with this key.
pub fn export_for_lock<R: CryptoRng + RngCore>(
&self,
csprng: &mut R,
lock: &LockId
) -> Option<StreamLockbox>[src]
&self,
csprng: &mut R,
lock: &LockId
) -> Option<StreamLockbox>
Pack this secret into a StreamLockbox, meant for the recipient specified by id. Returns
None if this key cannot be exported.
pub fn export_for_stream<R: CryptoRng + RngCore>(
&self,
csprng: &mut R,
stream: &StreamKey
) -> Option<StreamLockbox>[src]
&self,
csprng: &mut R,
stream: &StreamKey
) -> Option<StreamLockbox>
Pack this key into a StreamLockbox, meant for the recipient specified by stream. Returns
None if this key cannot be exported for the given recipient. Generally, the recipient
should be in the same Vault as the key being exported, or the exported key should be a
temporary key.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for StreamKey
impl Send for StreamKey
impl Sync for StreamKey
impl Unpin for StreamKey
impl !UnwindSafe for StreamKey
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> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
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> ToString for T where
T: Display + ?Sized, [src]
T: Display + ?Sized,
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>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,