Struct fog_crypto::lock::LockKey

source ·
pub struct LockKey { /* private fields */ }
Expand description

A key that allows decrypting data meant for a particular LockId.

This acts as a wrapper for a specific cryptographic private decryption key,

Example


// Make a new temporary key
let key = LockKey::new();
let id = key.id().clone();
println!("LockId(Base58): {}", key.id());

// ...
// Wait for encrypted data to show up
// ...

// Decrypt Some received data
let lockbox = DataLockboxRef::from_bytes(received.as_ref())?;
let data = key.decrypt_data(&lockbox)?;

Implementations§

source§

impl LockKey

source

pub fn from_interface(interface: Arc<dyn LockInterface>) -> Self

Create a new LockKey to hold a LockInterface implementation. Can be used by implementors of a vault when making new LockKey instances.

source

pub fn new() -> LockKey

Generate a temporary LockKey that exists only in program memory.

source

pub fn with_rng<R>(csprng: &mut R) -> LockKeywhere R: CryptoRng + RngCore,

Generate a temporary LockKey that exists only in program memory, using the provided cryptographic RNG.

source

pub fn with_rng_and_version<R>( csprng: &mut R, version: u8 ) -> Result<LockKey, CryptoError>where R: CryptoRng + RngCore,

Generate a temporary LockKey that exists only in program memory. Uses the specified version instead of the default, and fails if the version is unsupported.

source

pub fn version(&self) -> u8

Version of Diffie-Hellman key exchange algorithm used by this key.

source

pub fn id(&self) -> &LockId

The public identifier for this key.

source

pub fn decrypt_lock_key( &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.

source

pub fn decrypt_identity_key( &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.

source

pub fn decrypt_stream_key( &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.

source

pub fn decrypt_data( &self, lockbox: &DataLockboxRef ) -> Result<Vec<u8>, CryptoError>

Attempt to decrypt a DataLockboxRef with this key.

source

pub fn export_for_lock(&self, lock: &LockId) -> Option<LockLockbox>

Export the signing key in a LockLockbox, with receive_lock as the recipient. If the key cannot be exported, this should return None.

source

pub fn export_for_lock_with_rng<R: CryptoRng + RngCore>( &self, csprng: &mut R, lock: &LockId ) -> Option<LockLockbox>

Export the signing key in an LockLockbox, with receive_lock as the recipient. If the key cannot be exported, this should return None.

source

pub fn export_for_stream(&self, stream: &StreamKey) -> Option<LockLockbox>

Export the private key in a LockLockbox, with receive_stream as the recipient. If the key cannot be exported, this should return None. Additionally, if the underlying implementation does not allow moving the raw key into memory (i.e. it cannot call StreamInterface::encrypt or lock_id_encrypt) then None can also be returned.

source

pub fn export_for_stream_with_rng<R: CryptoRng + RngCore>( &self, csprng: &mut R, stream: &StreamKey ) -> Option<LockLockbox>

Export the private key in a LockLockbox, with receive_stream as the recipient. If the key cannot be exported, this should return None. Additionally, if the underlying implementation does not allow moving the raw key into memory (i.e. it cannot call StreamInterface::encrypt or lock_id_encrypt) then None can also be returned.

Trait Implementations§

source§

impl Clone for LockKey

source§

fn clone(&self) -> LockKey

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for LockKey

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for LockKey

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl Display for LockKey

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Display just the LockId (never the underlying key).

source§

impl<T: LockInterface + 'static> From<T> for LockKey

source§

fn from(value: T) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl !RefUnwindSafe for LockKey

§

impl !Send for LockKey

§

impl !Sync for LockKey

§

impl Unpin for LockKey

§

impl !UnwindSafe for LockKey

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.