pub trait Suspendable<const SERIALIZED_STATE_LEN: usize>: Sized {
// Required methods
fn suspend(self) -> [u8; SERIALIZED_STATE_LEN];
fn from_suspended(
state: [u8; SERIALIZED_STATE_LEN],
) -> Result<Self, SuspendableError>;
}Expand description
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.
This is intended for situations where an object is being used through its streaming API (do_update, do_final) and the operation wants to be paused to a cache, for example while waiting for network IO.
This is not intended as a mechanism to clone the state of an object since in most cases .clone()
will be more straightforward.
The serialized state MAY contain short-term sensitive values such as nonces or IVs,
but it MUST NOT include a serialized private key.
Keyed algorithms MUST instead impl
SuspendableKeyed which requires the key to be supplied independently at the time of deserialization.
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],
) -> Result<Self, SuspendableError>
fn from_suspended( state: [u8; SERIALIZED_STATE_LEN], ) -> Result<Self, SuspendableError>
Resume operation from a serialized state.
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.