pub trait SuspendableKeyed<const SERIALIZED_STATE_LEN: usize>: Sized {
type Key: ?Sized;
// Required methods
fn suspend(self) -> [u8; SERIALIZED_STATE_LEN];
fn from_suspended(
state: [u8; SERIALIZED_STATE_LEN],
key: &Self::Key,
) -> Result<Self, SuspendableError>;
}Expand description
Similar to Suspendable in that it allows a stateful object to suspend its operation by
serializing its state into a byte array so that it can be resumed later, potentially from a different host.
The difference is that this trait is for keyed algorithms – MACs, symmetric ciphers, signatures, etc – which require a private key in order to resume successfully. For security reasons, the private key is not included in the serialized state and must be provided separately as part of the deserialization process.
Required Associated Types§
Required Methods§
Sourcefn suspend(self) -> [u8; SERIALIZED_STATE_LEN]
fn suspend(self) -> [u8; SERIALIZED_STATE_LEN]
Suspend operation by serializing out the state of the object.
Note that this consumes self to prevent accidentally continuing to use the object after serialization.
If you want to do this intentionally, then you will need to clone the object before serializing it.
The serialized state MUST include a prefix indicating the version of the library that serialized it.
Sourcefn from_suspended(
state: [u8; SERIALIZED_STATE_LEN],
key: &Self::Key,
) -> Result<Self, SuspendableError>
fn from_suspended( state: [u8; SERIALIZED_STATE_LEN], key: &Self::Key, ) -> Result<Self, SuspendableError>
Resume operation from a serialized state and the key.
Deserializers SHOULD check the version and reject serialized states from incompatible versions (including rejecting serializations from a future version of the library). For example, if a given object made a breaking change to its serialization in version 1.2.3, then its deserializer should reject serialized states from that version or older.
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.