pub struct Key { /* private fields */ }Expand description
A handle to a key.
A key encapsulates secret key material, and exposes some secret
key operations like decrypting a message, signing a message,
changing the key’s password, and deleting the secret key material.
Not all keys implement all operations. In particular, a key will
typically either implement Key::decrypt_ciphertext or
Key::sign_message.
Implementations§
Source§impl Key
impl Key
Sourcepub fn key_handle(&self) -> KeyHandle
pub fn key_handle(&self) -> KeyHandle
Returns the key’s key handle.
Sourcepub fn fingerprint(&self) -> Fingerprint
pub fn fingerprint(&self) -> Fingerprint
Returns the key’s fingerprint.
Sourcepub fn public_key(&self) -> &Key<PublicParts, UnspecifiedRole>
pub fn public_key(&self) -> &Key<PublicParts, UnspecifiedRole>
Returns the key’s public key.
Sourcepub fn id(&mut self) -> Result<String>
pub fn id(&mut self) -> Result<String>
Returns a unique key identifier.
It should be a well-formed UTF-8 string, which should give a curious user a pretty good idea of what key this is.
Sourcepub async fn id_async(&mut self) -> Result<String>
pub async fn id_async(&mut self) -> Result<String>
Returns a unique key identifier.
It should be a well-formed UTF-8 string, which should give a curious user a pretty good idea of what key this is.
Sourcepub fn unlock(&mut self, password: Password) -> Result<()>
pub fn unlock(&mut self, password: Password) -> Result<()>
Unlocks a key.
A key is typically unlocked by providing a password or pin. Not all keys are locked. If the key is not available, this should attempt to connect to the device. If the device is not available or cannot be initialized, then this should fail.
Sourcepub async fn unlock_async(&mut self, password: Password) -> Result<()>
pub async fn unlock_async(&mut self, password: Password) -> Result<()>
Unlocks a key.
A key is typically unlocked by providing a password or pin. Not all keys are locked. If the key is not available, this should attempt to connect to the device. If the device is not available or cannot be initialized, then this should fail.
Sourcepub fn decrypt_ciphertext(
&mut self,
ciphertext: &Ciphertext,
plaintext_len: Option<usize>,
) -> Result<SessionKey>
pub fn decrypt_ciphertext( &mut self, ciphertext: &Ciphertext, plaintext_len: Option<usize>, ) -> Result<SessionKey>
Decrypts a ciphertext.
This function corresponds to Decryptor::decrypt.
When decrypting a message you normally don’t want to manually
try to decrypt each PKESK using this function, but use
Keystore::decrypt, which first tries to use keys that
don’t require user interaction.
If you want to decrypt a PKESK, then you should pass the
Key to PKESK::decrypt.
Sourcepub async fn decrypt_ciphertext_async(
&mut self,
ciphertext: &Ciphertext,
plaintext_len: Option<usize>,
) -> Result<SessionKey>
pub async fn decrypt_ciphertext_async( &mut self, ciphertext: &Ciphertext, plaintext_len: Option<usize>, ) -> Result<SessionKey>
Decrypts a ciphertext.
This function corresponds to Decryptor::decrypt.
When decrypting a message you normally don’t want to manually
try to decrypt each PKESK using this function, but use
Keystore::decrypt, which first tries to use keys that
don’t require user interaction.
If you want to decrypt a PKESK, then you should pass the
Key to PKESK::decrypt.
Sourcepub fn sign_message(
&mut self,
hash_algo: HashAlgorithm,
digest: &[u8],
) -> Result<Signature>
pub fn sign_message( &mut self, hash_algo: HashAlgorithm, digest: &[u8], ) -> Result<Signature>
Signs a message.
digest is the message to sign.
Sourcepub async fn sign_message_async(
&mut self,
hash_algo: HashAlgorithm,
digest: &[u8],
) -> Result<Signature>
pub async fn sign_message_async( &mut self, hash_algo: HashAlgorithm, digest: &[u8], ) -> Result<Signature>
Signs a message.
digest is the message to sign.
Sourcepub fn available(&mut self) -> Result<bool>
pub fn available(&mut self) -> Result<bool>
Whether the key is available.
If false, this usually means the device needs to be connected, e.g., a smartcard needs to be plugged in.
Sourcepub async fn available_async(&mut self) -> Result<bool>
pub async fn available_async(&mut self) -> Result<bool>
Whether the key is available.
If false, this usually means the device needs to be connected, e.g., a smartcard needs to be plugged in.
Sourcepub fn locked(&mut self) -> Result<Protection>
pub fn locked(&mut self) -> Result<Protection>
Whether the key is locked, and the type of protection.
Sourcepub async fn locked_async(&mut self) -> Result<Protection>
pub async fn locked_async(&mut self) -> Result<Protection>
Whether the key is locked, and the type of protection.
Sourcepub fn password_source(&mut self) -> Result<PasswordSource>
pub fn password_source(&mut self) -> Result<PasswordSource>
How the password is obtained to unlock the key.
This is independent of whether the key is currently protected.
Sourcepub async fn password_source_async(&mut self) -> Result<PasswordSource>
pub async fn password_source_async(&mut self) -> Result<PasswordSource>
How the password is obtained to unlock the key.
This is independent of whether the key is currently protected.
Sourcepub fn decryption_capable(&mut self) -> Result<bool>
pub fn decryption_capable(&mut self) -> Result<bool>
Whether the key can be used for decryption.
Sourcepub async fn decryption_capable_async(&mut self) -> Result<bool>
pub async fn decryption_capable_async(&mut self) -> Result<bool>
Whether the key can be used for decryption.
Sourcepub fn signing_capable(&mut self) -> Result<bool>
pub fn signing_capable(&mut self) -> Result<bool>
Whether the key can be used for signing.
Sourcepub async fn signing_capable_async(&mut self) -> Result<bool>
pub async fn signing_capable_async(&mut self) -> Result<bool>
Whether the key can be used for signing.
Sourcepub fn export(&mut self) -> Result<Key<SecretParts, UnspecifiedRole>>
pub fn export(&mut self) -> Result<Key<SecretParts, UnspecifiedRole>>
Exports the secret key material.
Sourcepub async fn export_async(
&mut self,
) -> Result<Key<SecretParts, UnspecifiedRole>>
pub async fn export_async( &mut self, ) -> Result<Key<SecretParts, UnspecifiedRole>>
Exports the secret key material.
Sourcepub fn change_password(&mut self, password: Option<&Password>) -> Result<()>
pub fn change_password(&mut self, password: Option<&Password>) -> Result<()>
Changes the key’s password.
Sourcepub async fn change_password_async(
&mut self,
password: Option<&Password>,
) -> Result<()>
pub async fn change_password_async( &mut self, password: Option<&Password>, ) -> Result<()>
Changes the key’s password.
Sourcepub fn delete_secret_key_material(&mut self) -> Result<()>
pub fn delete_secret_key_material(&mut self) -> Result<()>
Deletes the specified key’s secret key material.
On success, the key is no registered with the device, and future operations on the current key handle will fail.
Sourcepub async fn delete_secret_key_material_async(&mut self) -> Result<()>
pub async fn delete_secret_key_material_async(&mut self) -> Result<()>
Deletes the specified key’s secret key material.
On success, the key is no registered with the device, and future operations on the current key handle will fail.
Trait Implementations§
Source§impl Decryptor for &mut Key
impl Decryptor for &mut Key
Source§fn public(&self) -> &Key<PublicParts, UnspecifiedRole>
fn public(&self) -> &Key<PublicParts, UnspecifiedRole>
Source§fn decrypt(
&mut self,
ciphertext: &Ciphertext,
plaintext_len: Option<usize>,
) -> Result<SessionKey>
fn decrypt( &mut self, ciphertext: &Ciphertext, plaintext_len: Option<usize>, ) -> Result<SessionKey>
ciphertext, returning the plain session key.Source§impl Decryptor for Key
impl Decryptor for Key
Source§fn public(&self) -> &Key<PublicParts, UnspecifiedRole>
fn public(&self) -> &Key<PublicParts, UnspecifiedRole>
Source§fn decrypt(
&mut self,
ciphertext: &Ciphertext,
plaintext_len: Option<usize>,
) -> Result<SessionKey>
fn decrypt( &mut self, ciphertext: &Ciphertext, plaintext_len: Option<usize>, ) -> Result<SessionKey>
ciphertext, returning the plain session key.Source§impl Signer for &mut Key
impl Signer for &mut Key
Source§fn public(&self) -> &Key<PublicParts, UnspecifiedRole>
fn public(&self) -> &Key<PublicParts, UnspecifiedRole>
Source§fn sign(&mut self, hash_algo: HashAlgorithm, digest: &[u8]) -> Result<Signature>
fn sign(&mut self, hash_algo: HashAlgorithm, digest: &[u8]) -> Result<Signature>
digest produced by hash_algo.Source§fn acceptable_hashes(&self) -> &[HashAlgorithm]
fn acceptable_hashes(&self) -> &[HashAlgorithm]
Source§impl Signer for Key
impl Signer for Key
Source§fn public(&self) -> &Key<PublicParts, UnspecifiedRole>
fn public(&self) -> &Key<PublicParts, UnspecifiedRole>
Source§fn sign(&mut self, hash_algo: HashAlgorithm, digest: &[u8]) -> Result<Signature>
fn sign(&mut self, hash_algo: HashAlgorithm, digest: &[u8]) -> Result<Signature>
digest produced by hash_algo.