pub struct LocalKey { /* private fields */ }Expand description
A stored key entry
Implementations§
Source§impl LocalKey
impl LocalKey
Sourcepub fn generate_with_rng(alg: KeyAlg, ephemeral: bool) -> Result<Self, Error>
pub fn generate_with_rng(alg: KeyAlg, ephemeral: bool) -> Result<Self, Error>
Create a new random key or keypair
Sourcepub fn generate_for_hardware(
alg: KeyAlg,
ephemeral: bool,
) -> Result<Self, Error>
pub fn generate_for_hardware( alg: KeyAlg, ephemeral: bool, ) -> Result<Self, Error>
Create a new random keypair backed by hardware
Sourcepub fn from_seed(
alg: KeyAlg,
seed: &[u8],
method: Option<&str>,
) -> Result<Self, Error>
pub fn from_seed( alg: KeyAlg, seed: &[u8], method: Option<&str>, ) -> Result<Self, Error>
Create a new deterministic key or keypair
Sourcepub fn from_jwk_slice(jwk: &[u8]) -> Result<Self, Error>
pub fn from_jwk_slice(jwk: &[u8]) -> Result<Self, Error>
Import a key or keypair from a JWK in binary format
Sourcepub fn from_public_bytes(alg: KeyAlg, public: &[u8]) -> Result<Self, Error>
pub fn from_public_bytes(alg: KeyAlg, public: &[u8]) -> Result<Self, Error>
Import a public key from its compact representation
Sourcepub fn to_public_bytes(&self) -> Result<SecretBytes, Error>
pub fn to_public_bytes(&self) -> Result<SecretBytes, Error>
Export the raw bytes of the public key
Sourcepub fn from_secret_bytes(alg: KeyAlg, secret: &[u8]) -> Result<Self, Error>
pub fn from_secret_bytes(alg: KeyAlg, secret: &[u8]) -> Result<Self, Error>
Import a symmetric key or public-private keypair from its compact representation
Sourcepub fn to_secret_bytes(&self) -> Result<SecretBytes, Error>
pub fn to_secret_bytes(&self) -> Result<SecretBytes, Error>
Export the raw bytes of the private key
Sourcepub fn to_key_exchange(&self, alg: KeyAlg, pk: &LocalKey) -> Result<Self, Error>
pub fn to_key_exchange(&self, alg: KeyAlg, pk: &LocalKey) -> Result<Self, Error>
Derive a new key from a Diffie-Hellman exchange between this keypair and a public key
Sourcepub fn to_jwk_public(&self, alg: Option<KeyAlg>) -> Result<String, Error>
pub fn to_jwk_public(&self, alg: Option<KeyAlg>) -> Result<String, Error>
Get the public JWK representation for this key or keypair
Sourcepub fn to_jwk_secret(&self) -> Result<SecretBytes, Error>
pub fn to_jwk_secret(&self) -> Result<SecretBytes, Error>
Get the JWK representation for this private key or keypair
Sourcepub fn to_jwk_thumbprint(&self, alg: Option<KeyAlg>) -> Result<String, Error>
pub fn to_jwk_thumbprint(&self, alg: Option<KeyAlg>) -> Result<String, Error>
Get the JWK thumbprint for this key or keypair
Sourcepub fn to_jwk_thumbprints(&self) -> Result<Vec<String>, Error>
pub fn to_jwk_thumbprints(&self) -> Result<Vec<String>, Error>
Get the set of indexed JWK thumbprints for this key or keypair
Sourcepub fn convert_key(&self, alg: KeyAlg) -> Result<Self, Error>
pub fn convert_key(&self, alg: KeyAlg) -> Result<Self, Error>
Map this key or keypair to its equivalent for another key algorithm
Sourcepub fn aead_params(&self) -> Result<KeyAeadParams, Error>
pub fn aead_params(&self) -> Result<KeyAeadParams, Error>
Fetch the AEAD parameter lengths
Sourcepub fn aead_padding(&self, msg_len: usize) -> usize
pub fn aead_padding(&self, msg_len: usize) -> usize
Calculate the padding required for a message
Sourcepub fn aead_random_nonce(&self) -> Result<Vec<u8>, Error>
pub fn aead_random_nonce(&self) -> Result<Vec<u8>, Error>
Create a new random nonce for AEAD message encryption
Sourcepub fn aead_encrypt(
&self,
message: &[u8],
nonce: &[u8],
aad: &[u8],
) -> Result<Encrypted, Error>
pub fn aead_encrypt( &self, message: &[u8], nonce: &[u8], aad: &[u8], ) -> Result<Encrypted, Error>
Perform AEAD message encryption with this encryption key
Sourcepub fn aead_decrypt<'d>(
&'d self,
ciphertext: impl Into<ToDecrypt<'d>>,
nonce: &[u8],
aad: &[u8],
) -> Result<SecretBytes, Error>
pub fn aead_decrypt<'d>( &'d self, ciphertext: impl Into<ToDecrypt<'d>>, nonce: &[u8], aad: &[u8], ) -> Result<SecretBytes, Error>
Perform AEAD message decryption with this encryption key
Sourcepub fn sign_message(
&self,
message: &[u8],
sig_type: Option<&str>,
) -> Result<Vec<u8>, Error>
pub fn sign_message( &self, message: &[u8], sig_type: Option<&str>, ) -> Result<Vec<u8>, Error>
Sign a message with this private signing key
Sourcepub fn verify_signature(
&self,
message: &[u8],
signature: &[u8],
sig_type: Option<&str>,
) -> Result<bool, Error>
pub fn verify_signature( &self, message: &[u8], signature: &[u8], sig_type: Option<&str>, ) -> Result<bool, Error>
Verify a message signature with this private signing key or public verification key
Sourcepub fn wrap_key(&self, key: &LocalKey, nonce: &[u8]) -> Result<Encrypted, Error>
pub fn wrap_key(&self, key: &LocalKey, nonce: &[u8]) -> Result<Encrypted, Error>
Wrap another key using this key
Sourcepub fn unwrap_key<'d>(
&'d self,
alg: KeyAlg,
ciphertext: impl Into<ToDecrypt<'d>>,
nonce: &[u8],
) -> Result<LocalKey, Error>
pub fn unwrap_key<'d>( &'d self, alg: KeyAlg, ciphertext: impl Into<ToDecrypt<'d>>, nonce: &[u8], ) -> Result<LocalKey, Error>
Unwrap a key using this key
Sourcepub fn is_hardware_backed(&self) -> bool
pub fn is_hardware_backed(&self) -> bool
Check whether the key is hardware backed by checking the type id of the underlying structure
Trait Implementations§
Source§impl KeyExchange for LocalKey
impl KeyExchange for LocalKey
Source§fn write_key_exchange(
&self,
other: &LocalKey,
out: &mut dyn WriteBuffer,
) -> Result<(), CryptoError>
fn write_key_exchange( &self, other: &LocalKey, out: &mut dyn WriteBuffer, ) -> Result<(), CryptoError>
Source§fn key_exchange_bytes(&self, other: &Rhs) -> Result<SecretBytes, Error>
fn key_exchange_bytes(&self, other: &Rhs) -> Result<SecretBytes, Error>
Auto Trait Implementations§
impl Freeze for LocalKey
impl RefUnwindSafe for LocalKey
impl Send for LocalKey
impl Sync for LocalKey
impl Unpin for LocalKey
impl UnwindSafe for LocalKey
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> 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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more