Trait bdrck::crypto::key::AbstractKey
source · pub trait AbstractKey: Sized {
type Error: Error;
// Required methods
fn get_digest(&self) -> Digest;
fn serialize(&self) -> Result<Secret, Self::Error>;
fn deserialize(data: Secret) -> Result<Self, Self::Error>;
fn encrypt(
&self,
plaintext: &Secret,
nonce: Option<Nonce>
) -> Result<(Option<Nonce>, Vec<u8>), Self::Error>;
fn decrypt(
&self,
nonce: Option<&Nonce>,
ciphertext: &[u8]
) -> Result<Secret, Self::Error>;
}
Expand description
An AbstractKey is any cryptographic structure which supports encryption and decryption.
Required Associated Types§
Required Methods§
sourcefn get_digest(&self) -> Digest
fn get_digest(&self) -> Digest
Return a digest/signature computed from this key.
sourcefn serialize(&self) -> Result<Secret, Self::Error>
fn serialize(&self) -> Result<Secret, Self::Error>
Serialize this key out as a set of raw bytes.
sourcefn deserialize(data: Secret) -> Result<Self, Self::Error>
fn deserialize(data: Secret) -> Result<Self, Self::Error>
Construct an instance of this key from a previously serialized instance of the key. In
general, deserialize
should accept data previously produced by this key’s serialize
implementation.
sourcefn encrypt(
&self,
plaintext: &Secret,
nonce: Option<Nonce>
) -> Result<(Option<Nonce>, Vec<u8>), Self::Error>
fn encrypt( &self, plaintext: &Secret, nonce: Option<Nonce> ) -> Result<(Option<Nonce>, Vec<u8>), Self::Error>
Encrypt the given plaintext with this key. This function optionally takes a nonce as an argument. If this key’s encryption algorithm utilizes a nonce, the provided one will be used.
This function returns the ciphertext, as well as a Nonce (if one was used for encryption). If a Nonce was provided, that same Nonce is returned.