1use pyo3::{pyclass, pymethods};
4
5#[pyclass(frozen)]
7#[derive(Debug, Clone)]
8pub struct Label {
9 #[pyo3(get)]
11 pub id: u64,
12
13 #[pyo3(get)]
15 pub name: String,
16
17 #[pyo3(get)]
19 pub parent: Option<String>,
20}
21
22#[pymethods]
23impl Label {
24 #[must_use]
26 pub fn __repr__(&self) -> String {
27 if let Some(parent) = &self.parent {
28 format!("Label {}: {parent}/{}", self.id, self.name)
29 } else {
30 format!("Label {}: {}", self.id, self.name)
31 }
32 }
33
34 #[must_use]
36 pub fn __str__(&self) -> String {
37 self.name.clone()
38 }
39}
40
41#[pyclass(frozen)]
43#[derive(Debug, Clone)]
44pub struct ServerInfo {
45 #[pyo3(get)]
47 pub os_name: String,
48
49 #[pyo3(get)]
51 pub memory_used: String,
52
53 #[pyo3(get)]
55 pub mdb_version: String,
56
57 #[pyo3(get)]
59 pub db_version: String,
60
61 #[pyo3(get)]
63 pub db_size: String,
64
65 #[pyo3(get)]
67 pub num_samples: u64,
68
69 #[pyo3(get)]
71 pub num_users: u32,
72
73 #[pyo3(get)]
75 pub uptime: String,
76}
77
78#[pymethods]
79impl ServerInfo {
80 #[must_use]
82 pub fn __repr__(&self) -> String {
83 format!(
84 "MalwareDB {} running on {} for {}",
85 self.mdb_version, self.os_name, self.uptime
86 )
87 }
88
89 #[must_use]
91 pub fn __str__(&self) -> String {
92 format!("MalwareDB {}", self.mdb_version)
93 }
94}
95
96#[pyclass(frozen)]
98#[derive(Debug, Clone)]
99pub struct Source {
100 #[pyo3(get)]
102 pub id: u32,
103
104 #[pyo3(get)]
106 pub name: String,
107
108 #[pyo3(get)]
110 pub description: Option<String>,
111
112 #[pyo3(get)]
114 pub url: Option<String>,
115
116 #[pyo3(get)]
118 pub first_acquisition: String,
119
120 #[pyo3(get)]
122 pub malicious: Option<bool>,
123}
124
125#[pymethods]
126impl Source {
127 #[must_use]
129 pub fn __repr__(&self) -> String {
130 let url = if let Some(url) = &self.url {
131 format!(" from {url}")
132 } else {
133 String::new()
134 };
135
136 let desc = if let Some(desc) = &self.description {
137 format!(" -- {desc}")
138 } else {
139 String::new()
140 };
141
142 format!("{}({}){url}{desc}", self.name, self.id)
143 }
144
145 #[must_use]
147 pub fn __str__(&self) -> String {
148 self.name.clone()
149 }
150}
151
152#[pyclass(frozen)]
154#[derive(Debug, Clone)]
155pub struct SupportedFileType {
156 #[pyo3(get)]
158 pub name: String,
159
160 #[pyo3(get)]
162 pub magic: Vec<String>,
163
164 #[pyo3(get)]
166 pub is_executable: bool,
167
168 #[pyo3(get)]
170 pub description: Option<String>,
171}
172
173#[pymethods]
174impl SupportedFileType {
175 #[must_use]
177 pub fn __repr__(&self) -> String {
178 format!("{}, starting with {}", self.name, self.magic.join(" or "))
179 }
180
181 #[must_use]
183 pub fn __str__(&self) -> String {
184 self.name.clone()
185 }
186}
187
188#[pyclass(frozen)]
190#[derive(Debug, Clone)]
191pub struct UserInfo {
192 #[pyo3(get)]
194 pub id: u32,
195
196 #[pyo3(get)]
198 pub username: String,
199
200 #[pyo3(get)]
202 pub groups: Vec<String>,
203
204 #[pyo3(get)]
206 pub sources: Vec<String>,
207
208 #[pyo3(get)]
210 pub is_admin: bool,
211
212 #[pyo3(get)]
214 pub created: String,
215
216 #[pyo3(get)]
218 pub is_readonly: bool,
219}
220
221#[pymethods]
222impl UserInfo {
223 #[must_use]
225 pub fn __str__(&self) -> String {
226 self.username.clone()
227 }
228}