ffsend_api/
config.rs

1use reqwest::StatusCode;
2
3use crate::api::Version;
4
5/// The Send host to use by default.
6pub const SEND_DEFAULT_HOST: &str = "https://send.vis.ee/";
7
8/// The default time after which uploaded files expire after, in seconds.
9pub const SEND_DEFAULT_EXPIRE_TIME: usize = 24 * 60 * 60;
10
11/// The HTTP status code that is returned for expired or non existant files.
12pub const HTTP_STATUS_EXPIRED: StatusCode = StatusCode::NOT_FOUND;
13
14/// The HTTP status code that is returned on authentication failure.
15pub const HTTP_STATUS_UNAUTHORIZED: StatusCode = StatusCode::UNAUTHORIZED;
16
17/// The recommended maximum upload size in bytes.
18pub const UPLOAD_SIZE_MAX_RECOMMENDED: u64 = ((1024 * 1024 * 1024) as f64 * 2.5f64) as u64;
19
20/// The maximum upload size in bytes for Firefox Send v2.
21#[cfg(feature = "send2")]
22const SEND2_MAX_UPLOAD_SIZE: u64 = 1024 * 1024 * 1024 * 2;
23
24/// The maximum upload size in bytes for Firefox Send v3 non-authenticated users.
25#[cfg(feature = "send3")]
26const SEND3_MAX_UPLOAD_SIZE: u64 = ((1024 * 1024 * 1024) as f64 * 2.5f64) as u64;
27
28/// The maximum upload size in bytes for Firefox Send v3 authenticated users.
29#[cfg(feature = "send3")]
30const SEND3_MAX_UPLOAD_SIZE_AUTH: u64 = SEND3_MAX_UPLOAD_SIZE;
31
32/// Default number of maximum downloads for a Send v2 file.
33#[cfg(feature = "send2")]
34const SEND2_DEFAULT_DOWNLOADS: usize = 20;
35
36/// Default number of maximum downloads for a Send v3 file.
37#[cfg(feature = "send3")]
38const SEND3_DEFAULT_DOWNLOADS: usize = 1;
39
40/// Default number of maximum downloads for a Send v3 file when authenticated.
41#[cfg(feature = "send3")]
42const SEND3_DEFAULT_DOWNLOADS_AUTH: usize = SEND3_DEFAULT_DOWNLOADS;
43
44/// Supported maximum number of download values for a file for Firefox Send v2.
45#[cfg(feature = "send2")]
46const SEND2_MAX_DOWNLOADS: [usize; 6] = [1, 2, 3, 4, 5, 20];
47
48/// Supported maximum number of download values for Firefox Send v3 non-authenticated users.
49#[cfg(feature = "send3")]
50const SEND3_MAX_DOWNLOADS: [usize; 6] = [1, 2, 3, 4, 5, 20];
51
52/// Supported maximum number of download values for Firefox Send v3 authenticated users.
53#[cfg(feature = "send3")]
54const SEND3_MAX_DOWNLOADS_AUTH: [usize; 8] = [1, 2, 3, 4, 5, 20, 50, 100];
55
56/// The default expriy time in seconds for a file.
57pub const SEND_EXPIRY_DEFAULT: usize = 86_400;
58
59/// Supported maximum file expiry time values in seconds for a file for Firefox Send v2.
60#[cfg(feature = "send2")]
61const SEND2_EXPIRY_MAX: [usize; 1] = [86_400];
62
63/// Supported maximum file expiry time values in seconds for a file for Firefox Send v3 non-authenticated users.
64// TODO: use single biggest value, can use any expiry time now
65#[cfg(feature = "send3")]
66const SEND3_EXPIRY_MAX: [usize; 4] = [300, 3600, 86_400, 604_800];
67
68/// Supported maximum file expiry time values in seconds for a file for Firefox Send v3 authenticated users.
69#[cfg(feature = "send3")]
70const SEND3_EXPIRY_MAX_AUTH: [usize; 4] = SEND3_EXPIRY_MAX;
71
72/// The length of the tag in bytes we're using for cryptography.
73pub const TAG_LEN: usize = 16;
74
75/// The ECE record size that is used (`>= Send v2`).
76pub const ECE_RECORD_SIZE: u32 = 1024 * 64;
77
78/// Get the maximum file upload size.
79pub fn upload_size_max(version: Version, _auth: bool) -> u64 {
80    match version {
81        #[cfg(feature = "send2")]
82        Version::V2 => SEND2_MAX_UPLOAD_SIZE,
83        #[cfg(feature = "send3")]
84        Version::V3 => {
85            if _auth {
86                SEND3_MAX_UPLOAD_SIZE_AUTH
87            } else {
88                SEND3_MAX_UPLOAD_SIZE
89            }
90        }
91    }
92}
93
94/// Get supported maximum number of download values for a Send file.
95///
96/// The remote server only accepts any of these specific values, and nothing in between.
97pub fn downloads_default(version: Version, _auth: bool) -> usize {
98    match version {
99        #[cfg(feature = "send2")]
100        Version::V2 => SEND2_DEFAULT_DOWNLOADS,
101        #[cfg(feature = "send3")]
102        Version::V3 => {
103            if _auth {
104                SEND3_DEFAULT_DOWNLOADS_AUTH
105            } else {
106                SEND3_DEFAULT_DOWNLOADS
107            }
108        }
109    }
110}
111
112/// Get supported maximum number of download values for a Send file.
113///
114/// The remote server only accepts any of these specific values, and nothing in between.
115pub fn downloads_max(version: Version, _auth: bool) -> &'static [usize] {
116    match version {
117        #[cfg(feature = "send2")]
118        Version::V2 => &SEND2_MAX_DOWNLOADS,
119        #[cfg(feature = "send3")]
120        Version::V3 => {
121            if _auth {
122                &SEND3_MAX_DOWNLOADS_AUTH
123            } else {
124                &SEND3_MAX_DOWNLOADS
125            }
126        }
127    }
128}
129
130/// Get supported maximum file expiry time values in seconds for a Send file.
131///
132/// The remote server only accepts any of these specific values, and nothing in between.
133pub fn expiry_max(version: Version, _auth: bool) -> &'static [usize] {
134    match version {
135        #[cfg(feature = "send2")]
136        Version::V2 => &SEND2_EXPIRY_MAX,
137        #[cfg(feature = "send3")]
138        Version::V3 => {
139            if _auth {
140                &SEND3_EXPIRY_MAX_AUTH
141            } else {
142                &SEND3_EXPIRY_MAX
143            }
144        }
145    }
146}