ffsend_api/file/
info.rs

1use serde_json;
2
3use crate::config;
4use crate::crypto::key_set::KeySet;
5
6/// File information, sent to the server before uploading.
7///
8/// This is used for Firefox Send v3.
9#[derive(Debug, Serialize, Deserialize)]
10pub struct FileInfo {
11    /// The expirey time in seconds.
12    ///
13    /// Must be in any of these bounds:
14    /// - Not authenticated: `[0, 86400]`
15    /// - Authenticated: `[0, 86400 * 7]`
16    #[serde(rename = "timeLimit")]
17    expire: usize,
18
19    /// The download limit.
20    ///
21    /// Must be in any of these bounds:
22    /// - Not authenticated: `[0, 20]`
23    /// - Authenticated: `[0, 200]`
24    #[serde(rename = "dlimit")]
25    download_limit: Option<u8>,
26
27    /// File metadata.
28    #[serde(rename = "fileMetadata")]
29    metadata: String,
30
31    /// File authorization.
32    // TODO: what is this?
33    #[serde(rename = "authorization")]
34    auth: String,
35
36    /// Firefox Account user authentication information.
37    // TODO: what is this?
38    #[serde(rename = "bearer")]
39    _firefox_user: Option<String>,
40}
41
42impl FileInfo {
43    /// Constructor.
44    ///
45    /// Parameters:
46    /// * `expire`: optional file expiry time in seconds.
47    /// * `download_limit`: optional download limit.
48    /// * `metadata`: encrypted and base64 encoded file metadata
49    /// * `auth`: authorization data
50    pub fn from(
51        expire: Option<usize>,
52        download_limit: Option<u8>,
53        metadata: String,
54        key_set: &KeySet,
55    ) -> Self {
56        Self {
57            expire: expire.unwrap_or(config::SEND_DEFAULT_EXPIRE_TIME),
58            download_limit,
59            metadata,
60            auth: format!("send-v1 {}", key_set.auth_key_encoded().unwrap()),
61            _firefox_user: None,
62        }
63    }
64
65    /// Convert this structure to a JSON string.
66    pub fn to_json(&self) -> String {
67        serde_json::to_string(&self).unwrap()
68    }
69}