pub trait Pke {
type PublicKey: AsRef<[u8]> + Clone;
type SecretKey: Zeroize + AsRef<[u8]> + Clone;
type Ciphertext: AsRef<[u8]> + Clone;
// Required methods
fn name() -> &'static str;
fn keypair<R: CryptoRng + RngCore>(
rng: &mut R,
) -> Result<(Self::PublicKey, Self::SecretKey)>;
fn encrypt<R: RngCore + CryptoRng>(
pk_recipient: &Self::PublicKey,
plaintext: &[u8],
aad: Option<&[u8]>,
rng: &mut R,
) -> Result<Self::Ciphertext>;
fn decrypt(
sk_recipient: &Self::SecretKey,
ciphertext: &Self::Ciphertext,
aad: Option<&[u8]>,
) -> Result<Vec<u8>>;
}Expand description
Trait for Public Key Encryption schemes.
Required Associated Types§
Sourcetype PublicKey: AsRef<[u8]> + Clone
type PublicKey: AsRef<[u8]> + Clone
Public key type for the PKE scheme. Expected to be a byte representation that can be deserialized.
Sourcetype SecretKey: Zeroize + AsRef<[u8]> + Clone
type SecretKey: Zeroize + AsRef<[u8]> + Clone
Secret key type for the PKE scheme. Expected to be a byte representation that can be deserialized.
Sourcetype Ciphertext: AsRef<[u8]> + Clone
type Ciphertext: AsRef<[u8]> + Clone
Ciphertext type produced by the PKE scheme.
This is typically a Vec<u8> containing the serialized ciphertext components.
Required Methods§
Sourcefn keypair<R: CryptoRng + RngCore>(
rng: &mut R,
) -> Result<(Self::PublicKey, Self::SecretKey)>
fn keypair<R: CryptoRng + RngCore>( rng: &mut R, ) -> Result<(Self::PublicKey, Self::SecretKey)>
Generates a new key pair for the PKE scheme.
Sourcefn encrypt<R: RngCore + CryptoRng>(
pk_recipient: &Self::PublicKey,
plaintext: &[u8],
aad: Option<&[u8]>,
rng: &mut R,
) -> Result<Self::Ciphertext>
fn encrypt<R: RngCore + CryptoRng>( pk_recipient: &Self::PublicKey, plaintext: &[u8], aad: Option<&[u8]>, rng: &mut R, ) -> Result<Self::Ciphertext>
Encrypts a plaintext message using the recipient’s public key.
§Arguments
pk_recipient- The recipient’s public key.plaintext- The message to encrypt.aad- Optional Associated Additional Data to be authenticated.rng- A cryptographically secure random number generator.
§Returns
The resulting ciphertext as a Vec<u8>.
Sourcefn decrypt(
sk_recipient: &Self::SecretKey,
ciphertext: &Self::Ciphertext,
aad: Option<&[u8]>,
) -> Result<Vec<u8>>
fn decrypt( sk_recipient: &Self::SecretKey, ciphertext: &Self::Ciphertext, aad: Option<&[u8]>, ) -> Result<Vec<u8>>
Decrypts a ciphertext using the recipient’s secret key.
§Arguments
sk_recipient- The recipient’s secret key.ciphertext- The ciphertext to decrypt.aad- Optional Associated Additional Data that was authenticated.
§Returns
The original plaintext as a Vec<u8> if decryption and authentication (if applicable) succeed.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".