mod binaries;
mod entry;
mod xml;
pub use self::binaries::Binaries;
pub use self::entry::Entry;
pub use self::xml::Xml;
use crate::encryption::StreamCipher;
use crate::Result as KdbxResult;
use log::*;
#[derive(Debug)]
pub struct Database {
bin: Binaries,
xml: Xml,
cipher: StreamCipher,
}
impl Database {
#[allow(clippy::new_ret_no_self)]
pub(super) fn new(cipher: StreamCipher, xml: Xml, bin: Binaries) -> KdbxResult<Database> {
debug!("{:X?}", cipher);
debug!("{:?}", xml);
debug!("{:?}", bin);
xml.parse()?;
Ok(Database { cipher, xml, bin })
}
pub fn entries(&self) -> Vec<Entry> {
let mut entries = self.xml.parse().expect("Cannot parse XML");
for entry in &mut entries {
entry.database.set(Some(self));
}
entries
}
pub fn find<'a>(&'a self, title: &'a str) -> Vec<Entry<'a>> {
let title = title.to_lowercase();
self.entries()
.into_iter()
.filter(|e| e.title.to_lowercase().starts_with(&*title))
.collect()
}
}