Struct win_crypto_ng::asymmetric::AsymmetricKey
source · 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
impl AsymmetricKey
source§impl<A: Algorithm, P: Parts> AsymmetricKey<A, P>
impl<A: Algorithm, P: Parts> AsymmetricKey<A, P>
sourcepub fn id(&self) -> AsymmetricAlgorithmId
pub fn id(&self) -> AsymmetricAlgorithmId
Returns the asymmetric algorithm ID known at run-time.
source§impl<A: Algorithm> AsymmetricKey<A, Private>
impl<A: Algorithm> AsymmetricKey<A, Private>
sourcepub fn as_public(&self) -> &AsymmetricKey<A, Public>
pub fn as_public(&self) -> &AsymmetricKey<A, Public>
Views the key pair as having only public key parts.
source§impl AsymmetricKey<Rsa, Private>
impl AsymmetricKey<Rsa, Private>
sourcepub fn export_full(&self) -> Result<Box<Blob<RsaKeyFullPrivateBlob>>>
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>
impl AsymmetricKey<Rsa, Private>
pub fn import_from_parts( provider: &AsymmetricAlgorithm, parts: &RsaKeyPrivatePayload<'_> ) -> Result<Self>
source§impl AsymmetricKey<Rsa, Public>
impl AsymmetricKey<Rsa, Public>
pub fn import_from_parts( provider: &AsymmetricAlgorithm, parts: &RsaKeyPublicPayload<'_> ) -> Result<Self>
source§impl AsymmetricKey<Ecdsa<NistP256>, Private>
impl AsymmetricKey<Ecdsa<NistP256>, Private>
pub fn import_from_parts( provider: &AsymmetricAlgorithm, parts: &EccKeyPrivatePayload<'_> ) -> Result<Self>
source§impl AsymmetricKey<Ecdsa<NistP256>, Public>
impl AsymmetricKey<Ecdsa<NistP256>, Public>
pub fn import_from_parts( provider: &AsymmetricAlgorithm, parts: &EccKeyPublicPayload<'_> ) -> Result<Self>
source§impl AsymmetricKey<Ecdsa<NistP384>, Private>
impl AsymmetricKey<Ecdsa<NistP384>, Private>
pub fn import_from_parts( provider: &AsymmetricAlgorithm, parts: &EccKeyPrivatePayload<'_> ) -> Result<Self>
source§impl AsymmetricKey<Ecdsa<NistP384>, Public>
impl AsymmetricKey<Ecdsa<NistP384>, Public>
pub fn import_from_parts( provider: &AsymmetricAlgorithm, parts: &EccKeyPublicPayload<'_> ) -> Result<Self>
source§impl AsymmetricKey<Ecdsa<NistP521>, Private>
impl AsymmetricKey<Ecdsa<NistP521>, Private>
pub fn import_from_parts( provider: &AsymmetricAlgorithm, parts: &EccKeyPrivatePayload<'_> ) -> Result<Self>
source§impl AsymmetricKey<Ecdsa<NistP521>, Public>
impl AsymmetricKey<Ecdsa<NistP521>, Public>
pub fn import_from_parts( provider: &AsymmetricAlgorithm, parts: &EccKeyPublicPayload<'_> ) -> Result<Self>
source§impl AsymmetricKey<Ecdh<Curve25519>, Private>
impl AsymmetricKey<Ecdh<Curve25519>, Private>
pub fn import_from_parts( provider: &AsymmetricAlgorithm, private: &[u8] ) -> Result<Self>
source§impl AsymmetricKey<Ecdh<Curve25519>, Public>
impl AsymmetricKey<Ecdh<Curve25519>, Public>
pub fn import_from_parts( provider: &AsymmetricAlgorithm, public: &[u8] ) -> Result<Self>
source§impl AsymmetricKey<Ecdh<NistP256>, Private>
impl AsymmetricKey<Ecdh<NistP256>, Private>
pub fn import_from_parts( provider: &AsymmetricAlgorithm, parts: &EccKeyPrivatePayload<'_> ) -> Result<Self>
source§impl AsymmetricKey<Ecdh<NistP256>, Public>
impl AsymmetricKey<Ecdh<NistP256>, Public>
pub fn import_from_parts( provider: &AsymmetricAlgorithm, parts: &EccKeyPublicPayload<'_> ) -> Result<Self>
source§impl AsymmetricKey<Ecdh<NistP384>, Private>
impl AsymmetricKey<Ecdh<NistP384>, Private>
pub fn import_from_parts( provider: &AsymmetricAlgorithm, parts: &EccKeyPrivatePayload<'_> ) -> Result<Self>
source§impl AsymmetricKey<Ecdh<NistP384>, Public>
impl AsymmetricKey<Ecdh<NistP384>, Public>
pub fn import_from_parts( provider: &AsymmetricAlgorithm, parts: &EccKeyPublicPayload<'_> ) -> Result<Self>
source§impl AsymmetricKey<Ecdh<NistP521>, Private>
impl AsymmetricKey<Ecdh<NistP521>, Private>
pub fn import_from_parts( provider: &AsymmetricAlgorithm, parts: &EccKeyPrivatePayload<'_> ) -> Result<Self>
source§impl AsymmetricKey<Ecdh<NistP521>, Public>
impl AsymmetricKey<Ecdh<NistP521>, Public>
pub fn import_from_parts( provider: &AsymmetricAlgorithm, parts: &EccKeyPublicPayload<'_> ) -> Result<Self>
source§impl<P: Parts> AsymmetricKey<Rsa, P>
impl<P: Parts> AsymmetricKey<Rsa, P>
Trait Implementations§
source§impl<'a> Export<AsymmetricAlgorithmId, Private> for AsymmetricKey<AsymmetricAlgorithmId, Private>
impl<'a> Export<AsymmetricAlgorithmId, Private> for AsymmetricKey<AsymmetricAlgorithmId, Private>
source§impl<'a> Export<AsymmetricAlgorithmId, Public> for AsymmetricKey<AsymmetricAlgorithmId, Public>
impl<'a> Export<AsymmetricAlgorithmId, Public> for AsymmetricKey<AsymmetricAlgorithmId, Public>
source§impl<'a> Export<Ecdh<Curve25519>, Private> for AsymmetricKey<Ecdh<Curve25519>, Private>
impl<'a> Export<Ecdh<Curve25519>, Private> for AsymmetricKey<Ecdh<Curve25519>, Private>
source§impl<'a> Export<Ecdh<Curve25519>, Public> for AsymmetricKey<Ecdh<Curve25519>, Public>
impl<'a> Export<Ecdh<Curve25519>, Public> for AsymmetricKey<Ecdh<Curve25519>, Public>
source§impl<'a> Import<'a, AsymmetricAlgorithmId, Private> for AsymmetricKey<AsymmetricAlgorithmId, Private>
impl<'a> Import<'a, AsymmetricAlgorithmId, Private> for AsymmetricKey<AsymmetricAlgorithmId, Private>
type Blob = &'a Blob<ErasedKeyBlob>
fn import( algo: A, provider: &AsymmetricAlgorithm, blob: Self::Blob ) -> Result<AsymmetricKey<A, P>>
source§impl<'a> Import<'a, AsymmetricAlgorithmId, Public> for AsymmetricKey<AsymmetricAlgorithmId, Public>
impl<'a> Import<'a, AsymmetricAlgorithmId, Public> for AsymmetricKey<AsymmetricAlgorithmId, Public>
type Blob = &'a Blob<ErasedKeyBlob>
fn import( algo: A, provider: &AsymmetricAlgorithm, blob: Self::Blob ) -> Result<AsymmetricKey<A, P>>
source§impl<'a> Import<'a, Dh, Private> for AsymmetricKey<Dh, Private>
impl<'a> Import<'a, Dh, Private> for AsymmetricKey<Dh, Private>
type Blob = &'a Blob<DhKeyPrivateBlob>
fn import( algo: A, provider: &AsymmetricAlgorithm, blob: Self::Blob ) -> Result<AsymmetricKey<A, P>>
source§impl<'a> Import<'a, Dh, Public> for AsymmetricKey<Dh, Public>
impl<'a> Import<'a, Dh, Public> for AsymmetricKey<Dh, Public>
type Blob = &'a Blob<DhKeyPublicBlob>
fn import( algo: A, provider: &AsymmetricAlgorithm, blob: Self::Blob ) -> Result<AsymmetricKey<A, P>>
source§impl<'a> Import<'a, Dsa, Private> for AsymmetricKey<Dsa, Private>
impl<'a> Import<'a, Dsa, Private> for AsymmetricKey<Dsa, Private>
type Blob = DsaPrivateBlob
fn import( algo: A, provider: &AsymmetricAlgorithm, blob: Self::Blob ) -> Result<AsymmetricKey<A, P>>
source§impl<'a> Import<'a, Dsa, Public> for AsymmetricKey<Dsa, Public>
impl<'a> Import<'a, Dsa, Public> for AsymmetricKey<Dsa, Public>
type Blob = DsaPublicBlob
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>
impl<'a> Import<'a, Ecdh<Curve25519>, Private> for AsymmetricKey<Ecdh<Curve25519>, Private>
type Blob = &'a Blob<EccKeyPrivateBlob>
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>
impl<'a> Import<'a, Ecdh<Curve25519>, Public> for AsymmetricKey<Ecdh<Curve25519>, Public>
type Blob = &'a Blob<EccKeyPublicBlob>
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>
impl<'a> Import<'a, Ecdh<NistP256>, Private> for AsymmetricKey<Ecdh<NistP256>, Private>
type Blob = &'a Blob<EccKeyPrivateBlob>
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>
impl<'a> Import<'a, Ecdh<NistP256>, Public> for AsymmetricKey<Ecdh<NistP256>, Public>
type Blob = &'a Blob<EccKeyPublicBlob>
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>
impl<'a> Import<'a, Ecdh<NistP384>, Private> for AsymmetricKey<Ecdh<NistP384>, Private>
type Blob = &'a Blob<EccKeyPrivateBlob>
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>
impl<'a> Import<'a, Ecdh<NistP384>, Public> for AsymmetricKey<Ecdh<NistP384>, Public>
type Blob = &'a Blob<EccKeyPublicBlob>
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>
impl<'a> Import<'a, Ecdh<NistP521>, Private> for AsymmetricKey<Ecdh<NistP521>, Private>
type Blob = &'a Blob<EccKeyPrivateBlob>
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>
impl<'a> Import<'a, Ecdh<NistP521>, Public> for AsymmetricKey<Ecdh<NistP521>, Public>
type Blob = &'a Blob<EccKeyPublicBlob>
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>
impl<'a> Import<'a, Ecdsa<NistP256>, Private> for AsymmetricKey<Ecdsa<NistP256>, Private>
type Blob = &'a Blob<EccKeyPrivateBlob>
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>
impl<'a> Import<'a, Ecdsa<NistP256>, Public> for AsymmetricKey<Ecdsa<NistP256>, Public>
type Blob = &'a Blob<EccKeyPublicBlob>
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>
impl<'a> Import<'a, Ecdsa<NistP384>, Private> for AsymmetricKey<Ecdsa<NistP384>, Private>
type Blob = &'a Blob<EccKeyPrivateBlob>
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>
impl<'a> Import<'a, Ecdsa<NistP384>, Public> for AsymmetricKey<Ecdsa<NistP384>, Public>
type Blob = &'a Blob<EccKeyPublicBlob>
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>
impl<'a> Import<'a, Ecdsa<NistP521>, Private> for AsymmetricKey<Ecdsa<NistP521>, Private>
type Blob = &'a Blob<EccKeyPrivateBlob>
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>
impl<'a> Import<'a, Ecdsa<NistP521>, Public> for AsymmetricKey<Ecdsa<NistP521>, Public>
type Blob = &'a Blob<EccKeyPublicBlob>
fn import( algo: A, provider: &AsymmetricAlgorithm, blob: Self::Blob ) -> Result<AsymmetricKey<A, P>>
source§impl<'a> Import<'a, Rsa, Private> for AsymmetricKey<Rsa, Private>
impl<'a> Import<'a, Rsa, Private> for AsymmetricKey<Rsa, Private>
type Blob = &'a Blob<RsaKeyPrivateBlob>
fn import( algo: A, provider: &AsymmetricAlgorithm, blob: Self::Blob ) -> Result<AsymmetricKey<A, P>>
source§impl<'a> Import<'a, Rsa, Public> for AsymmetricKey<Rsa, Public>
impl<'a> Import<'a, Rsa, Public> for AsymmetricKey<Rsa, Public>
type Blob = &'a Blob<RsaKeyPublicBlob>
fn import( algo: A, provider: &AsymmetricAlgorithm, blob: Self::Blob ) -> Result<AsymmetricKey<A, P>>
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> 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
Mutably borrows from an owned value. Read more