Skip to main content

Module db

Module db 

Source
Expand description

Types representing an opened KeePass database

The main entry point is the Database struct, which can be created with Database::new or loaded from a file using Database::open. The example uses explicit type annotations to show what is happening, but these can be omitted in your own code.

use keepass::{Database, db::{fields, AttachmentMut, EntryMut, GroupMut, Value}};
let mut db = Database::new();
let mut root: GroupMut<'_> = db.root_mut();

// Add a new child group to the root group
let mut group: GroupMut<'_> = root.add_group();

// GroupMut dereferences to &mut Group, so you can access most of its fields directly
group.name = "My Group".into();
group.notes = Some("This is an example group".into());

// Add a new entry to the group
let mut entry: EntryMut<'_> = root.add_entry();

// EntryMut dereferences to &mut Entry, so you can access most of its fields directly
entry.set_unprotected(fields::TITLE, "My Entry");
entry.set_unprotected(fields::USERNAME, "jdoe");
entry.set_protected(fields::PASSWORD, "hunter2");
entry.tags.push("example".into());

// Adding the attachment to an entry will store it in the associated database and add a
// reference to the entry.
entry.add_attachment("myfile.txt", Value::unprotected(b"Hello, world!".to_vec()));

// You can also use the fluent API to chain method calls together.
let entry_id = root.add_group()
    .edit(|g: &mut GroupMut| {
        g.name = "Another Group".into();
        g.notes = Some("This is another example group".into());
    })
    .add_entry()
    .edit(|e: &mut EntryMut<'_>| {
        e.set_unprotected(fields::TITLE, "Another Entry");
        e.set_unprotected(fields::USERNAME, "asmith");
        e.set_protected(fields::PASSWORD, "password123");
        e.tags.push("example".into());
    }).id();

Modules§

fields
Standard field names for entries.

Structs§

Attachment
Attachment for an entry.
AttachmentId
Identifier for an Attachment
AttachmentMut
A mutable reference to an Attachment. Implements DerefMut to &mut Attachment
AttachmentRef
An immutable reference to an Attachment. Implements Deref to &Attachment
AutoType
An AutoType setting associated with an Entry
AutoTypeAssociation
A window association associated with an AutoType setting
Color
A color value for the Database, or Entry
CustomDataItem
Custom data field for an Entry or Meta for database-wide custom data
CustomIcon
A custom icon stored in the database, containing raw image data.
CustomIconId
A unique identifier for a CustomIcon
CustomIconMut
A mutable reference to a CustomIcon. Implements DerefMut to &mut CustomIcon
CustomIconNotFoundError
Error type for when a CustomIconId is provided that does not exist in the database
CustomIconRef
An immutable reference to a CustomIcon. Implements Deref to &CustomIcon
Database
A decrypted KeePass database
DestinationGroupNotFoundError
Error type for when a destination GroupId is provided that does not exist in the database
DuplicateEntryIdError
Attempted to add an entry with an ID that already exists in the database.
DuplicateGroupIdError
Attempted to add a group with an ID that already exists in the database.
Entry
A database entry containing several key-value fields.
EntryId
Unique identifier for an Entry
EntryMut
A mutable reference to an Entry. Implements DerefMut to &mut Entry.
EntryRef
An immutable reference to an Entry. Implements Deref to &Entry.
EntryTrack
A variant of EntryMut that will persist the history of the entry when dropped.
Group
A database group with child groups and entries
GroupId
Unique identifier for a Group
GroupMut
Mutable reference to a Group. Implements DerefMut to &mut Group
GroupRef
Immutable reference to a Group. Implements Deref to &Group.
GroupTrack
A variant of GroupMut that tracks changes to the group, such as deletions and moves, and updates the location changed time when the group is moved.
History
An entry’s history
MemoryProtection
Database memory protection settings
Meta
Database metadata
ParseColorError
Error parsing a color code
Times
Timestamps for a Group or Entry

Enums§

CustomDataValue
Value of a CustomDataItem
DataTransferObfuscation
Obfuscation methods for auto-type data transfer.
DatabaseFormatError
Format-specific database parsing errors
DatabaseOpenError
Errors that can occur when opening a database
Icon
Icon specification for an Entry or Group.
MoveGroupError
Errors that can occur when moving a group to a new parent.
Value
Value in an Entry’s fields or an Attachment’s data