Skip to main content

rustenium_identity/
identity.rs

1use serde::{Deserialize, Serialize};
2
3/// Top-level identity record. Serialises to/from the MongoDB document
4/// schema produced by persona_generator.py.
5#[derive(Debug, Clone, Serialize, Deserialize)]
6pub struct Identity {
7    pub id: Option<u64>,
8
9    /// None device_model implies desktop/laptop
10    pub device_model: Option<String>,
11    pub has_battery: bool,
12    pub has_mouse: bool,
13    pub has_touch: bool,
14
15    pub os: Os,
16    pub os_version: String,
17    pub platform: PlatformInfo,
18
19    pub browser: Browser,
20    /// e.g. [124, 0, 6367, 78]
21    pub browser_version: Vec<u16>,
22
23    pub screen: ScreenResolution,
24    pub hardware_concurrency: u8,
25    /// deviceMemory in GiB
26    pub memory: u8,
27    pub gpu: Gpu,
28
29    /// e.g. ["en-US", "en"]
30    pub language: Vec<String>,
31    pub history_count: Option<u16>,
32    /// Full URL with credentials, optional
33    pub proxy: Option<String>,
34    /// IANA timezone string. If None, fetched from ip-api.com via proxy.
35    pub timezone: Option<String>,
36}
37
38impl Identity {
39    /// Deserialize from a raw JSON string (MongoDB extended JSON).
40    pub fn from_json(s: &str) -> Result<Self, serde_json::Error> {
41        serde_json::from_str(s)
42    }
43
44    /// Deserialize from a BSON Document.
45    #[cfg(feature = "bson")]
46    pub fn from_bson(doc: bson::Document) -> Result<Self, bson::de::Error> {
47        bson::from_document(doc)
48    }
49}
50
51#[derive(Debug, Clone, Serialize, Deserialize)]
52pub struct PlatformInfo {
53    pub bitness: Option<String>,
54    pub architecture: Option<String>,
55    pub navigator_platform: NavigatorPlatform,
56    pub version: String,
57}
58
59#[derive(Debug, Clone, Serialize, Deserialize)]
60pub enum NavigatorPlatform {
61    #[serde(rename = "Win32")]
62    Win32,
63    #[serde(rename = "MacIntel")]
64    MacIntel,
65    #[serde(rename = "Linux x86_64")]
66    LinuxX86_64,
67    #[serde(rename = "Linux armv81")]
68    LinuxArmV81,
69    #[serde(rename = "iPhone")]
70    IPhone,
71    Other(String),
72}
73
74impl NavigatorPlatform {
75    pub fn as_str(&self) -> &str {
76        match self {
77            Self::Win32 => "Win32",
78            Self::MacIntel => "MacIntel",
79            Self::LinuxX86_64 => "Linux x86_64",
80            Self::LinuxArmV81 => "Linux armv81",
81            Self::IPhone => "iPhone",
82            Self::Other(s) => s.as_str(),
83        }
84    }
85}
86
87#[derive(Debug, Clone, Serialize, Deserialize)]
88pub struct ScreenResolution {
89    pub logical_width: u16,
90    pub logical_height: u16,
91    pub original_width: u16,
92    pub original_height: u16,
93    pub density_pixel_ratio: f32,
94}
95
96/// GPU identity — drives WebGL parameter spoofing.
97#[derive(Debug, Clone, Serialize, Deserialize)]
98pub struct Gpu {
99    pub vendor: String,
100    /// e.g. "ANGLE (NVIDIA GeForce RTX 3080...)"
101    pub webgl_renderer: String,
102    /// Exact UNMASKED_VENDOR_WEBGL string, e.g. "Google Inc. (NVIDIA)"
103    pub webgl_vendor: String,
104}
105
106#[derive(Debug, Clone, Serialize, Deserialize)]
107pub enum Os {
108    Windows,
109    Macintosh,
110    Linux,
111    Android,
112    Ios,
113}
114
115#[derive(Debug, Clone, Serialize, Deserialize)]
116#[serde(rename_all = "lowercase")]
117pub enum Browser {
118    Chrome,
119    Safari,
120    Edge,
121}