1mod authorization;
4mod directive;
5mod directive_site;
6mod elements;
7mod error;
8mod error_response;
9
10pub use authorization::*;
11pub use directive::*;
12pub use directive_site::*;
13pub use elements::*;
14pub use error::*;
15pub use error_response::*;
16
17pub use http::StatusCode;
18pub use serde::Deserialize;
19use serde::Serialize;
20
21use crate::{cbor, wit};
22
23pub struct FieldOutput(wit::FieldOutput);
25
26impl Default for FieldOutput {
27 fn default() -> Self {
28 Self::new()
29 }
30}
31
32impl FieldOutput {
33 pub fn new() -> Self {
35 Self(wit::FieldOutput { outputs: Vec::new() })
36 }
37
38 pub fn with_capacity(capacity: usize) -> Self {
43 Self(wit::FieldOutput {
44 outputs: Vec::with_capacity(capacity),
45 })
46 }
47
48 pub fn push_value<T>(&mut self, output: T)
50 where
51 T: Serialize,
52 {
53 let output = crate::cbor::to_vec(output).expect("serialization error is Infallible, so it should never happen");
54
55 self.0.outputs.push(Ok(output));
56 }
57
58 pub fn push_error(&mut self, error: impl Into<Error>) {
60 self.0.outputs.push(Err(Into::<Error>::into(error).into()));
61 }
62}
63
64impl From<FieldOutput> for wit::FieldOutput {
65 fn from(value: FieldOutput) -> Self {
66 value.0
67 }
68}
69
70#[derive(Debug)]
72pub struct FieldInputs(Vec<Vec<u8>>);
73
74impl FieldInputs {
75 pub(crate) fn new(inputs: Vec<Vec<u8>>) -> Self {
76 Self(inputs)
77 }
78
79 pub fn deserialize<'de, T>(&'de self) -> Result<Vec<T>, Box<dyn std::error::Error>>
81 where
82 T: Deserialize<'de>,
83 {
84 self.0
85 .iter()
86 .map(|input| cbor::from_slice(input).map_err(|e| Box::new(e) as Box<dyn std::error::Error>))
87 .collect()
88 }
89}
90
91pub struct Configuration(Vec<u8>);
93
94impl Configuration {
95 pub(crate) fn new(config: Vec<u8>) -> Self {
97 Self(config)
98 }
99
100 pub fn deserialize<'de, T>(&'de self) -> Result<T, Box<dyn std::error::Error>>
106 where
107 T: Deserialize<'de>,
108 {
109 cbor::from_slice(&self.0).map_err(|e| Box::new(e) as Box<dyn std::error::Error>)
110 }
111}
112
113pub struct Cache;
115
116pub struct Token {
118 claims: Vec<u8>,
119}
120
121impl From<Token> for wit::Token {
122 fn from(token: Token) -> wit::Token {
123 wit::Token { raw: token.claims }
124 }
125}
126
127impl Token {
128 pub fn new<T>(claims: T) -> Self
132 where
133 T: serde::Serialize,
134 {
135 Self {
136 claims: cbor::to_vec(&claims).expect("serialization error is Infallible, so it should never happen"),
137 }
138 }
139}