Expand description
Library for reading and writing KeePass 2 and KeePassX databases.
§Usage
To use this crate, add the following to your Cargo.toml:
[dependencies]
rust-kpdb = "0.5"And the following to your crate root:
extern crate kpdb;§Examples
Create a new database adding two groups and two entries:
use kpdb::{CompositeKey, Database, Entry, Group};
// Create a new database.
let key = CompositeKey::from_password("password");
let mut db = Database::new(&key);
// Create a new group named Email.
let mut email_group = Group::new("Email");
let email_group_uuid = email_group.uuid;
// Create an entry for ProtonMail and add it to the Email group.
let mut protonmail = Entry::new();
let protonmail_uuid = protonmail.uuid;
protonmail.set_title("ProtonMail");
protonmail.set_username("mailuser");
protonmail.set_password("mailpass");
protonmail.set_url("https://mail.protonmail.com");
email_group.add_entry(protonmail);
// Create a new group named VPN.
let mut vpn_group = Group::new("VPN");
// Create an entry for ProtonVPN and add it to the VPN group.
let mut protonvpn = Entry::new();
protonvpn.set_title("ProtonVPN");
protonvpn.set_username("vpnuser");
protonvpn.set_password("vpnpass");
protonvpn.set_url("https://prontvpn.com");
vpn_group.add_entry(protonvpn);
// Add the Email and VPN groups to the Root group.
db.root_group.add_group(email_group);
db.root_group.add_group(vpn_group);
// Find groups matching "email".
let groups = db.find_groups("email");
assert_eq!(groups.len(), 1);
// Find entries matching "proton".
let entries = db.find_entries("proton");
assert_eq!(entries.len(), 2);
// Retrieve a group by its UUID.
let group = db.get_group(email_group_uuid).unwrap();
assert_eq!(group.name, "Email");
// Retrieve an entry by its UUID.
let entry = db.get_entry(protonmail_uuid).unwrap();
assert_eq!(entry.title(), Some("ProtonMail"));
assert_eq!(entry.username(), Some("mailuser"));
assert_eq!(entry.password(), Some("mailpass"));
assert_eq!(entry.url(), Some("https://mail.protonmail.com"));
assert_eq!(entry.notes(), None);Open the existing KeePass database passwords.kdbx using the password “password”, print it and save it to new.kdbx:
use kpdb::{CompositeKey, Database};
use std::fs::File;
let mut file = File::open("passwords.kdbx").unwrap();
let key = CompositeKey::from_password("password");
let db = Database::open(&mut file, &key).unwrap();
println!("{:?}", db);
let mut file = File::create("new.kdbx").unwrap();
db.save(&mut file).unwrap();Open the existing KeePass database passwords.kdbx using both the password “password” and the key file passwords.key, print it and save it to new.kdbx:
use kpdb::{CompositeKey, Database, KeyFile};
use std::fs::File;
let mut file = File::open("passwords.key").unwrap();
let key_file = KeyFile::open(&mut file).unwrap();
let key = CompositeKey::from_both("password", key_file);
let mut file = File::open("passwords.kdbx").unwrap();
let db = Database::open(&mut file, &key).unwrap();
println!("{:?}", db);
let mut file = File::create("new.kdbx").unwrap();
db.save(&mut file).unwrap();§Not Implemented
The following features are currently not implemented:
- KeePass 1 databases.
 
Structs§
- Association
 - An auto-type association.
 - Binary
Id  - An identifier for binaries in the global binaries map.
 - Binary
Key  - A key for binaries in entry’s binaries map.
 - Color
 - A structure representing a color (RGB).
 - Comment
 - The binary comment header from the database file.
 - Composite
Key  - Composition of the user’s key data.
 - Custom
Icon Uuid  - The identifier for a custom icon.
 - Database
 - The KeePass database.
 - Entry
 - An entry in the database.
 - Entry
Uuid  - The identifier for an entry.
 - Group
 - A group in the database.
 - Group
Uuid  - The identifier for a group.
 - KeyFile
 - A key file used for encrypting and decrypting the database.
 - Transform
Rounds  - Number of times the composite key must be transformed.
 - Version
 - The database version.
 
Enums§
- Binary
Value  - A value for entry’s map with binaries.
 - Color
Error  - Error type for color conversion errors.
 - Compression
 - The compression algorithm.
 - DbType
 - The database type.
 - Error
 - Error type for database errors.
 - Icon
 - The icon of an entry or group.
 - Icon
Error  - Error type for icon conversion errors.
 - KeyFile
Type  - The type of the key file.
 - Master
Cipher  - The encryption algorithm for the master data.
 - Obfuscation
 - The type of obfuscation to use.
 - Obfuscation
Error  - Error type for obfuscation conversion errors.
 - Stream
Cipher  - The encryption algorithm for the stream data (e.g. passwords).
 - String
Key  - A key for the map with strings.
 - String
Value  - A value for the map with strings.
 
Traits§
- Times
 - Trait for getting and setting of time related data.
 
Type Aliases§
- Binaries
Map  - A type alias for the global map with binaries.
 - Custom
Data Map  - A type alias for a map with custom data.
 - Custom
Icons Map  - A type alias for a map with custom icons.
 - Result
 - A specialized result type for database operations.
 - Strings
Map  - A type alias for the map with strings.