1use serde::{Deserialize, Serialize};
5use trussed_core::{types::KeyId, Error, Result};
6
7use super::AuthReply;
8
9#[derive(Debug, Deserialize, Serialize)]
10#[must_use]
11pub struct HasPin {
12 pub has_pin: bool,
13}
14
15impl From<HasPin> for AuthReply {
16 fn from(reply: HasPin) -> Self {
17 Self::HasPin(reply)
18 }
19}
20
21impl TryFrom<AuthReply> for HasPin {
22 type Error = Error;
23
24 fn try_from(reply: AuthReply) -> Result<Self> {
25 match reply {
26 AuthReply::HasPin(reply) => Ok(reply),
27 _ => Err(Error::InternalError),
28 }
29 }
30}
31
32#[derive(Debug, Deserialize, Serialize)]
33#[must_use]
34pub struct CheckPin {
35 pub success: bool,
36}
37
38impl From<CheckPin> for AuthReply {
39 fn from(reply: CheckPin) -> Self {
40 Self::CheckPin(reply)
41 }
42}
43
44impl TryFrom<AuthReply> for CheckPin {
45 type Error = Error;
46
47 fn try_from(reply: AuthReply) -> Result<Self> {
48 match reply {
49 AuthReply::CheckPin(reply) => Ok(reply),
50 _ => Err(Error::InternalError),
51 }
52 }
53}
54
55#[derive(Debug, Deserialize, Serialize)]
56#[must_use]
57pub struct GetPinKey {
58 pub result: Option<KeyId>,
60}
61
62impl From<GetPinKey> for AuthReply {
63 fn from(reply: GetPinKey) -> Self {
64 Self::GetPinKey(reply)
65 }
66}
67
68impl TryFrom<AuthReply> for GetPinKey {
69 type Error = Error;
70
71 fn try_from(reply: AuthReply) -> Result<Self> {
72 match reply {
73 AuthReply::GetPinKey(reply) => Ok(reply),
74 _ => Err(Error::InternalError),
75 }
76 }
77}
78
79#[derive(Debug, Deserialize, Serialize)]
80#[must_use]
81pub struct GetApplicationKey {
82 pub key: KeyId,
83}
84
85impl From<GetApplicationKey> for AuthReply {
86 fn from(reply: GetApplicationKey) -> Self {
87 Self::GetApplicationKey(reply)
88 }
89}
90
91impl TryFrom<AuthReply> for GetApplicationKey {
92 type Error = Error;
93
94 fn try_from(reply: AuthReply) -> Result<Self> {
95 match reply {
96 AuthReply::GetApplicationKey(reply) => Ok(reply),
97 _ => Err(Error::InternalError),
98 }
99 }
100}
101
102#[derive(Debug, Deserialize, Serialize)]
103pub struct SetPin;
104
105impl From<SetPin> for AuthReply {
106 fn from(reply: SetPin) -> Self {
107 Self::SetPin(reply)
108 }
109}
110
111impl TryFrom<AuthReply> for SetPin {
112 type Error = Error;
113
114 fn try_from(reply: AuthReply) -> Result<Self> {
115 match reply {
116 AuthReply::SetPin(reply) => Ok(reply),
117 _ => Err(Error::InternalError),
118 }
119 }
120}
121
122#[derive(Debug, Deserialize, Serialize)]
123pub struct SetPinWithKey;
124
125impl From<SetPinWithKey> for AuthReply {
126 fn from(reply: SetPinWithKey) -> Self {
127 Self::SetPinWithKey(reply)
128 }
129}
130
131impl TryFrom<AuthReply> for SetPinWithKey {
132 type Error = Error;
133
134 fn try_from(reply: AuthReply) -> Result<Self> {
135 match reply {
136 AuthReply::SetPinWithKey(reply) => Ok(reply),
137 _ => Err(Error::InternalError),
138 }
139 }
140}
141
142#[derive(Debug, Deserialize, Serialize)]
143pub struct ChangePin {
144 pub success: bool,
145}
146
147impl From<ChangePin> for AuthReply {
148 fn from(reply: ChangePin) -> Self {
149 Self::ChangePin(reply)
150 }
151}
152
153impl TryFrom<AuthReply> for ChangePin {
154 type Error = Error;
155
156 fn try_from(reply: AuthReply) -> Result<Self> {
157 match reply {
158 AuthReply::ChangePin(reply) => Ok(reply),
159 _ => Err(Error::InternalError),
160 }
161 }
162}
163
164#[derive(Debug, Deserialize, Serialize)]
165pub struct DeletePin;
166
167impl From<DeletePin> for AuthReply {
168 fn from(reply: DeletePin) -> Self {
169 Self::DeletePin(reply)
170 }
171}
172
173impl TryFrom<AuthReply> for DeletePin {
174 type Error = Error;
175
176 fn try_from(reply: AuthReply) -> Result<Self> {
177 match reply {
178 AuthReply::DeletePin(reply) => Ok(reply),
179 _ => Err(Error::InternalError),
180 }
181 }
182}
183
184#[derive(Debug, Deserialize, Serialize)]
185pub struct DeleteAllPins;
186
187impl From<DeleteAllPins> for AuthReply {
188 fn from(reply: DeleteAllPins) -> Self {
189 Self::DeleteAllPins(reply)
190 }
191}
192
193impl TryFrom<AuthReply> for DeleteAllPins {
194 type Error = Error;
195
196 fn try_from(reply: AuthReply) -> Result<Self> {
197 match reply {
198 AuthReply::DeleteAllPins(reply) => Ok(reply),
199 _ => Err(Error::InternalError),
200 }
201 }
202}
203
204#[derive(Debug, Deserialize, Serialize)]
205#[must_use]
206pub struct PinRetries {
207 pub retries: Option<u8>,
208}
209
210impl From<PinRetries> for AuthReply {
211 fn from(reply: PinRetries) -> Self {
212 Self::PinRetries(reply)
213 }
214}
215
216impl TryFrom<AuthReply> for PinRetries {
217 type Error = Error;
218
219 fn try_from(reply: AuthReply) -> Result<Self> {
220 match reply {
221 AuthReply::PinRetries(reply) => Ok(reply),
222 _ => Err(Error::InternalError),
223 }
224 }
225}
226#[derive(Debug, Deserialize, Serialize)]
227pub struct ResetAppKeys;
228
229impl From<ResetAppKeys> for AuthReply {
230 fn from(reply: ResetAppKeys) -> Self {
231 Self::ResetAppKeys(reply)
232 }
233}
234
235impl TryFrom<AuthReply> for ResetAppKeys {
236 type Error = Error;
237
238 fn try_from(reply: AuthReply) -> Result<Self> {
239 match reply {
240 AuthReply::ResetAppKeys(reply) => Ok(reply),
241 _ => Err(Error::InternalError),
242 }
243 }
244}
245
246#[derive(Debug, Deserialize, Serialize)]
247pub struct ResetAuthData;
248
249impl From<ResetAuthData> for AuthReply {
250 fn from(reply: ResetAuthData) -> Self {
251 Self::ResetAuthData(reply)
252 }
253}
254
255impl TryFrom<AuthReply> for ResetAuthData {
256 type Error = Error;
257
258 fn try_from(reply: AuthReply) -> Result<Self> {
259 match reply {
260 AuthReply::ResetAuthData(reply) => Ok(reply),
261 _ => Err(Error::InternalError),
262 }
263 }
264}