SerdeEncryptPublicKey

Trait SerdeEncryptPublicKey 

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

Source

type S: TypedSerialized<T = Self>

Serializer implementation

Provided Methods§

Source

fn encrypt( &self, combined_key: &SenderCombinedKey<'_, '_>, ) -> Result<EncryptedMessage, Error>
where Self: Serialize,

Serialize and encrypt.

§Failures
Source

fn decrypt_owned( encrypted_message: &EncryptedMessage, combined_key: &ReceiverCombinedKey<'_, '_>, ) -> Result<Self, Error>
where Self: DeserializeOwned,

Decrypt and deserialize into DeserializeOwned type.

§Failures
Source

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

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.

Implementors§