serde_encrypt/
serialize.rs

1//! Serializer trait and default implementation.
2
3pub mod impls;
4
5use crate::Error;
6use alloc::vec::Vec;
7use serde::{Deserialize, Serialize};
8
9/// Serialization abstract with type to serialize.
10///
11/// Serializer implementations must implement this trait.
12pub trait TypedSerialized {
13    /// Type to serialize
14    type T;
15
16    /// Constructor
17    fn new(serialized: Vec<u8>) -> Self
18    where
19        Self: Sized;
20
21    /// Ref to serialized.
22    fn as_slice(&self) -> &[u8];
23
24    /// Into serialized.
25    fn into_vec(self) -> Vec<u8>;
26
27    /// # Failures
28    ///
29    /// - [SerializationError](serde_encrypt_core::error::ErrorKind::SerializationError) when failed to serialize message.
30    fn serialize(v: &Self::T) -> Result<Self, Error>
31    where
32        Self: Sized,
33        Self::T: Serialize;
34
35    /// # Failures
36    ///
37    /// - [DeserializationError](serde_encrypt_core::error::ErrorKind::DeserializationError) when failed to deserialize decrypted message.
38    fn deserialize<'de>(&'de self) -> Result<Self::T, Error>
39    where
40        Self::T: Deserialize<'de>;
41}