fxa_client/internal/commands/
mod.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5pub mod close_tabs;
6mod keys;
7pub mod send_tab;
8
9pub use close_tabs::CloseTabsPayload;
10pub use send_tab::SendTabPayload;
11
12pub(crate) use keys::{
13    decrypt_command, encrypt_command, get_public_keys, PrivateCommandKeys, PublicCommandKeys,
14};
15
16use super::device::Device;
17use crate::{Error, Result};
18
19// Currently public for use by example crates, but should be made private eventually.
20#[derive(Clone, Debug)]
21pub enum IncomingDeviceCommand {
22    TabReceived {
23        sender: Option<Device>,
24        payload: SendTabPayload,
25    },
26    TabsClosed {
27        sender: Option<Device>,
28        payload: CloseTabsPayload,
29    },
30}
31
32impl TryFrom<IncomingDeviceCommand> for crate::IncomingDeviceCommand {
33    type Error = Error;
34    fn try_from(cmd: IncomingDeviceCommand) -> Result<Self> {
35        Ok(match cmd {
36            IncomingDeviceCommand::TabReceived { sender, payload } => {
37                crate::IncomingDeviceCommand::TabReceived {
38                    sender: sender.map(crate::Device::try_from).transpose()?,
39                    payload: payload.into(),
40                }
41            }
42            IncomingDeviceCommand::TabsClosed { sender, payload } => {
43                crate::IncomingDeviceCommand::TabsClosed {
44                    sender: sender.map(crate::Device::try_from).transpose()?,
45                    payload: payload.into(),
46                }
47            }
48        })
49    }
50}