AnyKey

Type Alias AnyKey 

Source
pub type AnyKey = KeyT<dyn AnyKeyAlg + Send + Sync + RefUnwindSafe + UnwindSafe>;
Available on crate feature any_key only.
Expand description

The type-erased representation for a concrete key instance

Aliased Type§

pub struct AnyKey(/* private fields */);

Implementations§

Source§

impl AnyKey

Source

pub fn algorithm(&self) -> KeyAlg

Source

pub fn backend(&self) -> KeyBackend

Source

pub fn downcast_ref<K: AnyKeyAlg>(&self) -> Option<&K>

Source

pub fn key_type_id(&self) -> TypeId

Source

pub fn key_id(&self) -> Result<SecretBytes, Error>

Trait Implementations§

Source§

impl AnyKeyCreate for Box<AnyKey>

Source§

fn generate_with_rng(alg: KeyAlg, rng: impl KeyMaterial) -> Result<Self, Error>

Generate a new key from a key material generator for the given key algorithm.
Source§

fn generate_for_hardware(alg: KeyAlg) -> Result<Self, Error>

Generate a new key with an id for the given key algorithm.
Source§

fn get_with_id(alg: KeyAlg, id: &str) -> Result<Self, Error>

Get a key by id for hardware-based key
Source§

fn from_public_bytes(alg: KeyAlg, public: &[u8]) -> Result<Self, Error>

Load a public key from its byte representation
Source§

fn from_secret_bytes(alg: KeyAlg, secret: &[u8]) -> Result<Self, Error>

Load a secret key or keypair from its byte representation
Source§

fn from_key<K: HasKeyAlg + HasKeyBackend + Send + Sync + RefUnwindSafe + UnwindSafe + 'static>( key: K, ) -> Self

Convert from a concrete key instance
Source§

fn from_key_exchange<Sk, Pk>( alg: KeyAlg, secret: &Sk, public: &Pk, ) -> Result<Self, Error>
where Sk: KeyExchange<Pk> + ?Sized, Pk: ?Sized,

Create a new key instance from a key exchange
Source§

fn from_key_derivation( alg: KeyAlg, derive: impl KeyDerivation, ) -> Result<Self, Error>

Create a new key instance from a key derivation
Source§

fn convert_key(&self, alg: KeyAlg) -> Result<Self, Error>

Derive the corresponding key for the provided key algorithm
Source§

fn random(alg: KeyAlg) -> Result<Self, Error>

Available on crate feature getrandom only.
Generate a new random key for the given key algorithm.
Source§

fn random_det(alg: KeyAlg, seed: &[u8]) -> Result<Self, Error>

Generate a new random key for the given key algorithm.
Source§

impl FromJwk for Box<AnyKey>

Source§

fn from_jwk_parts(jwk: JwkParts<'_>) -> Result<Self, Error>

Import the key from a pre-parsed JWK
Source§

fn from_jwk(jwk: &str) -> Result<Self, Error>

Import the key from a JWK string reference
Source§

fn from_jwk_slice(jwk: &[u8]) -> Result<Self, Error>

Import the key from a JWK byte slice
Source§

impl KeyAeadInPlace for AnyKey

Source§

fn encrypt_in_place( &self, buffer: &mut dyn ResizeBuffer, nonce: &[u8], aad: &[u8], ) -> Result<usize, Error>

Encrypt a secret value in place, appending the verification tag and returning the length of the ciphertext
Source§

fn decrypt_in_place( &self, buffer: &mut dyn ResizeBuffer, nonce: &[u8], aad: &[u8], ) -> Result<(), Error>

Decrypt an encrypted (verification tag appended) value in place
Source§

fn aead_params(&self) -> KeyAeadParams

Get the nonce and tag length for encryption
Source§

fn aead_padding(&self, msg_len: usize) -> usize

Get the ciphertext padding required
Source§

impl KeyExchange for AnyKey

Source§

fn write_key_exchange( &self, other: &AnyKey, out: &mut dyn WriteBuffer, ) -> Result<(), Error>

Perform a key exchange, writing the result to the provided buffer.
Source§

fn key_exchange_bytes(&self, other: &Rhs) -> Result<SecretBytes, Error>

Available on crate feature alloc only.
Perform a key exchange and return a new allocated buffer.
Source§

impl KeySigVerify for AnyKey

Source§

fn verify_signature( &self, message: &[u8], signature: &[u8], sig_type: Option<SignatureType>, ) -> Result<bool, Error>

Check the validity of signature over a message with the specified signature type.
Source§

impl KeySign for AnyKey

Source§

fn write_signature( &self, message: &[u8], sig_type: Option<SignatureType>, out: &mut dyn WriteBuffer, ) -> Result<(), Error>

Create a signature of the requested type and write it to the provided buffer.
Source§

fn create_signature( &self, message: &[u8], sig_type: Option<SignatureType>, ) -> Result<SecretBytes, Error>

Available on crate feature alloc only.
Create a signature of the requested type and return an allocated buffer.
Source§

impl ToJwk for AnyKey

Source§

fn encode_jwk(&self, enc: &mut dyn JwkEncoder) -> Result<(), Error>

Write the JWK representation to an encoder
Source§

fn to_jwk_thumbprint(&self, alg: Option<KeyAlg>) -> Result<String, Error>

Available on crate feature alloc only.
Create the JWK thumbprint of the key
Source§

fn to_jwk_public(&self, alg: Option<KeyAlg>) -> Result<String, Error>

Available on crate feature alloc only.
Create a JWK of the public key
Source§

fn to_jwk_secret(&self, alg: Option<KeyAlg>) -> Result<SecretBytes, Error>

Available on crate feature alloc only.
Create a JWK of the secret key
Source§

impl ToPublicBytes for AnyKey

Source§

fn public_bytes_length(&self) -> Result<usize, Error>

Get the length of a public key
Source§

fn write_public_bytes(&self, out: &mut dyn WriteBuffer) -> Result<(), Error>

Write the key public bytes to a buffer.
Source§

fn to_public_bytes(&self) -> Result<SecretBytes, Error>

Available on crate feature alloc only.
Write the key public bytes to a new allocated buffer.
Source§

impl ToSecretBytes for AnyKey

Source§

fn secret_bytes_length(&self) -> Result<usize, Error>

Get the length of a secret key
Source§

fn write_secret_bytes(&self, out: &mut dyn WriteBuffer) -> Result<(), Error>

Write the key secret bytes to a buffer.
Source§

fn to_secret_bytes(&self) -> Result<SecretBytes, Error>

Available on crate feature alloc only.
Write the key secret bytes to a new allocated buffer.