Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
duckdb::MainHeader Class Reference

#include <duckdb.hpp>

Public Member Functions

string LibraryGitDesc ()
string LibraryGitHash ()
bool IsEncrypted () const
void SetEncrypted ()
void SetEncryptionVersion (uint8_t version)
void SetEncryptionMetadata (data_ptr_t source)
uint8_t GetEncryptionCipher () const
uint8_t GetEncryptionVersion () const
void SetDBIdentifier (data_ptr_t source)
void SetEncryptedCanary (data_ptr_t source)
void SetCanaryIV (data_ptr_t source)
void SetCanaryTag (data_ptr_t source)
data_ptr_t GetDBIdentifier ()
data_ptr_t GetIV ()
data_ptr_t GetTag ()
data_ptr_t GetEncryptedCanary ()
void Write (WriteStream &ser)

Static Public Member Functions

static void CheckMagicBytes (QueryContext context, FileHandle &handle)
static bool CompareDBIdentifiers (const data_ptr_t db_identifier_1, const data_ptr_t db_identifier_2)
static MainHeader Read (ReadStream &source)

Public Attributes

uint64_t version_number
 The (storage) version of the database.
uint64_t flags [FLAG_COUNT]
 The set of flags used by the database.
uint8_t encryption_version
 Encryption version.

Static Public Attributes

static constexpr idx_t MAX_VERSION_SIZE = 32
static constexpr idx_t MAGIC_BYTE_SIZE = 4
static constexpr idx_t MAGIC_BYTE_OFFSET = Storage::DEFAULT_BLOCK_HEADER_SIZE
static constexpr idx_t FLAG_COUNT = 4
static constexpr uint64_t ENCRYPTED_DATABASE_FLAG = 1
 Indicates whether database is encrypted or not.
static constexpr uint64_t DEFAULT_ENCRYPTION_KEY_LENGTH = 32
 The encryption key length.
static const char MAGIC_BYTES [] = "DUCK"
 The magic bytes in front of the file should be "DUCK".
static const char CANARY [] = "DUCKKEY"
 The canary should be "DUCKKEY".
static constexpr idx_t DB_IDENTIFIER_LEN = 16
 The length of the unique database identifier.
static constexpr idx_t ENCRYPTION_METADATA_LEN = 8
 Optional metadata for encryption, if encryption flag is set.
static constexpr idx_t CANARY_BYTE_SIZE = 8
 The canary is a known plaintext for detecting wrong keys early.
static constexpr uint64_t AES_NONCE_LEN = 12
 Nonce, IV (nonce + counter) and tag length.
static constexpr uint64_t AES_COUNTER_BYTES = 4
static constexpr uint64_t AES_NONCE_LEN_DEPRECATED = 16
static constexpr uint64_t AES_IV_LEN = 16
static constexpr uint64_t AES_TAG_LEN = 16

Private Attributes

data_t library_git_desc [MAX_VERSION_SIZE]
data_t library_git_hash [MAX_VERSION_SIZE]
data_t encryption_metadata [ENCRYPTION_METADATA_LEN]
data_t db_identifier [DB_IDENTIFIER_LEN]
 The unique database identifier and optional encryption salt.
data_t encrypted_canary [CANARY_BYTE_SIZE]
data_t canary_iv [AES_NONCE_LEN]
data_t canary_tag [AES_TAG_LEN]

Detailed Description

The MainHeader is the first header in the storage file. It is written only once for a database file.

Member Function Documentation

◆ CheckMagicBytes()

void duckdb::MainHeader::CheckMagicBytes ( QueryContext context,
FileHandle & handle )
static
420439 {
420440 data_t magic_bytes[MAGIC_BYTE_SIZE];
420441 if (handle.GetFileSize() < MainHeader::MAGIC_BYTE_SIZE + MainHeader::MAGIC_BYTE_OFFSET) {
420442 throw IOException("The file \"%s\" exists, but it is not a valid DuckDB database file!", handle.path);
420443 }
420444 handle.Read(context, magic_bytes, MainHeader::MAGIC_BYTE_SIZE, MainHeader::MAGIC_BYTE_OFFSET);
420445 if (memcmp(magic_bytes, MainHeader::MAGIC_BYTES, MainHeader::MAGIC_BYTE_SIZE) != 0) {
420446 throw IOException("The file \"%s\" exists, but it is not a valid DuckDB database file!", handle.path);
420447 }
420448}
static const char MAGIC_BYTES[]
The magic bytes in front of the file should be "DUCK".
Definition duckdb.hpp:9751
uint8_t data_t
data pointers
Definition duckdb.hpp:246

◆ LibraryGitDesc()

string duckdb::MainHeader::LibraryGitDesc ( )
inline
9777 {
9778 return string(char_ptr_cast(library_git_desc), 0, MAX_VERSION_SIZE);
9779 }

◆ LibraryGitHash()

string duckdb::MainHeader::LibraryGitHash ( )
inline
9780 {
9781 return string(char_ptr_cast(library_git_hash), 0, MAX_VERSION_SIZE);
9782 }

◆ IsEncrypted()

bool duckdb::MainHeader::IsEncrypted ( ) const
inline
9784 {
9786 }
static constexpr uint64_t ENCRYPTED_DATABASE_FLAG
Indicates whether database is encrypted or not.
Definition duckdb.hpp:9747
uint64_t flags[FLAG_COUNT]
The set of flags used by the database.
Definition duckdb.hpp:9758

◆ SetEncrypted()

void duckdb::MainHeader::SetEncrypted ( )
inline
9787 {
9789 }

◆ SetEncryptionVersion()

void duckdb::MainHeader::SetEncryptionVersion ( uint8_t version)
inline
9790 {
9791 encryption_version = version;
9792 }
uint8_t encryption_version
Encryption version.
Definition duckdb.hpp:9760

◆ SetEncryptionMetadata()

void duckdb::MainHeader::SetEncryptionMetadata ( data_ptr_t source)
inline
9794 {
9795 memset(encryption_metadata, 0, ENCRYPTION_METADATA_LEN);
9796 memcpy(encryption_metadata, source, ENCRYPTION_METADATA_LEN);
9797 }
static constexpr idx_t ENCRYPTION_METADATA_LEN
Optional metadata for encryption, if encryption flag is set.
Definition duckdb.hpp:9765

◆ GetEncryptionCipher()

uint8_t duckdb::MainHeader::GetEncryptionCipher ( ) const
inline
9799 {
9800 return encryption_metadata[2];
9801 }

◆ GetEncryptionVersion()

uint8_t duckdb::MainHeader::GetEncryptionVersion ( ) const
inline
9803 {
9804 return encryption_metadata[3];
9805 }

◆ SetDBIdentifier()

void duckdb::MainHeader::SetDBIdentifier ( data_ptr_t source)
inline
9807 {
9808 memset(db_identifier, 0, DB_IDENTIFIER_LEN);
9809 memcpy(db_identifier, source, DB_IDENTIFIER_LEN);
9810 }
data_t db_identifier[DB_IDENTIFIER_LEN]
The unique database identifier and optional encryption salt.
Definition duckdb.hpp:9860
static constexpr idx_t DB_IDENTIFIER_LEN
The length of the unique database identifier.
Definition duckdb.hpp:9763

◆ SetEncryptedCanary()

void duckdb::MainHeader::SetEncryptedCanary ( data_ptr_t source)
inline
9812 {
9813 memset(encrypted_canary, 0, CANARY_BYTE_SIZE);
9814 memcpy(encrypted_canary, source, CANARY_BYTE_SIZE);
9815 }
static constexpr idx_t CANARY_BYTE_SIZE
The canary is a known plaintext for detecting wrong keys early.
Definition duckdb.hpp:9767

◆ SetCanaryIV()

void duckdb::MainHeader::SetCanaryIV ( data_ptr_t source)
inline
9817 {
9818 memset(canary_iv, 0, AES_NONCE_LEN);
9819 memcpy(canary_iv, source, AES_NONCE_LEN);
9820 }
static constexpr uint64_t AES_NONCE_LEN
Nonce, IV (nonce + counter) and tag length.
Definition duckdb.hpp:9769

◆ SetCanaryTag()

void duckdb::MainHeader::SetCanaryTag ( data_ptr_t source)
inline
9822 {
9823 memset(canary_tag, 0, AES_TAG_LEN);
9824 memcpy(canary_tag, source, AES_TAG_LEN);
9825 }

◆ GetDBIdentifier()

data_ptr_t duckdb::MainHeader::GetDBIdentifier ( )
inline
9827 {
9828 return db_identifier;
9829 }

◆ GetIV()

data_ptr_t duckdb::MainHeader::GetIV ( )
inline
9831 {
9832 return canary_iv;
9833 }

◆ GetTag()

data_ptr_t duckdb::MainHeader::GetTag ( )
inline
9835 {
9836 return canary_tag;
9837 }

◆ CompareDBIdentifiers()

bool duckdb::MainHeader::CompareDBIdentifiers ( const data_ptr_t db_identifier_1,
const data_ptr_t db_identifier_2 )
inlinestatic
9839 {
9840 for (idx_t i = 0; i < DB_IDENTIFIER_LEN; i++) {
9841 if (db_identifier_1[i] != db_identifier_2[i]) {
9842 return false;
9843 }
9844 }
9845 return true;
9846 }
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

◆ GetEncryptedCanary()

data_ptr_t duckdb::MainHeader::GetEncryptedCanary ( )
inline
9848 {
9849 return encrypted_canary;
9850 }

◆ Write()

void duckdb::MainHeader::Write ( WriteStream & ser)
420420 {
420421 ser.WriteData(const_data_ptr_cast(MAGIC_BYTES), MAGIC_BYTE_SIZE);
420422 ser.Write<uint64_t>(version_number);
420423 for (idx_t i = 0; i < FLAG_COUNT; i++) {
420424 ser.Write<uint64_t>(flags[i]);
420425 }
420426
420427 SerializeVersionNumber(ser, DuckDB::LibraryVersion());
420428 SerializeVersionNumber(ser, DuckDB::SourceID());
420429
420430 // We always serialize, and write zeros, if not set.
420431 auto encryption_enabled = IsEncrypted();
420432 SerializeEncryptionMetadata(ser, encryption_metadata, encryption_enabled);
420433 SerializeDBIdentifier(ser, db_identifier);
420434 SerializeEncryptionMetadata(ser, encrypted_canary, encryption_enabled);
420435 SerializeIV(ser, canary_iv, encryption_enabled);
420436 SerializeTag(ser, canary_tag, encryption_enabled);
420437}
uint64_t version_number
The (storage) version of the database.
Definition duckdb.hpp:9756
::uint64_t uint64_t

◆ Read()

MainHeader duckdb::MainHeader::Read ( ReadStream & source)
static
420450 {
420451 data_t magic_bytes[MAGIC_BYTE_SIZE];
420452
420453 MainHeader header;
420454 source.ReadData(magic_bytes, MainHeader::MAGIC_BYTE_SIZE);
420455 if (memcmp(magic_bytes, MainHeader::MAGIC_BYTES, MainHeader::MAGIC_BYTE_SIZE) != 0) {
420456 throw IOException("The file is not a valid DuckDB database file!");
420457 }
420458
420459 header.version_number = source.Read<uint64_t>();
420460
420461 // Check the version number to determine if we can read this file.
420462 if (header.version_number < VERSION_NUMBER_LOWER || header.version_number > VERSION_NUMBER_UPPER) {
420463 auto version = GetDuckDBVersions(header.version_number);
420464 string version_text;
420465 if (!version.empty()) {
420466 // Known version.
420467 version_text = "DuckDB version " + string(version);
420468 } else {
420469 version_text = string("an ") +
420470 (VERSION_NUMBER_UPPER > header.version_number ? "older development" : "newer") +
420471 string(" version of DuckDB");
420472 }
420473 throw IOException(
420474 "Trying to read a database file with version number %lld, but we can only read versions between %lld and "
420475 "%lld.\n"
420476 "The database file was created with %s.\n\n"
420477 "Newer DuckDB version might introduce backward incompatible changes (possibly guarded by compatibility "
420478 "settings).\n"
420479 "See the storage page for migration strategy and more information: https://duckdb.org/internals/storage",
420480 header.version_number, VERSION_NUMBER_LOWER, VERSION_NUMBER_UPPER, version_text);
420481 }
420482
420483 // Read the flags.
420484 for (idx_t i = 0; i < FLAG_COUNT; i++) {
420485 header.flags[i] = source.Read<uint64_t>();
420486 }
420487 DeserializeVersionNumber(source, header.library_git_desc);
420488 DeserializeVersionNumber(source, header.library_git_hash);
420489
420490 // We always deserialize, and read zeros, if not set.
420491 DeserializeEncryptionData(source, header.encryption_metadata, MainHeader::ENCRYPTION_METADATA_LEN);
420492 DeserializeEncryptionData(source, header.db_identifier, MainHeader::DB_IDENTIFIER_LEN);
420493 DeserializeEncryptionData(source, header.encrypted_canary, MainHeader::CANARY_BYTE_SIZE);
420494 DeserializeEncryptionData(source, header.canary_iv, MainHeader::AES_NONCE_LEN);
420495 DeserializeEncryptionData(source, header.canary_tag, MainHeader::AES_TAG_LEN);
420496
420497 return header;
420498}

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