pub struct EncryptedBodyBuilder<T> { /* private fields */ }Expand description
Route builder that expects a VEIL-encrypted request body of type T.
Obtained from ServerMechanism::encryption. On each matching request the raw
body bytes are decrypted using the SerializationKey supplied there. If
decryption fails for any reason (wrong key, mismatched secret, corrupted payload)
the route immediately returns 403 Forbidden — the handler is never invoked.
Optionally attach shared state via state before
finalising with onconnect /
onconnect_sync.
Implementations§
Source§impl<T> EncryptedBodyBuilder<T>
impl<T> EncryptedBodyBuilder<T>
Sourcepub fn onconnect<F, Fut, Re>(self, handler: F) -> SocketType
pub fn onconnect<F, Fut, Re>(self, handler: F) -> SocketType
Finalises this route with an async handler that receives the decrypted body as T.
On each request the raw body bytes are VEIL-decrypted using the SerializationKey
configured on this builder. The handler is only invoked when decryption succeeds —
a wrong key, mismatched secret, or corrupted body causes the route to return
403 Forbidden without ever reaching the handler. The T the closure receives is
therefore always a trusted, fully-decrypted value ready to use.
The handler must return Result<impl Reply, Rejection>.
Returns a SocketType ready to be passed to Server::mechanism.
Sourcepub unsafe fn onconnect_sync<F, Re>(self, handler: F) -> SocketType
pub unsafe fn onconnect_sync<F, Re>(self, handler: F) -> SocketType
Finalises this route with a synchronous handler that receives the decrypted
body as T.
Decryption happens before the handler is dispatched to the thread pool: if the key
is wrong or the body is corrupt the request is rejected with 403 Forbidden and
the thread pool is not touched at all. The T handed to the closure is always a
trusted, fully-decrypted value. The closure may block but must complete quickly.
Returns a SocketType ready to be passed to Server::mechanism.
§Safety
See ServerMechanism::onconnect_sync for the thread-pool safety notes.
Sourcepub fn state<S: Clone + Send + Sync + 'static>(
self,
state: S,
) -> StatefulEncryptedBodyBuilder<T, S>
pub fn state<S: Clone + Send + Sync + 'static>( self, state: S, ) -> StatefulEncryptedBodyBuilder<T, S>
Attaches shared state S, transitioning to StatefulEncryptedBodyBuilder.
A fresh clone of S is injected alongside the decrypted T on every request.
The handler will receive (state: S, body: T).
S must be Clone + Send + Sync + 'static.