lair_keystore_api/lair_api/
unlock.rs

1use super::*;
2
3/// Unlock the keystore -- this verifies the client to the keystore.
4#[derive(Debug, serde::Serialize, serde::Deserialize)]
5#[serde(rename_all = "camelCase")]
6pub struct LairApiReqUnlock {
7    /// Msg id to relate request / response.
8    pub msg_id: Arc<str>,
9
10    /// Passphrase to unlock the keystore.
11    pub passphrase: SecretDataSized<64, 81>,
12}
13
14impl LairApiReqUnlock {
15    /// Make a new server unlock request.
16    pub fn new(passphrase: SecretDataSized<64, 81>) -> Self {
17        Self {
18            msg_id: new_msg_id(),
19            passphrase,
20        }
21    }
22}
23
24impl std::convert::TryFrom<LairApiEnum> for LairApiReqUnlock {
25    type Error = one_err::OneErr;
26
27    fn try_from(e: LairApiEnum) -> Result<Self, Self::Error> {
28        if let LairApiEnum::ReqUnlock(s) = e {
29            Ok(s)
30        } else {
31            Err(format!("Invalid response type: {e:?}").into())
32        }
33    }
34}
35
36impl AsLairCodec for LairApiReqUnlock {
37    fn into_api_enum(self) -> LairApiEnum {
38        LairApiEnum::ReqUnlock(self)
39    }
40}
41
42/// Sucess / Failure of the unlock request.
43#[derive(Debug, serde::Serialize, serde::Deserialize)]
44#[serde(rename_all = "camelCase")]
45pub struct LairApiResUnlock {
46    /// Msg id to relate request / response.
47    pub msg_id: Arc<str>,
48}
49
50impl std::convert::TryFrom<LairApiEnum> for LairApiResUnlock {
51    type Error = one_err::OneErr;
52
53    fn try_from(e: LairApiEnum) -> Result<Self, Self::Error> {
54        if let LairApiEnum::ResUnlock(s) = e {
55            Ok(s)
56        } else {
57            Err(format!("Invalid response type: {e:?}").into())
58        }
59    }
60}
61
62impl AsLairCodec for LairApiResUnlock {
63    fn into_api_enum(self) -> LairApiEnum {
64        LairApiEnum::ResUnlock(self)
65    }
66}
67
68impl AsLairRequest for LairApiReqUnlock {
69    type Response = LairApiResUnlock;
70}
71
72impl AsLairResponse for LairApiResUnlock {
73    type Request = LairApiReqUnlock;
74}