libkeepass 0.2.0
KeePass key database importer/exporter library
Loading...
Searching...
No Matches
keepass::Entry Class Referencefinal

A single KeePass entry (a username/password record). More...

#include <entry.hh>

Classes

class  Attachment
 A file attachment of an entry. More...
 
class  AutoType
 Keystroke-sending (auto-type) configuration for an entry. More...
 
class  Field
 An arbitrary custom string (key/value) field. More...
 

Public Member Functions

 Entry ()
 Creates an empty entry.
 
const std::array< uint8_t, 16 > & uuid () const
 Returns the entry's unique identifier (UUID).
 
void set_uuid (const std::array< uint8_t, 16 > &uuid)
 Sets the entry's unique identifier (UUID).
 
uint32_t icon () const
 Returns the index of the stock icon.
 
void set_icon (const uint32_t &icon)
 Sets the index of the stock icon.
 
std::weak_ptr< Icon > custom_icon () const
 Returns a weak reference to the custom icon (if any).
 
void set_custom_icon (std::weak_ptr< Icon > icon)
 Sets the custom icon.
 
const protect< secure_string > & title () const
 Returns the entry title.
 
void set_title (const protect< secure_string > &title)
 Sets the entry title.
 
const protect< secure_string > & url () const
 Returns the URL.
 
void set_url (const protect< secure_string > &url)
 Sets the URL.
 
const std::string & override_url () const
 Returns the override URL.
 
void set_override_url (const std::string &url)
 Sets the override URL.
 
const protect< secure_string > & username () const
 Returns the username.
 
void set_username (const protect< secure_string > &username)
 Sets the username.
 
const protect< secure_string > & password () const
 Returns the password.
 
void set_password (const protect< secure_string > &password)
 Sets the password.
 
const protect< secure_string > & notes () const
 Returns the notes.
 
void set_notes (const protect< secure_string > &notes)
 Sets the notes.
 
const std::string & tags () const
 Returns the tags (space-separated).
 
void set_tags (const std::string &tags)
 Sets the tags (space-separated).
 
bool quality_check () const
 Returns whether the password quality warning is enabled for this entry.
 
void set_quality_check (bool quality_check)
 Sets whether the password quality warning is enabled for this entry.
 
const std::optional< std::array< uint8_t, 16 > > & previous_parent_group () const
 Returns the UUID of the previous parent group (KDBX 4.1); empty if unset.
 
void set_previous_parent_group (const std::optional< std::array< uint8_t, 16 > > &uuid)
 
std::time_t creation_time () const
 Returns the creation time.
 
void set_creation_time (const std::time_t &time)
 Sets the creation time.
 
std::time_t modification_time () const
 Returns the last modification time.
 
void set_modification_time (const std::time_t &time)
 Sets the last modification time.
 
std::time_t access_time () const
 Returns the last access time.
 
void set_access_time (const std::time_t &time)
 Sets the last access time.
 
std::time_t expiry_time () const
 Returns the expiry time.
 
void set_expiry_time (const std::time_t &time)
 Sets the expiry time.
 
std::time_t move_time () const
 Returns the last move time.
 
void set_move_time (const std::time_t &time)
 Sets the last move time.
 
bool expires () const
 Returns whether the entry expires.
 
void set_expires (bool expires)
 Sets whether the entry expires.
 
uint32_t usage_count () const
 Returns the usage count.
 
void set_usage_count (uint32_t usage_count)
 Sets the usage count.
 
const std::string & bg_color () const
 Returns the background color.
 
void set_bg_color (const std::string &bg_color)
 Sets the background color.
 
const std::string & fg_color () const
 Returns the foreground color.
 
void set_fg_color (const std::string &fg_color)
 Sets the foreground color.
 
AutoType & auto_type ()
 Returns the auto-type configuration.
 
const std::vector< std::shared_ptr< Attachment > > & attachments () const
 Returns the list of attachments.
 
const std::vector< std::shared_ptr< Entry > > & history () const
 
const std::vector< Field > & custom_fields () const
 Returns the list of custom fields.
 
std::weak_ptr< Group > parent () const
 Returns the parent group (empty if this entry is not attached).
 
void set_parent (std::weak_ptr< Group > parent)
 Sets the parent group.
 
std::string path () const
 Returns the full path of this entry including its title.
 
std::map< std::string, std::string > custom_properties () const
 Returns the custom fields as a key/value map.
 
std::string GetString (const std::string &key) const
 Returns the value of the given string field.
 
bool HasString (const std::string &key) const
 Returns whether the given string field exists.
 
void set_custom_property (const std::string &key, const std::string &value)
 Sets a custom field, creating it if it does not exist.
 
void delete_custom_property (const std::string &key)
 Removes a custom field.
 
void set_binary_property (const std::string &name, const std::vector< uint8_t > &data)
 Sets (or replaces) a binary property (attachment) of this entry.
 
std::vector< uint8_t > get_binary_property (const std::string &name) const
 Returns the data of the binary property with the given name.
 
std::shared_ptr< Binary > FindAttachment (const std::string &name) const
 Returns the attachment object with the given name, or null if absent.
 
std::vector< std::string > attachment_names () const
 Returns the names of all attachments in attachment order.
 
bool HasAttachment (const std::string &name) const
 Returns whether an attachment with the given name exists.
 
void delete_binary_property (const std::string &name)
 Removes the binary property with the given name.
 
std::optional< TotpConfig > totp () const
 
std::string totp_code (std::time_t time=0) const
 Generates the current TOTP code from the entry's custom fields.
 
void save_history ()
 Saves a copy of the current state into the entry history.
 
void delete_history ()
 Clears the entry history.
 
void delete_old_history (std::size_t max_items)
 Removes the oldest history items, keeping at most max_items.
 
void delete_old_history (std::size_t max_items, std::size_t max_bytes)
 
void DeleteOldHistory (std::size_t max_items)
 Alias for delete_old_history(std::size_t) matching the KeePass API.
 
void touch (bool modify=false)
 Updates the last access time (and optionally the modification time).
 
void AddAttachment (const std::shared_ptr< Attachment > &attachment)
 Adds an attachment to the entry.
 
bool HasAttachment () const
 Returns whether the entry has at least one attachment.
 
void AddHistoryEntry (const std::shared_ptr< Entry > &entry)
 Adds a previous version of this entry to its history.
 
void AddCustomField (std::string &key, const protect< secure_string > &value)
 Adds a custom field with the given key and value.
 
bool HasNonDefaultAutoTypeSettings () const
 Returns whether the auto-type settings differ from the defaults.
 
bool IsMetaEntry () const
 Returns whether the entry is a KeePassX metadata entry.
 
std::string ToJson (bool include_attachments=false) const
 Serializes the entry to a JSON object.
 
bool operator== (const Entry &other) const
 Equality comparison.
 
bool operator!= (const Entry &other) const
 Inequality comparison.
 

Detailed Description

A single KeePass entry (a username/password record).

An Entry stores the standard fields of a password record (title, username, password, url, notes), timestamps, custom fields, attachments, auto-type configuration, and an entry history. Passwords and other sensitive fields are held in a memory-zeroing protect wrapper.

Member Function Documentation

◆ delete_old_history() [1/2]

void keepass::Entry::delete_old_history ( std::size_t  max_items)

Removes the oldest history items, keeping at most max_items.

History is ordered oldest first. A max_items value of zero clears the history entirely; use a large value (for example std::numeric_limits<std::size_t>::max()) to keep everything.

◆ delete_old_history() [2/2]

void keepass::Entry::delete_old_history ( std::size_t  max_items,
std::size_t  max_bytes 
)

Removes the oldest history items until at most max_items remain and the estimated serialized history size is at most max_bytes. The size estimate is based on each history item's JSON representation and is intended as a practical bound, not a byte-exact copy of KeePass's own accounting. Pass a large value to disable the byte limit.

◆ FindAttachment()

std::shared_ptr< Binary > keepass::Entry::FindAttachment ( const std::string &  name) const

Returns the attachment object with the given name, or null if absent.

Unlike get_binary_property this exposes the underlying Binary (including whether its data is empty), avoiding the ambiguity between an empty attachment and a missing one.

◆ GetString()

std::string keepass::Entry::GetString ( const std::string &  key) const

Returns the value of the given string field.

The standard fields Title, URL, UserName, Password and Notes are checked first; otherwise the custom fields are searched.

◆ history()

const std::vector< std::shared_ptr< Entry > > & keepass::Entry::history ( ) const
inline

Returns the list of historical (previous) versions of this entry. Returns the entry history (previous versions saved by save_history). The history is fully preserved during import/export but deliberately hidden from the kpx CLI print output (text/JSON/CSV) and the audit command. This keeps the day-to-day view clean; consumers who need history can call this API directly.

◆ set_previous_parent_group()

void keepass::Entry::set_previous_parent_group ( const std::optional< std::array< uint8_t, 16 > > &  uuid)
inline

Sets the UUID of the previous parent group (KDBX 4.1); pass std::nullopt to unset.

◆ ToJson()

std::string keepass::Entry::ToJson ( bool  include_attachments = false) const

Serializes the entry to a JSON object.

Parameters
include_attachmentsInclude attachment payloads as base64 (the default emits attachment names only).

◆ totp()

std::optional< TotpConfig > keepass::Entry::totp ( ) const

Returns the TOTP parameters stored in the otp/TOTP Seed/TOTP Settings custom fields, if present and valid.

◆ totp_code()

std::string keepass::Entry::totp_code ( std::time_t  time = 0) const

Generates the current TOTP code from the entry's custom fields.

Parameters
timeUnix time to use; 0 means the current system time.
Returns
The code, or an empty string if no valid TOTP seed is present.

The documentation for this class was generated from the following file: