Skip to main content

PrivateKey

Enum PrivateKey 

Source
pub enum PrivateKey {
    Ed25519(SigningKey),
    Secp256k1(SigningKey),
    P256(SigningKey),
    P384(SigningKey),
    Aes256([u8; 32]),
}
Expand description

Container of private keys

The following is supported

Variants§

§

Ed25519(SigningKey)

§

Secp256k1(SigningKey)

§

P256(SigningKey)

§

P384(SigningKey)

§

Aes256([u8; 32])

Implementations§

Source§

impl PrivateKey

Source

pub fn new() -> Self

Generates a new PrivateKey with randomly generated key

Source

pub fn new_with(key_type: PrivateKeyType) -> Self

Generate a PrivateKey using PrivateKeyType

Source

pub fn import(key_type: PrivateKeyType, key: Vec<u8>) -> Result<Self>

Import private key which is identified with PrivateKeyType

Source

pub fn decode<B: AsRef<[u8]>>(bytes: B) -> Result<PrivateKey>

Imports a private key from bytes prefixed with a PrivateKeyType identifier

Source

pub fn to_bytes(&self) -> Vec<u8>

Exports the keys out as bytes.

Source

pub fn encode(&self) -> Vec<u8>

Exports the key out with an identifier

Source

pub fn key_type(&self) -> PrivateKeyType

Provides the PrivateKeyType of the PrivateKey

Source

pub fn public_key(&self) -> Result<PublicKey>

Provides the PublicKey of the PrivateKey Note: This will only work with asymmetric keys. Any symmetric keys will return Error::Unsupported

Source

pub fn sign<B: AsRef<[u8]>>(&self, data: B) -> Result<Vec<u8>>

Sign the data provided using PrivateKey

Source

pub fn sign_reader(&self, reader: &mut impl Read) -> Result<Vec<u8>>

Available on crate feature std only.

Sign the data from std::io::Read using PrivateKey

Source

pub fn verify(&self, data: &[u8], signature: &[u8]) -> Result<()>

Verify the signature of the data provided using PrivateKey

Source

pub fn verify_reader( &self, reader: &mut impl Read, signature: &[u8], ) -> Result<()>

Available on crate feature std only.

Verify the signature of the data from std::io::Read using PrivateKey

Source§

impl PrivateKey

Source

pub fn encrypt(&self, data: &[u8], pubkey: CarrierKeyType) -> Result<Vec<u8>>

Encrypt the data using PrivateKey. If PrivateKeyType::Aes256 is used, the pubkey will be ignored

Source

pub fn encrypt_with_aad( &self, data: &[u8], pubkey: CarrierKeyType, aad: &[u8], ) -> Result<Vec<u8>>

Source

pub fn decrypt(&self, data: &[u8], pubkey: CarrierKeyType) -> Result<Vec<u8>>

Decrypt the data using PrivateKey. If PrivateKeyType::Aes256 is used, the pubkey will be ignored

Source

pub fn decrypt_with_aad( &self, data: &[u8], pubkey: CarrierKeyType, aad: &[u8], ) -> Result<Vec<u8>>

Source§

impl PrivateKey

Source

pub fn encrypt_stream( &self, reader: &mut impl Read, writer: &mut impl Write, pubkey: CarrierKeyType, ) -> Result<()>

Available on crate feature std only.

Encrypt the data stream from std::io::Read to std::io::Write using PrivateKey. If PrivateKeyType::Aes256 is used, the pubkey will be ignored

Source

pub fn decrypt_stream( &self, reader: &mut impl Read, writer: &mut impl Write, pubkey: CarrierKeyType, ) -> Result<()>

Available on crate feature std only.

Decrypt the data stream from std::io::Read to std::io::Write using PrivateKey. If PrivateKeyType::Aes256 is used, the pubkey will be ignored

Trait Implementations§

Source§

impl Clone for PrivateKey

Source§

fn clone(&self) -> PrivateKey

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PrivateKey

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for PrivateKey

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Drop for PrivateKey

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl TryFrom<&PrivateKey> for StaticSecret

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: &PrivateKey) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<PrivateKey> for StaticSecret

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: PrivateKey) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Zeroize for PrivateKey

Source§

fn zeroize(&mut self)

Zero out this object from memory using Rust intrinsics which ensure the zeroization operation is not “optimized away” by the compiler.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 T
where 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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V