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

Parses and serializes the outer header of a KDBX database. More...

#include <kdbx_header.hh>

Static Public Member Functions

static uint32_t ReadVersion (std::istream &src)
 Reads the file signatures and version prefix of a KDBX database.
 
static bool IsKdbx4 (uint32_t version)
 Returns whether version denotes a KDBX 4 database.
 
static std::array< uint8_t, 32 > Parse3 (std::istream &src, Database &db)
 Parses the KDBX 3 outer header fields into db.
 
static void Parse4 (std::istream &src, Database &db)
 Parses the KDBX 4 outer header fields into db.
 
static std::string Write3 (const Database &db, const std::array< uint8_t, 32 > &content_start_bytes)
 Serializes a KDBX 3 outer header.
 
static std::string Write4 (const Database &db, bool kdbx41)
 Serializes a KDBX 4 (or 4.1) outer header.
 

Static Public Attributes

static constexpr uint32_t kSignature0 = detail::kKdbxSignature0
 First magic value identifying a KDBX database.
 
static constexpr uint32_t kSignature1 = detail::kKdbxSignature1
 Second magic value identifying a KDBX database.
 
static constexpr uint32_t kVersionCriticalMask = detail::kKdbxVersionCriticalMask
 Mask selecting the critical (major) part of the version field.
 
static constexpr uint32_t kVersion3 = detail::kKdbxVersion3
 KDBX 3 critical version.
 
static constexpr uint32_t kVersion4 = detail::kKdbxVersion4
 KDBX 4 critical version.
 

Detailed Description

Parses and serializes the outer header of a KDBX database.

The outer header of a KDBX 3 and a KDBX 4 database differs in the field layout (16-bit vs. 32-bit field sizes, different field IDs) and in the stored parameters (KDBX 4 carries a KDF variant dictionary). This class hides those differences behind a version-dispatched interface; all state is kept in the Database that the header describes.

All operations are static: the class carries no per-instance state.

Member Function Documentation

◆ Parse3()

static std::array< uint8_t, 32 > keepass::KdbxHeader::Parse3 ( std::istream &  src,
Database &  db 
)
static

Parses the KDBX 3 outer header fields into db.

Reads and validates every header field of a KDBX 3 database and populates the corresponding settings (cipher, compression, seeds, init vector, inner random stream) on db.

Parameters
srcThe input stream positioned after the signature/version prefix.
dbThe database to populate with the parsed header settings.
Returns
The 32 content stream start bytes used to verify the decryption.
Exceptions
FormatErrorIf a header field is malformed or unknown.

◆ Parse4()

static void keepass::KdbxHeader::Parse4 ( std::istream &  src,
Database &  db 
)
static

Parses the KDBX 4 outer header fields into db.

Reads and validates every header field of a KDBX 4 database, including the KDF variant dictionary, and populates the corresponding settings on db.

Parameters
srcThe input stream positioned after the signature/version prefix.
dbThe database to populate with the parsed header settings.
Exceptions
FormatErrorIf a header field is malformed or unknown.

◆ ReadVersion()

static uint32_t keepass::KdbxHeader::ReadVersion ( std::istream &  src)
static

Reads the file signatures and version prefix of a KDBX database.

Verifies the two magic values and returns the raw version field of the database. The caller dispatches on the critical version bits.

Parameters
srcThe input stream positioned at the start of the database.
Returns
The version field (e.g. 0x00040001 for KDBX 4.1).
Exceptions
FormatErrorIf the stream does not start with a KDBX signature.

◆ Write3()

static std::string keepass::KdbxHeader::Write3 ( const Database &  db,
const std::array< uint8_t, 32 > &  content_start_bytes 
)
static

Serializes a KDBX 3 outer header.

Parameters
dbThe database whose settings to serialize.
content_start_bytesThe 32 randomly chosen content stream start bytes that KdbxFile embeds in the header.
Returns
The raw header bytes (fits a KDBX 3.1 critical version).

◆ Write4()

static std::string keepass::KdbxHeader::Write4 ( const Database &  db,
bool  kdbx41 
)
static

Serializes a KDBX 4 (or 4.1) outer header.

Parameters
dbThe database whose settings to serialize.
kdbx41True to write the KDBX 4.1 critical version (0x00040001).
Returns
The raw header bytes, without the trailing hash and HMAC values.

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