pub struct AsymmetricKey<A: Algorithm = AsymmetricAlgorithmId, P: Parts = Public>(_, _, _);
Expand description

Asymmetric key handle.

Can be specified as that of which type is known at run-time (erased) or with a concrete algorithm parameter.

Type-safety

At the time of writing, all of the relevant crypto operations are implemented for only keys whose algorithm is statically known. This means that the keys using the dynamic AsymmetricAlgorithmId need to be re-imported in order to statically verify the algorithm used.

use win_crypto_ng::asymmetric::{AsymmetricAlgorithm, AsymmetricAlgorithmId, AsymmetricKey};
use win_crypto_ng::asymmetric::{Rsa, Private, Import, Export};

let dynamic: AsymmetricKey<AsymmetricAlgorithmId, Private> =
    AsymmetricKey::builder(AsymmetricAlgorithmId::Rsa).key_bits(512).build().unwrap();
let dynamic_blob = dynamic.export().unwrap();

let provider = AsymmetricAlgorithm::open(AsymmetricAlgorithmId::Rsa).unwrap();
let rsa_blob = dynamic_blob.try_into().unwrap_or_else(|_| panic!());
let rsa_key = AsymmetricKey::<Rsa, Private>::import(Rsa, &provider, &rsa_blob).unwrap();
// Can now additional impls for `AsymmetricKey<Rsa, Private>`, e.g.
// rsa_key.decrypt(..);

Generation

use win_crypto_ng::asymmetric::{AsymmetricAlgorithm, AsymmetricAlgorithmId, AsymmetricKey};
use win_crypto_ng::asymmetric::{Rsa, Private};

// Handle to an asymmetric key whose algorithm ID is known at run-time
let handle: AsymmetricKey<AsymmetricAlgorithmId, Private> =
    AsymmetricKey::builder(AsymmetricAlgorithmId::Rsa).key_bits(512).build().unwrap();

// Handle to an asymmetric key whose algorithm is known to be RSA
let handle: AsymmetricKey<Rsa, Private> =
    AsymmetricKey::builder(Rsa).key_bits(512).build().unwrap();

Implementations§

source§

impl AsymmetricKey

source

pub fn builder<B: Algorithm>(algorithm: B) -> Builder<B>

Create a type-safe builder capable of generating asymmetric keys.

source§

impl<A: Algorithm, P: Parts> AsymmetricKey<A, P>

source

pub fn id(&self) -> AsymmetricAlgorithmId

Returns the asymmetric algorithm ID known at run-time.

source§

impl<A: Algorithm> AsymmetricKey<A, Private>

source

pub fn as_public(&self) -> &AsymmetricKey<A, Public>

Views the key pair as having only public key parts.

source§

impl AsymmetricKey<Rsa, Private>

source

pub fn export_full(&self) -> Result<Box<Blob<RsaKeyFullPrivateBlob>>>

Export the RSA key to “full” raw data format. Additionally includes coefficient and (private) exponents.

source§

impl AsymmetricKey<Rsa, Private>

source

pub fn import_from_parts( provider: &AsymmetricAlgorithm, parts: &RsaKeyPrivatePayload<'_> ) -> Result<Self>

source§

impl AsymmetricKey<Rsa, Public>

source

pub fn import_from_parts( provider: &AsymmetricAlgorithm, parts: &RsaKeyPublicPayload<'_> ) -> Result<Self>

source§

impl AsymmetricKey<Ecdsa<NistP256>, Private>

source

pub fn import_from_parts( provider: &AsymmetricAlgorithm, parts: &EccKeyPrivatePayload<'_> ) -> Result<Self>

source§

impl AsymmetricKey<Ecdsa<NistP256>, Public>

source

pub fn import_from_parts( provider: &AsymmetricAlgorithm, parts: &EccKeyPublicPayload<'_> ) -> Result<Self>

source§

impl AsymmetricKey<Ecdsa<NistP384>, Private>

source

pub fn import_from_parts( provider: &AsymmetricAlgorithm, parts: &EccKeyPrivatePayload<'_> ) -> Result<Self>

source§

impl AsymmetricKey<Ecdsa<NistP384>, Public>

source

pub fn import_from_parts( provider: &AsymmetricAlgorithm, parts: &EccKeyPublicPayload<'_> ) -> Result<Self>

source§

impl AsymmetricKey<Ecdsa<NistP521>, Private>

source

pub fn import_from_parts( provider: &AsymmetricAlgorithm, parts: &EccKeyPrivatePayload<'_> ) -> Result<Self>

source§

impl AsymmetricKey<Ecdsa<NistP521>, Public>

source

pub fn import_from_parts( provider: &AsymmetricAlgorithm, parts: &EccKeyPublicPayload<'_> ) -> Result<Self>

source§

impl AsymmetricKey<Ecdh<Curve25519>, Private>

source

pub fn import_from_parts( provider: &AsymmetricAlgorithm, private: &[u8] ) -> Result<Self>

source§

impl AsymmetricKey<Ecdh<Curve25519>, Public>

source

pub fn import_from_parts( provider: &AsymmetricAlgorithm, public: &[u8] ) -> Result<Self>

source§

impl AsymmetricKey<Ecdh<NistP256>, Private>

source

pub fn import_from_parts( provider: &AsymmetricAlgorithm, parts: &EccKeyPrivatePayload<'_> ) -> Result<Self>

source§

impl AsymmetricKey<Ecdh<NistP256>, Public>

source

pub fn import_from_parts( provider: &AsymmetricAlgorithm, parts: &EccKeyPublicPayload<'_> ) -> Result<Self>

source§

impl AsymmetricKey<Ecdh<NistP384>, Private>

source

pub fn import_from_parts( provider: &AsymmetricAlgorithm, parts: &EccKeyPrivatePayload<'_> ) -> Result<Self>

source§

impl AsymmetricKey<Ecdh<NistP384>, Public>

source

pub fn import_from_parts( provider: &AsymmetricAlgorithm, parts: &EccKeyPublicPayload<'_> ) -> Result<Self>

source§

impl AsymmetricKey<Ecdh<NistP521>, Private>

source

pub fn import_from_parts( provider: &AsymmetricAlgorithm, parts: &EccKeyPrivatePayload<'_> ) -> Result<Self>

source§

impl AsymmetricKey<Ecdh<NistP521>, Public>

source

pub fn import_from_parts( provider: &AsymmetricAlgorithm, parts: &EccKeyPublicPayload<'_> ) -> Result<Self>

source§

impl<P: Parts> AsymmetricKey<Rsa, P>

source

pub fn encrypt( &self, padding: Option<EncryptionPadding>, data: &[u8] ) -> Result<Box<[u8]>>

Encrypt a message using the RSA key.

source§

impl AsymmetricKey<Rsa, Private>

source

pub fn decrypt( &self, padding: Option<EncryptionPadding>, data: &[u8] ) -> Result<Box<[u8]>>

Decrypt a message using the RSA key.

Trait Implementations§

source§

impl<'a> Export<AsymmetricAlgorithmId, Private> for AsymmetricKey<AsymmetricAlgorithmId, Private>

§

type Blob = ErasedKeyBlob

source§

fn export(&self) -> Result<Box<Blob<Self::Blob>>>

source§

impl<'a> Export<AsymmetricAlgorithmId, Public> for AsymmetricKey<AsymmetricAlgorithmId, Public>

§

type Blob = ErasedKeyBlob

source§

fn export(&self) -> Result<Box<Blob<Self::Blob>>>

source§

impl<'a> Export<Dh, Private> for AsymmetricKey<Dh, Private>

source§

impl<'a> Export<Dh, Public> for AsymmetricKey<Dh, Public>

source§

impl<'a> Export<Dsa, Private> for AsymmetricKey<Dsa, Private>

source§

impl<'a> Export<Dsa, Public> for AsymmetricKey<Dsa, Public>

source§

impl<'a> Export<Ecdh<Curve25519>, Private> for AsymmetricKey<Ecdh<Curve25519>, Private>

source§

impl<'a> Export<Ecdh<Curve25519>, Public> for AsymmetricKey<Ecdh<Curve25519>, Public>

source§

impl<'a> Export<Ecdh<NistP256>, Private> for AsymmetricKey<Ecdh<NistP256>, Private>

source§

impl<'a> Export<Ecdh<NistP256>, Public> for AsymmetricKey<Ecdh<NistP256>, Public>

source§

impl<'a> Export<Ecdh<NistP384>, Private> for AsymmetricKey<Ecdh<NistP384>, Private>

source§

impl<'a> Export<Ecdh<NistP384>, Public> for AsymmetricKey<Ecdh<NistP384>, Public>

source§

impl<'a> Export<Ecdh<NistP521>, Private> for AsymmetricKey<Ecdh<NistP521>, Private>

source§

impl<'a> Export<Ecdh<NistP521>, Public> for AsymmetricKey<Ecdh<NistP521>, Public>

source§

impl<'a> Export<Ecdsa<NistP256>, Private> for AsymmetricKey<Ecdsa<NistP256>, Private>

source§

impl<'a> Export<Ecdsa<NistP256>, Public> for AsymmetricKey<Ecdsa<NistP256>, Public>

source§

impl<'a> Export<Ecdsa<NistP384>, Private> for AsymmetricKey<Ecdsa<NistP384>, Private>

source§

impl<'a> Export<Ecdsa<NistP384>, Public> for AsymmetricKey<Ecdsa<NistP384>, Public>

source§

impl<'a> Export<Ecdsa<NistP521>, Private> for AsymmetricKey<Ecdsa<NistP521>, Private>

source§

impl<'a> Export<Ecdsa<NistP521>, Public> for AsymmetricKey<Ecdsa<NistP521>, Public>

source§

impl<'a> Export<Rsa, Private> for AsymmetricKey<Rsa, Private>

source§

impl<'a> Export<Rsa, Public> for AsymmetricKey<Rsa, Public>

source§

impl<'a> Import<'a, AsymmetricAlgorithmId, Private> for AsymmetricKey<AsymmetricAlgorithmId, Private>

§

type Blob = &'a Blob<ErasedKeyBlob>

source§

fn import( algo: A, provider: &AsymmetricAlgorithm, blob: Self::Blob ) -> Result<AsymmetricKey<A, P>>

source§

impl<'a> Import<'a, AsymmetricAlgorithmId, Public> for AsymmetricKey<AsymmetricAlgorithmId, Public>

§

type Blob = &'a Blob<ErasedKeyBlob>

source§

fn import( algo: A, provider: &AsymmetricAlgorithm, blob: Self::Blob ) -> Result<AsymmetricKey<A, P>>

source§

impl<'a> Import<'a, Dh, Private> for AsymmetricKey<Dh, Private>

§

type Blob = &'a Blob<DhKeyPrivateBlob>

source§

fn import( algo: A, provider: &AsymmetricAlgorithm, blob: Self::Blob ) -> Result<AsymmetricKey<A, P>>

source§

impl<'a> Import<'a, Dh, Public> for AsymmetricKey<Dh, Public>

§

type Blob = &'a Blob<DhKeyPublicBlob>

source§

fn import( algo: A, provider: &AsymmetricAlgorithm, blob: Self::Blob ) -> Result<AsymmetricKey<A, P>>

source§

impl<'a> Import<'a, Dsa, Private> for AsymmetricKey<Dsa, Private>

§

type Blob = DsaPrivateBlob

source§

fn import( algo: A, provider: &AsymmetricAlgorithm, blob: Self::Blob ) -> Result<AsymmetricKey<A, P>>

source§

impl<'a> Import<'a, Dsa, Public> for AsymmetricKey<Dsa, Public>

§

type Blob = DsaPublicBlob

source§

fn import( algo: A, provider: &AsymmetricAlgorithm, blob: Self::Blob ) -> Result<AsymmetricKey<A, P>>

source§

impl<'a> Import<'a, Ecdh<Curve25519>, Private> for AsymmetricKey<Ecdh<Curve25519>, Private>

§

type Blob = &'a Blob<EccKeyPrivateBlob>

source§

fn import( algo: A, provider: &AsymmetricAlgorithm, blob: Self::Blob ) -> Result<AsymmetricKey<A, P>>

source§

impl<'a> Import<'a, Ecdh<Curve25519>, Public> for AsymmetricKey<Ecdh<Curve25519>, Public>

§

type Blob = &'a Blob<EccKeyPublicBlob>

source§

fn import( algo: A, provider: &AsymmetricAlgorithm, blob: Self::Blob ) -> Result<AsymmetricKey<A, P>>

source§

impl<'a> Import<'a, Ecdh<NistP256>, Private> for AsymmetricKey<Ecdh<NistP256>, Private>

§

type Blob = &'a Blob<EccKeyPrivateBlob>

source§

fn import( algo: A, provider: &AsymmetricAlgorithm, blob: Self::Blob ) -> Result<AsymmetricKey<A, P>>

source§

impl<'a> Import<'a, Ecdh<NistP256>, Public> for AsymmetricKey<Ecdh<NistP256>, Public>

§

type Blob = &'a Blob<EccKeyPublicBlob>

source§

fn import( algo: A, provider: &AsymmetricAlgorithm, blob: Self::Blob ) -> Result<AsymmetricKey<A, P>>

source§

impl<'a> Import<'a, Ecdh<NistP384>, Private> for AsymmetricKey<Ecdh<NistP384>, Private>

§

type Blob = &'a Blob<EccKeyPrivateBlob>

source§

fn import( algo: A, provider: &AsymmetricAlgorithm, blob: Self::Blob ) -> Result<AsymmetricKey<A, P>>

source§

impl<'a> Import<'a, Ecdh<NistP384>, Public> for AsymmetricKey<Ecdh<NistP384>, Public>

§

type Blob = &'a Blob<EccKeyPublicBlob>

source§

fn import( algo: A, provider: &AsymmetricAlgorithm, blob: Self::Blob ) -> Result<AsymmetricKey<A, P>>

source§

impl<'a> Import<'a, Ecdh<NistP521>, Private> for AsymmetricKey<Ecdh<NistP521>, Private>

§

type Blob = &'a Blob<EccKeyPrivateBlob>

source§

fn import( algo: A, provider: &AsymmetricAlgorithm, blob: Self::Blob ) -> Result<AsymmetricKey<A, P>>

source§

impl<'a> Import<'a, Ecdh<NistP521>, Public> for AsymmetricKey<Ecdh<NistP521>, Public>

§

type Blob = &'a Blob<EccKeyPublicBlob>

source§

fn import( algo: A, provider: &AsymmetricAlgorithm, blob: Self::Blob ) -> Result<AsymmetricKey<A, P>>

source§

impl<'a> Import<'a, Ecdsa<NistP256>, Private> for AsymmetricKey<Ecdsa<NistP256>, Private>

§

type Blob = &'a Blob<EccKeyPrivateBlob>

source§

fn import( algo: A, provider: &AsymmetricAlgorithm, blob: Self::Blob ) -> Result<AsymmetricKey<A, P>>

source§

impl<'a> Import<'a, Ecdsa<NistP256>, Public> for AsymmetricKey<Ecdsa<NistP256>, Public>

§

type Blob = &'a Blob<EccKeyPublicBlob>

source§

fn import( algo: A, provider: &AsymmetricAlgorithm, blob: Self::Blob ) -> Result<AsymmetricKey<A, P>>

source§

impl<'a> Import<'a, Ecdsa<NistP384>, Private> for AsymmetricKey<Ecdsa<NistP384>, Private>

§

type Blob = &'a Blob<EccKeyPrivateBlob>

source§

fn import( algo: A, provider: &AsymmetricAlgorithm, blob: Self::Blob ) -> Result<AsymmetricKey<A, P>>

source§

impl<'a> Import<'a, Ecdsa<NistP384>, Public> for AsymmetricKey<Ecdsa<NistP384>, Public>

§

type Blob = &'a Blob<EccKeyPublicBlob>

source§

fn import( algo: A, provider: &AsymmetricAlgorithm, blob: Self::Blob ) -> Result<AsymmetricKey<A, P>>

source§

impl<'a> Import<'a, Ecdsa<NistP521>, Private> for AsymmetricKey<Ecdsa<NistP521>, Private>

§

type Blob = &'a Blob<EccKeyPrivateBlob>

source§

fn import( algo: A, provider: &AsymmetricAlgorithm, blob: Self::Blob ) -> Result<AsymmetricKey<A, P>>

source§

impl<'a> Import<'a, Ecdsa<NistP521>, Public> for AsymmetricKey<Ecdsa<NistP521>, Public>

§

type Blob = &'a Blob<EccKeyPublicBlob>

source§

fn import( algo: A, provider: &AsymmetricAlgorithm, blob: Self::Blob ) -> Result<AsymmetricKey<A, P>>

source§

impl<'a> Import<'a, Rsa, Private> for AsymmetricKey<Rsa, Private>

§

type Blob = &'a Blob<RsaKeyPrivateBlob>

source§

fn import( algo: A, provider: &AsymmetricAlgorithm, blob: Self::Blob ) -> Result<AsymmetricKey<A, P>>

source§

impl<'a> Import<'a, Rsa, Public> for AsymmetricKey<Rsa, Public>

§

type Blob = &'a Blob<RsaKeyPublicBlob>

source§

fn import( algo: A, provider: &AsymmetricAlgorithm, blob: Self::Blob ) -> Result<AsymmetricKey<A, P>>

source§

impl Signer for AsymmetricKey<Dsa, Private>

source§

fn sign( &self, input: &[u8], padding: Option<SignaturePadding> ) -> Result<Box<[u8]>>

source§

impl Signer for AsymmetricKey<Ecdsa<NistP256>, Private>

source§

fn sign( &self, input: &[u8], padding: Option<SignaturePadding> ) -> Result<Box<[u8]>>

source§

impl Signer for AsymmetricKey<Ecdsa<NistP384>, Private>

source§

fn sign( &self, input: &[u8], padding: Option<SignaturePadding> ) -> Result<Box<[u8]>>

source§

impl Signer for AsymmetricKey<Ecdsa<NistP521>, Private>

source§

fn sign( &self, input: &[u8], padding: Option<SignaturePadding> ) -> Result<Box<[u8]>>

source§

impl Signer for AsymmetricKey<Rsa, Private>

source§

fn sign( &self, input: &[u8], padding: Option<SignaturePadding> ) -> Result<Box<[u8]>>

source§

impl Verifier for AsymmetricKey<Dsa, Private>

source§

fn verify( &self, hash: &[u8], signature: &[u8], padding: Option<SignaturePadding> ) -> Result<()>

source§

impl Verifier for AsymmetricKey<Dsa, Public>

source§

fn verify( &self, hash: &[u8], signature: &[u8], padding: Option<SignaturePadding> ) -> Result<()>

source§

impl Verifier for AsymmetricKey<Ecdsa<NistP256>, Private>

source§

fn verify( &self, hash: &[u8], signature: &[u8], padding: Option<SignaturePadding> ) -> Result<()>

source§

impl Verifier for AsymmetricKey<Ecdsa<NistP256>, Public>

source§

fn verify( &self, hash: &[u8], signature: &[u8], padding: Option<SignaturePadding> ) -> Result<()>

source§

impl Verifier for AsymmetricKey<Ecdsa<NistP384>, Private>

source§

fn verify( &self, hash: &[u8], signature: &[u8], padding: Option<SignaturePadding> ) -> Result<()>

source§

impl Verifier for AsymmetricKey<Ecdsa<NistP384>, Public>

source§

fn verify( &self, hash: &[u8], signature: &[u8], padding: Option<SignaturePadding> ) -> Result<()>

source§

impl Verifier for AsymmetricKey<Ecdsa<NistP521>, Private>

source§

fn verify( &self, hash: &[u8], signature: &[u8], padding: Option<SignaturePadding> ) -> Result<()>

source§

impl Verifier for AsymmetricKey<Ecdsa<NistP521>, Public>

source§

fn verify( &self, hash: &[u8], signature: &[u8], padding: Option<SignaturePadding> ) -> Result<()>

source§

impl Verifier for AsymmetricKey<Rsa, Private>

source§

fn verify( &self, hash: &[u8], signature: &[u8], padding: Option<SignaturePadding> ) -> Result<()>

source§

impl Verifier for AsymmetricKey<Rsa, Public>

source§

fn verify( &self, hash: &[u8], signature: &[u8], padding: Option<SignaturePadding> ) -> Result<()>

Auto Trait Implementations§

§

impl<A, P> RefUnwindSafe for AsymmetricKey<A, P>where A: RefUnwindSafe, P: RefUnwindSafe,

§

impl<A, P> Send for AsymmetricKey<A, P>where A: Send, P: Send,

§

impl<A = AsymmetricAlgorithmId, P = Public> !Sync for AsymmetricKey<A, P>

§

impl<A, P> Unpin for AsymmetricKey<A, P>where A: Unpin, P: Unpin,

§

impl<A, P> UnwindSafe for AsymmetricKey<A, P>where A: UnwindSafe, P: UnwindSafe,

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, 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.