decrypt_cookies/browser/
mod.rs

1pub mod cookies;
2pub mod info;
3
4use strum::{AsRefStr, Display, EnumIter, EnumProperty, EnumString, IntoEnumIterator};
5
6#[derive(Clone, Copy)]
7#[derive(PartialEq, Eq, PartialOrd, Ord)]
8#[derive(Default)]
9#[derive(Debug)]
10#[derive(EnumIter, Display, EnumString, AsRefStr, strum::EnumProperty)]
11pub enum Browser {
12    /// win, mac, Linux
13    #[default]
14    #[strum(ascii_case_insensitive, props(Based = "firefox"))]
15    Firefox,
16    /// win, mac, Linux
17    #[strum(ascii_case_insensitive, props(Based = "firefox"))]
18    Librewolf,
19
20    /// win, mac, Linux
21    #[strum(ascii_case_insensitive, props(Based = "chromium"))]
22    Chrome,
23    /// win, mac, Linux
24    #[strum(ascii_case_insensitive, props(Based = "chromium"))]
25    Edge,
26    /// win, mac, Linux
27    #[strum(ascii_case_insensitive, props(Based = "chromium"))]
28    Chromium,
29    /// win, mac, Linux
30    #[strum(ascii_case_insensitive, props(Based = "chromium"))]
31    Brave,
32    /// win, mac, Linux
33    #[strum(ascii_case_insensitive, props(Based = "chromium"))]
34    Yandex,
35    /// win, mac, Linux
36    #[strum(ascii_case_insensitive, props(Based = "chromium"))]
37    Vivaldi,
38    /// win, mac, Linux
39    #[strum(ascii_case_insensitive, props(Based = "chromium"))]
40    Opera,
41    /// win, mac
42    #[cfg(not(target_os = "linux"))]
43    #[strum(ascii_case_insensitive, props(Based = "chromium"))]
44    OperaGX,
45    /// win, mac
46    #[cfg(not(target_os = "linux"))]
47    #[strum(ascii_case_insensitive, props(Based = "chromium"))]
48    CocCoc,
49    /// win, mac, ?
50    // #[cfg(not(target_os = "linux"))]
51    #[cfg(target_os = "macos")]
52    #[strum(ascii_case_insensitive, props(Based = "chromium"))]
53    Arc,
54
55    /// mac
56    #[cfg(target_os = "macos")]
57    #[strum(ascii_case_insensitive, props(Based = "safari"))]
58    Safari,
59}
60
61impl Browser {
62    pub fn is_chromium_base(self) -> bool {
63        self.get_str("Based")
64            .map_or(false, |base| base.eq_ignore_ascii_case("chromium"))
65    }
66    pub fn is_firefox_base(self) -> bool {
67        self.get_str("Based")
68            .map_or(false, |base| base.eq_ignore_ascii_case("firefox"))
69    }
70    /// return Based chromium browser iterator
71    pub fn chromiums() -> impl Iterator<Item = Self> {
72        Self::iter().filter(|v| {
73            v.get_str("Based")
74                .map_or(false, |base| base.eq_ignore_ascii_case("chromium"))
75        })
76    }
77    /// return Based firefox browser iterator
78    pub fn firefoxs() -> impl Iterator<Item = Self> {
79        Self::iter().filter(|v| {
80            v.get_str("Based")
81                .map_or(false, |base| base.eq_ignore_ascii_case("firefox"))
82        })
83    }
84}
85
86impl Browser {
87    /// for fetch password
88    #[cfg(target_os = "macos")]
89    pub const fn safe_name(&self) -> &str {
90        match self {
91            Self::Chromium => "Chromium",
92            Self::Chrome => "Chrome",
93            Self::Edge => "Microsoft Edge",
94            Self::Brave => "Brave",
95            Self::Yandex => "Yandex",
96            Self::Vivaldi => "Vivaldi",
97            Self::Opera => "Opera",
98            #[cfg(not(target_os = "linux"))]
99            Self::OperaGX => "Opera",
100            #[cfg(not(target_os = "linux"))]
101            Self::CocCoc => "CocCoc",
102            #[cfg(not(target_os = "linux"))]
103            Self::Arc => "Arc",
104            _ => "Chrome",
105        }
106    }
107
108    /// for fetch password
109    #[cfg(not(target_os = "windows"))]
110    pub const fn storage(&self) -> &str {
111        match self {
112            Self::Chromium => concat!("Chromium", " Safe Storage"),
113            Self::Chrome => concat!("Chrome", " Safe Storage"),
114            Self::Edge => concat!("Microsoft Edge", " Safe Storage"),
115            Self::Brave => concat!("Brave", " Safe Storage"),
116            Self::Yandex => concat!("Yandex", " Safe Storage"),
117            Self::Vivaldi => concat!("Vivaldi", " Safe Storage"),
118            Self::Opera => concat!("Opera", " Safe Storage"),
119            #[cfg(not(target_os = "linux"))]
120            Self::OperaGX => concat!("Opera", " Safe Storage"),
121            #[cfg(not(target_os = "linux"))]
122            Self::CocCoc => concat!("CocCoc", " Safe Storage"),
123            #[cfg(not(target_os = "linux"))]
124            Self::Arc => concat!("Arc", " Safe Storage"),
125            _ => concat!("Chrome", " Safe Storage"),
126        }
127    }
128}