1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
use reqwest::StatusCode;
use crate::api::Version;
pub const SEND_DEFAULT_HOST: &str = "https://send.firefox.com/";
pub const SEND_DEFAULT_EXPIRE_TIME: usize = 24 * 60 * 60;
pub const HTTP_STATUS_EXPIRED: StatusCode = StatusCode::NOT_FOUND;
pub const HTTP_STATUS_UNAUTHORIZED: StatusCode = StatusCode::UNAUTHORIZED;
pub const UPLOAD_SIZE_MAX_RECOMMENDED: u64 = 1024 * 1024 * 1024;
#[cfg(feature = "send2")]
const SEND2_MAX_UPLOAD_SIZE: u64 = 1024 * 1024 * 1024 * 2;
#[cfg(feature = "send3")]
const SEND3_MAX_UPLOAD_SIZE: u64 = 1024 * 1024 * 1024;
#[cfg(feature = "send3")]
const SEND3_MAX_UPLOAD_SIZE_AUTH: u64 = ((1024 * 1024 * 1024) as f64 * 2.5f64) as u64;
#[cfg(feature = "send2")]
const SEND2_DEFAULT_DOWNLOADS: usize = 20;
#[cfg(feature = "send3")]
const SEND3_DEFAULT_DOWNLOADS: usize = 1;
#[cfg(feature = "send3")]
const SEND3_DEFAULT_DOWNLOADS_AUTH: usize = 20;
#[cfg(feature = "send2")]
const SEND2_MAX_DOWNLOADS: [usize; 6] = [1, 2, 3, 4, 5, 20];
#[cfg(feature = "send3")]
const SEND3_MAX_DOWNLOADS: [usize; 1] = [1];
#[cfg(feature = "send3")]
const SEND3_MAX_DOWNLOADS_AUTH: [usize; 8] = [1, 2, 3, 4, 5, 20, 50, 100];
pub const SEND_EXPIRY_DEFAULT: usize = 86_400;
#[cfg(feature = "send2")]
const SEND2_EXPIRY_MAX: [usize; 1] = [86_400];
#[cfg(feature = "send3")]
const SEND3_EXPIRY_MAX: [usize; 3] = [300, 3600, 86_400];
#[cfg(feature = "send3")]
const SEND3_EXPIRY_MAX_AUTH: [usize; 4] = [300, 3600, 86_400, 604_800];
pub const TAG_LEN: usize = 16;
pub const ECE_RECORD_SIZE: u32 = 1024 * 64;
pub fn upload_size_max(version: Version, auth: bool) -> u64 {
match version {
#[cfg(feature = "send2")]
Version::V2 => SEND2_MAX_UPLOAD_SIZE,
#[cfg(feature = "send3")]
Version::V3 => {
if auth {
SEND3_MAX_UPLOAD_SIZE_AUTH
} else {
SEND3_MAX_UPLOAD_SIZE
}
}
}
}
pub fn downloads_default(version: Version, auth: bool) -> usize {
match version {
#[cfg(feature = "send2")]
Version::V2 => SEND2_DEFAULT_DOWNLOADS,
#[cfg(feature = "send3")]
Version::V3 => {
if auth {
SEND3_DEFAULT_DOWNLOADS_AUTH
} else {
SEND3_DEFAULT_DOWNLOADS
}
}
}
}
pub fn downloads_max(version: Version, auth: bool) -> &'static [usize] {
match version {
#[cfg(feature = "send2")]
Version::V2 => &SEND2_MAX_DOWNLOADS,
#[cfg(feature = "send3")]
Version::V3 => {
if auth {
&SEND3_MAX_DOWNLOADS_AUTH
} else {
&SEND3_MAX_DOWNLOADS
}
}
}
}
pub fn expiry_max(version: Version, auth: bool) -> &'static [usize] {
match version {
#[cfg(feature = "send2")]
Version::V2 => &SEND2_EXPIRY_MAX,
#[cfg(feature = "send3")]
Version::V3 => {
if auth {
&SEND3_EXPIRY_MAX_AUTH
} else {
&SEND3_EXPIRY_MAX
}
}
}
}