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§
Implementations§
Source§impl PrivateKey
impl PrivateKey
Sourcepub fn new() -> Self
pub fn new() -> Self
Generates a new PrivateKey with randomly generated key
Sourcepub fn new_with(key_type: PrivateKeyType) -> Self
pub fn new_with(key_type: PrivateKeyType) -> Self
Generate a PrivateKey using PrivateKeyType
Sourcepub fn import(key_type: PrivateKeyType, key: Vec<u8>) -> Result<Self>
pub fn import(key_type: PrivateKeyType, key: Vec<u8>) -> Result<Self>
Import private key which is identified with PrivateKeyType
Sourcepub fn decode<B: AsRef<[u8]>>(bytes: B) -> Result<PrivateKey>
pub fn decode<B: AsRef<[u8]>>(bytes: B) -> Result<PrivateKey>
Imports a private key from bytes prefixed with a PrivateKeyType identifier
Sourcepub fn key_type(&self) -> PrivateKeyType
pub fn key_type(&self) -> PrivateKeyType
Provides the PrivateKeyType of the PrivateKey
Sourcepub fn public_key(&self) -> Result<PublicKey>
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
Sourcepub fn sign<B: AsRef<[u8]>>(&self, data: B) -> Result<Vec<u8>>
pub fn sign<B: AsRef<[u8]>>(&self, data: B) -> Result<Vec<u8>>
Sign the data provided using PrivateKey
Sourcepub fn sign_reader(&self, reader: &mut impl Read) -> Result<Vec<u8>>
Available on crate feature std only.
pub fn sign_reader(&self, reader: &mut impl Read) -> Result<Vec<u8>>
std only.Sign the data from std::io::Read using PrivateKey
Sourcepub fn verify(&self, data: &[u8], signature: &[u8]) -> Result<()>
pub fn verify(&self, data: &[u8], signature: &[u8]) -> Result<()>
Verify the signature of the data provided using PrivateKey
Sourcepub fn verify_reader(
&self,
reader: &mut impl Read,
signature: &[u8],
) -> Result<()>
Available on crate feature std only.
pub fn verify_reader( &self, reader: &mut impl Read, signature: &[u8], ) -> Result<()>
std only.Verify the signature of the data from std::io::Read using PrivateKey
Source§impl PrivateKey
impl PrivateKey
Sourcepub fn encrypt(&self, data: &[u8], pubkey: CarrierKeyType) -> Result<Vec<u8>>
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
pub fn encrypt_with_aad( &self, data: &[u8], pubkey: CarrierKeyType, aad: &[u8], ) -> Result<Vec<u8>>
Sourcepub fn decrypt(&self, data: &[u8], pubkey: CarrierKeyType) -> Result<Vec<u8>>
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
pub fn decrypt_with_aad( &self, data: &[u8], pubkey: CarrierKeyType, aad: &[u8], ) -> Result<Vec<u8>>
Source§impl PrivateKey
impl PrivateKey
Sourcepub fn encrypt_stream(
&self,
reader: &mut impl Read,
writer: &mut impl Write,
pubkey: CarrierKeyType,
) -> Result<()>
Available on crate feature std only.
pub fn encrypt_stream( &self, reader: &mut impl Read, writer: &mut impl Write, pubkey: CarrierKeyType, ) -> Result<()>
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
Sourcepub fn decrypt_stream(
&self,
reader: &mut impl Read,
writer: &mut impl Write,
pubkey: CarrierKeyType,
) -> Result<()>
Available on crate feature std only.
pub fn decrypt_stream( &self, reader: &mut impl Read, writer: &mut impl Write, pubkey: CarrierKeyType, ) -> Result<()>
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
impl Clone for PrivateKey
Source§fn clone(&self) -> PrivateKey
fn clone(&self) -> PrivateKey
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more