keepass_ng/db/
meta.rs

1use chrono::NaiveDateTime;
2use uuid::Uuid;
3
4use crate::db::{Color, CustomData};
5
6/// Database metadata
7#[derive(Debug, Default, Eq, PartialEq, Clone)]
8#[cfg_attr(feature = "serialization", derive(serde::Serialize))]
9pub struct Meta {
10    /// the program that generated the database file.
11    pub generator: Option<String>,
12
13    /// name of the database
14    pub database_name: Option<String>,
15
16    /// time the database name was last changed
17    pub database_name_changed: Option<NaiveDateTime>,
18
19    /// description of the database
20    pub database_description: Option<String>,
21
22    /// time the database description was last changed
23    pub database_description_changed: Option<NaiveDateTime>,
24
25    /// default username
26    pub default_username: Option<String>,
27
28    /// time the default username was last changed
29    pub default_username_changed: Option<NaiveDateTime>,
30
31    /// number of days of maintenance history to keep
32    pub maintenance_history_days: Option<usize>,
33
34    /// color code for the database
35    pub color: Option<Color>,
36
37    /// time the master key was last changed
38    pub master_key_changed: Option<NaiveDateTime>,
39
40    pub master_key_change_rec: Option<isize>,
41
42    pub master_key_change_force: Option<isize>,
43
44    /// memory protection settings
45    pub memory_protection: Option<MemoryProtection>,
46
47    /// custom icons
48    pub custom_icons: CustomIcons,
49
50    /// whether the recycle bin is enabled
51    pub(crate) recyclebin_enabled: Option<bool>,
52
53    /// A UUID for the recycle bin group
54    pub(crate) recyclebin_uuid: Option<Uuid>,
55
56    /// last time the recycle bin was changed
57    pub(crate) recyclebin_changed: Option<NaiveDateTime>,
58
59    /// UUID of the group containing entry templates
60    pub entry_templates_group: Option<Uuid>,
61
62    /// last time the group containing entry templates was changed
63    pub entry_templates_group_changed: Option<NaiveDateTime>,
64
65    /// UUID of the last selected group
66    pub last_selected_group: Option<Uuid>,
67
68    /// UUID of the last top-visible group
69    pub last_top_visible_group: Option<Uuid>,
70
71    /// Maximum number of items of history to keep
72    pub history_max_items: Option<usize>,
73
74    /// Maximum size of the history to keep
75    pub history_max_size: Option<usize>,
76
77    /// Last time the settings were changed
78    pub settings_changed: Option<NaiveDateTime>,
79
80    /// Binary attachments in the Metadata header
81    pub binaries: BinaryAttachments,
82
83    /// Additional custom data fields
84    pub custom_data: CustomData,
85}
86
87impl Meta {
88    /// Create a new Meta object
89    pub fn new() -> Self {
90        Self {
91            recyclebin_enabled: Some(true),
92            ..Meta::default()
93        }
94    }
95
96    /// Set recycle bin enabled
97    pub fn set_recycle_bin_enabled(&mut self, enabled: bool) {
98        self.recyclebin_enabled = Some(enabled);
99        self.set_recycle_bin_changed();
100    }
101
102    pub fn recycle_bin_enabled(&self) -> bool {
103        self.recyclebin_enabled.unwrap_or(false)
104    }
105
106    pub fn recycle_bin_changed(&self) -> Option<NaiveDateTime> {
107        self.recyclebin_changed
108    }
109
110    /// Set recycle bin changed time
111    pub fn set_recycle_bin_changed(&mut self) {
112        let time = chrono::Local::now().naive_local();
113        self.recyclebin_changed = Some(time);
114    }
115}
116
117/// Database memory protection settings
118#[derive(Debug, PartialEq, Eq, Clone)]
119#[cfg_attr(feature = "serialization", derive(serde::Serialize))]
120pub struct MemoryProtection {
121    /// Whether titles should be protected
122    pub protect_title: bool,
123
124    /// Whether user names should be protected
125    pub protect_username: bool,
126
127    /// Whether passwords should be protected
128    pub protect_password: bool,
129
130    /// Whether URLs should be protected
131    pub protect_url: bool,
132
133    /// Whether notes should be protected
134    pub protect_notes: bool,
135}
136
137impl Default for MemoryProtection {
138    fn default() -> Self {
139        Self {
140            protect_title: false,
141            protect_username: false,
142            protect_password: true,
143            protect_url: false,
144            protect_notes: false,
145        }
146    }
147}
148
149/// Collection of custom icons
150#[derive(Debug, Default, PartialEq, Eq, Clone)]
151#[cfg_attr(feature = "serialization", derive(serde::Serialize))]
152pub struct CustomIcons {
153    pub icons: Vec<Icon>,
154}
155
156/// A custom icon
157#[derive(Debug, Default, PartialEq, Eq, Clone)]
158#[cfg_attr(feature = "serialization", derive(serde::Serialize))]
159pub struct Icon {
160    /// UUID, to reference the icon
161    pub uuid: Uuid,
162
163    /// Image data
164    pub data: Vec<u8>,
165}
166
167/// Collection of binary attachments in the metadata of an XML database
168#[derive(Debug, Default, PartialEq, Eq, Clone)]
169#[cfg_attr(feature = "serialization", derive(serde::Serialize))]
170pub struct BinaryAttachments {
171    pub binaries: Vec<BinaryAttachment>,
172}
173
174/// Binary attachment in the metadata of a XML database
175#[derive(Debug, Default, PartialEq, Eq, Clone)]
176#[cfg_attr(feature = "serialization", derive(serde::Serialize))]
177pub struct BinaryAttachment {
178    pub identifier: Option<String>,
179    pub compressed: bool,
180    pub content: Vec<u8>,
181}