pub trait SerdeEncryptPublicKey {
type S: TypedSerialized<T = Self>;
// Provided methods
fn encrypt(
&self,
combined_key: &SenderCombinedKey<'_, '_>,
) -> Result<EncryptedMessage, Error>
where Self: Serialize { ... }
fn decrypt_owned(
encrypted_message: &EncryptedMessage,
combined_key: &ReceiverCombinedKey<'_, '_>,
) -> Result<Self, Error>
where Self: DeserializeOwned { ... }
fn decrypt_ref<'de>(
encrypted_message: &EncryptedMessage,
combined_key: &ReceiverCombinedKey<'_, '_>,
) -> Result<Self::S, Error>
where Self: Deserialize<'de> { ... }
}Expand description
Public-key authenticated encryption for serde-serializable types.
§Features
- Safe and bidirectional public-key exchange.
- Message authentication.
- Different cipher-text for the same plain-text to avoid attacks such as statistical analysis of cipher-text.
§Anti-features
- Identity authentication of sender nor receiver.
§Popular use cases
- Shared-key exchange.
- Encryption for relatively small and non-frequent messages (shared-key encryption is faster than public-key).
§Examples
§Encrypting owned data
See this example.
§Encrypting struct with reference fields
See this example.
§Algorithm
- Public-key exchange: X25519
- Encryption: XChaCha20
- Message authentication: Poly1305 MAC
Required Associated Types§
Sourcetype S: TypedSerialized<T = Self>
type S: TypedSerialized<T = Self>
Serializer implementation
Provided Methods§
Sourcefn encrypt(
&self,
combined_key: &SenderCombinedKey<'_, '_>,
) -> Result<EncryptedMessage, Error>where
Self: Serialize,
fn encrypt(
&self,
combined_key: &SenderCombinedKey<'_, '_>,
) -> Result<EncryptedMessage, Error>where
Self: Serialize,
Serialize and encrypt.
§Failures
- SerializationError when failed to serialize message.
- EncryptionError when failed to encrypt serialized message.
Sourcefn decrypt_owned(
encrypted_message: &EncryptedMessage,
combined_key: &ReceiverCombinedKey<'_, '_>,
) -> Result<Self, Error>where
Self: DeserializeOwned,
fn decrypt_owned(
encrypted_message: &EncryptedMessage,
combined_key: &ReceiverCombinedKey<'_, '_>,
) -> Result<Self, Error>where
Self: DeserializeOwned,
Decrypt and deserialize into DeserializeOwned type.
§Failures
- DecryptionError when failed to decrypt message.
- DeserializationError when failed to deserialize decrypted message.
Sourcefn decrypt_ref<'de>(
encrypted_message: &EncryptedMessage,
combined_key: &ReceiverCombinedKey<'_, '_>,
) -> Result<Self::S, Error>where
Self: Deserialize<'de>,
fn decrypt_ref<'de>(
encrypted_message: &EncryptedMessage,
combined_key: &ReceiverCombinedKey<'_, '_>,
) -> Result<Self::S, Error>where
Self: Deserialize<'de>,
Just decrypts cipher-text. Returned data must be deserialized later.
Types implementing serde::Deserialize<'de> (not serde::de::DeserializeOwned) should use
this function to resolve lifetime.
§Failures
- DecryptionError when failed to decrypt message.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.