cratestack_cose/envelope/open_api.rs
1//! The typed opening methods of [`CoseEnvelope`]: requests (one binding, or
2//! several candidates) and responses.
3
4use bytes::Bytes;
5use cratestack_core::{Binding, CratestackError};
6
7use super::CoseEnvelope;
8use crate::opened::Opened;
9
10impl CoseEnvelope {
11 /// Verify a request and run the replay checks, without a
12 /// `CratestackContext` (the #1006 axum layer runs before one exists).
13 /// Needs a nonce store; without one it is local misuse (a `500`).
14 pub async fn open_request(
15 &self,
16 body: Bytes,
17 bind: &Binding<'_>,
18 ) -> Result<Opened, CratestackError> {
19 crate::open::open(&self.inner, body, bind, true).await
20 }
21
22 /// [`open_request`](Self::open_request) against several candidate
23 /// bindings (differing, for the axum layer, only in the op-contract
24 /// digest): the message is parsed once and its key resolved once, and
25 /// only the signature verification is repeated per candidate, in
26 /// order. Returns the opened request and the index of the binding that
27 /// verified. A failed candidate records no nonce; an empty list is the
28 /// coarse `401`.
29 pub async fn open_request_any(
30 &self,
31 body: Bytes,
32 binds: &[Binding<'_>],
33 ) -> Result<(Opened, usize), CratestackError> {
34 crate::open::open_any(&self.inner, body, binds, true).await
35 }
36
37 /// Verify a response against the request it answers.
38 pub async fn open_response(
39 &self,
40 body: Bytes,
41 bind: &Binding<'_>,
42 ) -> Result<Opened, CratestackError> {
43 crate::open::open(&self.inner, body, bind, false).await
44 }
45}