Struct lock_keeper::crypto::generic::Encrypted
source · pub struct Encrypted<T> {
pub(super) ciphertext: Vec<u8>,
pub(super) associated_data: AssociatedData,
pub(super) nonce: Nonce,
pub(super) original_type: PhantomData<T>,
}
Expand description
A ciphertext representing an object of type T
, encrypted under the
ChaCha20Poly1305 scheme for
authenticated encryption with associated data (AEAD).
As implied by the scheme name, this uses the recommended 20 rounds and a standard 96-bit nonce. For more details, see the ChaCha20Poly1305 crate.
Fields§
§ciphertext: Vec<u8>
§associated_data: AssociatedData
§nonce: Nonce
§original_type: PhantomData<T>
Implementations§
source§impl Encrypted<Secret>
impl Encrypted<Secret>
sourcepub fn decrypt_secret(
self,
storage_key: StorageKey
) -> Result<Secret, LockKeeperError>
pub fn decrypt_secret( self, storage_key: StorageKey ) -> Result<Secret, LockKeeperError>
Decrypt a secret. This should be run as part of the subprotocol to retrieve a secret from the server.
This must be run by the client.
source§impl Encrypted<DataBlob>
impl Encrypted<DataBlob>
sourcepub fn decrypt_data_blob(
self,
remote_storage_key: &RemoteStorageKey
) -> Result<DataBlob, LockKeeperError>
pub fn decrypt_data_blob( self, remote_storage_key: &RemoteStorageKey ) -> Result<DataBlob, LockKeeperError>
Decrypt data blob server-side.
source§impl<T> Encrypted<T>
impl<T> Encrypted<T>
sourcepub(super) fn encrypt(
rng: &mut (impl CryptoRng + RngCore),
enc_key: &EncryptionKey,
object: T,
associated_data: &AssociatedData
) -> Result<Encrypted<T>, CryptoError>
pub(super) fn encrypt( rng: &mut (impl CryptoRng + RngCore), enc_key: &EncryptionKey, object: T, associated_data: &AssociatedData ) -> Result<Encrypted<T>, CryptoError>
Encrypt the T
and authenticate the AssociatedData
under the
EncryptionKey
.
Raises a [CryptoError::EncryptionFailed
] if encryption fails.
sourcepub(super) fn decrypt_inner(
self,
enc_key: &EncryptionKey
) -> Result<T, CryptoError>
pub(super) fn decrypt_inner( self, enc_key: &EncryptionKey ) -> Result<T, CryptoError>
Decrypt the ciphertext to a T
.
Raises a [CryptoError::DecryptionFailed
] if decryption fails or
[CryptoError::ConversionError
] if the decrypted plaintext cannot be
converted into T
.
source§impl Encrypted<SigningKeyPair>
impl Encrypted<SigningKeyPair>
sourcepub fn decrypt_signing_key(
self,
storage_key: StorageKey,
user_id: UserId,
key_id: KeyId
) -> Result<SigningKeyPair, LockKeeperError>
pub fn decrypt_signing_key( self, storage_key: StorageKey, user_id: UserId, key_id: KeyId ) -> Result<SigningKeyPair, LockKeeperError>
Decrypt a signing key. This should be run as part of the subprotocol to retrieve an encrypted signing key from the server.
This must be run by the client.
sourcepub fn decrypt_signing_key_by_server(
self,
remote_storage_key: &RemoteStorageKey,
user_id: UserId,
key_id: KeyId
) -> Result<SigningKeyPair, LockKeeperError>
pub fn decrypt_signing_key_by_server( self, remote_storage_key: &RemoteStorageKey, user_id: UserId, key_id: KeyId ) -> Result<SigningKeyPair, LockKeeperError>
Decrypt a signing key. This should be run by the server as part of the subprotocol to retrieve a signing key from the server.
fn decrypt( self, encryption_key: &EncryptionKey, user_id: UserId, key_id: KeyId, possible_context_strings: Vec<&str> ) -> Result<SigningKeyPair, LockKeeperError>
source§impl Encrypted<StorageKey>
impl Encrypted<StorageKey>
sourcepub fn decrypt_storage_key(
self,
master_key: MasterKey,
user_id: &UserId
) -> Result<StorageKey, LockKeeperError>
pub fn decrypt_storage_key( self, master_key: MasterKey, user_id: &UserId ) -> Result<StorageKey, LockKeeperError>
Decrypt a storage key. This should be run as part of the subprotocol to retrieve a storage key from the server.
This must be run by the client. It takes the following steps:
- Derive the decryption key from the master key using the associated data
- Decrypt the encrypted storage key using the decryption key
- Return the decrypted
StorageKey
source§impl Encrypted<OpaqueSessionKey>
impl Encrypted<OpaqueSessionKey>
sourcepub fn decrypt_session_key(
self,
remote_storage_key: &RemoteStorageKey
) -> Result<OpaqueSessionKey, LockKeeperError>
pub fn decrypt_session_key( self, remote_storage_key: &RemoteStorageKey ) -> Result<OpaqueSessionKey, LockKeeperError>
Decrypt a session key server-side.
source§impl Encrypted<Message>
impl Encrypted<Message>
pub fn decrypt_message( self, session_key: &OpaqueSessionKey ) -> Result<Message, LockKeeperError>
sourcepub fn try_into_message(self) -> Result<Message, LockKeeperError>
pub fn try_into_message(self) -> Result<Message, LockKeeperError>
Translates an Encrypted<Message>
to a Message
in order to be
sent through an authenticated channel.
sourcepub fn try_from_message(message: Message) -> Result<Self, LockKeeperError>
pub fn try_from_message(message: Message) -> Result<Self, LockKeeperError>
Translates a Message
received through an authenticated channel to an
Encrypted<Message>
.
Trait Implementations§
source§impl<'de, T> Deserialize<'de> for Encrypted<T>
impl<'de, T> Deserialize<'de> for Encrypted<T>
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl<T: PartialEq> PartialEq for Encrypted<T>
impl<T: PartialEq> PartialEq for Encrypted<T>
source§impl TryFrom<RetrievedSecret> for Encrypted<Secret>
impl TryFrom<RetrievedSecret> for Encrypted<Secret>
§type Error = LockKeeperError
type Error = LockKeeperError
source§impl TryFrom<StoredSecret> for Encrypted<SigningKeyPair>
impl TryFrom<StoredSecret> for Encrypted<SigningKeyPair>
§type Error = LockKeeperError
type Error = LockKeeperError
impl<T: Eq> Eq for Encrypted<T>
impl<T> StructuralPartialEq for Encrypted<T>
Auto Trait Implementations§
impl<T> Freeze for Encrypted<T>
impl<T> RefUnwindSafe for Encrypted<T>where
T: RefUnwindSafe,
impl<T> Send for Encrypted<T>where
T: Send,
impl<T> Sync for Encrypted<T>where
T: Sync,
impl<T> Unpin for Encrypted<T>where
T: Unpin,
impl<T> UnwindSafe for Encrypted<T>where
T: UnwindSafe,
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
source§impl<T> ConvertMessage for Twhere
T: for<'a> Deserialize<'a> + Serialize,
impl<T> ConvertMessage for Twhere
T: for<'a> Deserialize<'a> + Serialize,
fn from_message(value: Message) -> Result<Self, LockKeeperError>
fn to_message(self) -> Result<Message, LockKeeperError>
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§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
§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
key
and return true
if they are equal.source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request