keepass_ng/db/types/
meta.rs1use chrono::NaiveDateTime;
2use std::collections::HashMap;
3use uuid::Uuid;
4
5use crate::db::{Color, CustomDataItem, CustomIcon};
6
7#[derive(Debug, Default, Eq, PartialEq, Clone)]
9#[cfg_attr(feature = "serialization", derive(serde::Serialize))]
10pub struct Meta {
11 pub generator: Option<String>,
13
14 pub database_name: Option<String>,
16
17 pub database_name_changed: Option<NaiveDateTime>,
19
20 pub database_description: Option<String>,
22
23 pub database_description_changed: Option<NaiveDateTime>,
25
26 pub(crate) custom_icons: HashMap<Uuid, CustomIcon>,
28
29 pub default_username: Option<String>,
31
32 pub default_username_changed: Option<NaiveDateTime>,
34
35 pub maintenance_history_days: Option<usize>,
37
38 pub color: Option<Color>,
40
41 pub master_key_changed: Option<NaiveDateTime>,
43
44 pub master_key_change_rec: Option<isize>,
45
46 pub master_key_change_force: Option<isize>,
47
48 pub memory_protection: Option<MemoryProtection>,
50
51 pub(crate) recyclebin_enabled: Option<bool>,
53
54 pub(crate) recyclebin_uuid: Option<Uuid>,
56
57 pub(crate) recyclebin_changed: Option<NaiveDateTime>,
59
60 pub entry_templates_group: Option<Uuid>,
62
63 pub entry_templates_group_changed: Option<NaiveDateTime>,
65
66 pub last_selected_group: Option<Uuid>,
68
69 pub last_top_visible_group: Option<Uuid>,
71
72 pub history_max_items: Option<isize>,
74
75 pub history_max_size: Option<isize>,
77
78 pub settings_changed: Option<NaiveDateTime>,
80
81 pub custom_data: HashMap<String, CustomDataItem>,
83}
84
85impl Meta {
86 pub fn new() -> Self {
88 Self {
89 recyclebin_enabled: Some(true),
90 ..Meta::default()
91 }
92 }
93
94 pub fn custom_icon(&self, uuid: Uuid) -> Option<&CustomIcon> {
95 self.custom_icons.get(&uuid)
96 }
97
98 pub fn set_recycle_bin_enabled(&mut self, enabled: bool) {
100 self.recyclebin_enabled = Some(enabled);
101 self.set_recycle_bin_changed();
102 }
103
104 pub fn recycle_bin_enabled(&self) -> bool {
105 self.recyclebin_enabled.unwrap_or(false)
106 }
107
108 pub fn recycle_bin_changed(&self) -> Option<NaiveDateTime> {
109 self.recyclebin_changed
110 }
111
112 pub fn set_recycle_bin_changed(&mut self) {
114 let time = chrono::Local::now().naive_local();
115 self.recyclebin_changed = Some(time);
116 }
117}
118
119#[derive(Debug, PartialEq, Eq, Clone)]
121#[cfg_attr(feature = "serialization", derive(serde::Serialize))]
122pub struct MemoryProtection {
123 pub protect_title: bool,
125
126 pub protect_username: bool,
128
129 pub protect_password: bool,
131
132 pub protect_url: bool,
134
135 pub protect_notes: bool,
137}
138
139impl Default for MemoryProtection {
140 fn default() -> Self {
141 Self {
142 protect_title: false,
143 protect_username: false,
144 protect_password: true,
145 protect_url: false,
146 protect_notes: false,
147 }
148 }
149}