lair_keystore_api/lair_api/
crypto_box_xsalsa_open_by_sign_pub_key.rs

1use super::*;
2
3/// Request "crypto_box_open" decryption.
4#[derive(Debug, serde::Serialize, serde::Deserialize)]
5#[serde(rename_all = "camelCase")]
6pub struct LairApiReqCryptoBoxXSalsaOpenBySignPubKey {
7    /// Msg id to relate request / response.
8    pub msg_id: Arc<str>,
9
10    /// The pub key representing the sender.
11    pub sender_pub_key: Ed25519PubKey,
12
13    /// The pub key of the recipient.
14    pub recipient_pub_key: Ed25519PubKey,
15
16    /// If this new seed is to be deep_locked, the passphrase for that.
17    #[serde(skip_serializing_if = "Option::is_none", default)]
18    pub deep_lock_passphrase: Option<SecretDataSized<64, 81>>,
19
20    /// The nonce associated with the cipher.
21    pub nonce: [u8; 24],
22
23    /// The data to decrypt.
24    pub cipher: Arc<[u8]>,
25}
26
27impl LairApiReqCryptoBoxXSalsaOpenBySignPubKey {
28    /// Make a crypto_box_open request.
29    pub fn new(
30        sender_pub_key: Ed25519PubKey,
31        recipient_pub_key: Ed25519PubKey,
32        deep_lock_passphrase: Option<SecretDataSized<64, 81>>,
33        nonce: [u8; 24],
34        cipher: Arc<[u8]>,
35    ) -> Self {
36        Self {
37            msg_id: new_msg_id(),
38            sender_pub_key,
39            recipient_pub_key,
40            deep_lock_passphrase,
41            nonce,
42            cipher,
43        }
44    }
45}
46
47impl std::convert::TryFrom<LairApiEnum>
48    for LairApiReqCryptoBoxXSalsaOpenBySignPubKey
49{
50    type Error = one_err::OneErr;
51
52    fn try_from(e: LairApiEnum) -> Result<Self, Self::Error> {
53        if let LairApiEnum::ReqCryptoBoxXSalsaOpenBySignPubKey(s) = e {
54            Ok(s)
55        } else {
56            Err(format!("Invalid response type: {e:?}").into())
57        }
58    }
59}
60
61impl AsLairCodec for LairApiReqCryptoBoxXSalsaOpenBySignPubKey {
62    fn into_api_enum(self) -> LairApiEnum {
63        LairApiEnum::ReqCryptoBoxXSalsaOpenBySignPubKey(self)
64    }
65}
66
67/// A "crypto_box_open" decryption response.
68#[derive(Debug, serde::Serialize, serde::Deserialize)]
69#[serde(rename_all = "camelCase")]
70#[non_exhaustive]
71pub struct LairApiResCryptoBoxXSalsaOpenBySignPubKey {
72    /// Msg id to relate request / response.
73    pub msg_id: Arc<str>,
74
75    /// The decrypted bytes.
76    pub message: Arc<[u8]>,
77}
78
79impl std::convert::TryFrom<LairApiEnum>
80    for LairApiResCryptoBoxXSalsaOpenBySignPubKey
81{
82    type Error = one_err::OneErr;
83
84    fn try_from(e: LairApiEnum) -> Result<Self, Self::Error> {
85        if let LairApiEnum::ResCryptoBoxXSalsaOpenBySignPubKey(s) = e {
86            Ok(s)
87        } else {
88            Err(format!("Invalid response type: {e:?}").into())
89        }
90    }
91}
92
93impl AsLairCodec for LairApiResCryptoBoxXSalsaOpenBySignPubKey {
94    fn into_api_enum(self) -> LairApiEnum {
95        LairApiEnum::ResCryptoBoxXSalsaOpenBySignPubKey(self)
96    }
97}
98
99impl AsLairRequest for LairApiReqCryptoBoxXSalsaOpenBySignPubKey {
100    type Response = LairApiResCryptoBoxXSalsaOpenBySignPubKey;
101}
102
103impl AsLairResponse for LairApiResCryptoBoxXSalsaOpenBySignPubKey {
104    type Request = LairApiReqCryptoBoxXSalsaOpenBySignPubKey;
105}