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::ChecksumWriter Class Reference
Inheritance diagram for duckdb::ChecksumWriter:
Collaboration diagram for duckdb::ChecksumWriter:

Public Member Functions

 ChecksumWriter (WriteAheadLog &wal)
void WriteData (const_data_ptr_t buffer, idx_t write_size) override
void Flush ()
void FlushEncrypted ()
WriteAheadLog & GetWAL ()
Public Member Functions inherited from duckdb::WriteStream
template<class T>
void Write (T element)

Private Attributes

WriteAheadLog & wal
optional_ptr< WriteStream > stream
MemoryStream memory_stream

Constructor & Destructor Documentation

◆ ChecksumWriter()

duckdb::ChecksumWriter::ChecksumWriter ( WriteAheadLog & wal)
inlineexplicit
445085 : wal(wal), memory_stream(Allocator::Get(wal.GetDatabase())) {
445086 }

Member Function Documentation

◆ WriteData()

void duckdb::ChecksumWriter::WriteData ( const_data_ptr_t buffer,
idx_t write_size )
inlineoverridevirtual

Implements duckdb::WriteStream.

445088 {
445089 // buffer data into the memory stream
445090 memory_stream.WriteData(buffer, write_size);
445091 }

◆ Flush()

void duckdb::ChecksumWriter::Flush ( )
inline
445093 {
445094 if (!stream) {
445095 stream = wal.Initialize();
445096 }
445097
445098 // if the config.encrypt WAL is true
445099 // and if the attached database is encrypted
445100 // then encrypt WAL before flushing
445101 auto &catalog = wal.GetDatabase().GetCatalog().Cast<DuckCatalog>();
445102
445103 if (catalog.GetIsEncrypted()) {
445104 return FlushEncrypted();
445105 }
445106
445107 auto data = memory_stream.GetData();
445108 auto size = memory_stream.GetPosition();
445109 // compute the checksum over the entry
445110 auto checksum = Checksum(data, size);
445111 // write the checksum and the length of the entry
445112 stream->Write<uint64_t>(size);
445113 stream->Write<uint64_t>(checksum);
445114 // write data to the underlying stream
445115 stream->WriteData(memory_stream.GetData(), memory_stream.GetPosition());
445116 // rewind the buffer
445117 memory_stream.Rewind();
445118 }
void FlushEncrypted()
Definition duckdb.cpp:445120
GOpaque< Size > size(const GMat &src)
::uint64_t uint64_t
uint64_t Checksum(uint8_t *buffer, size_t size)
Compute a checksum over a buffer of size size.
Definition duckdb.cpp:49970

◆ FlushEncrypted()

void duckdb::ChecksumWriter::FlushEncrypted ( )
inline

store the checksum in the temp buffer

checksum + entry in the temp buf

encrypt the temp buf

calculate the tag (for GCM)

445120 {
445121 auto &catalog = wal.GetDatabase().GetCatalog().Cast<DuckCatalog>();
445122 auto encryption_key_id = catalog.GetEncryptionKeyId();
445123
445124 auto data = memory_stream.GetData();
445125 auto size = memory_stream.GetPosition();
445126
445127 // compute the checksum over the entry
445128 auto checksum = Checksum(data, size);
445129
445130 auto &db = wal.GetDatabase();
445131 auto &keys = EncryptionKeyManager::Get(db.GetDatabase());
445132 auto metadata = make_uniq<EncryptionStateMetadata>(db.GetStorageManager().GetCipher(),
445134 EncryptionTypes::EncryptionVersion::V0_1);
445135 auto encryption_state =
445136 db.GetDatabase().GetEncryptionUtil(db.IsReadOnly())->CreateEncryptionState(std::move(metadata));
445137
445138 // temp buffer
445139 const idx_t ciphertext_size = size + sizeof(uint64_t);
445140 std::unique_ptr<uint8_t[]> temp_buf(new uint8_t[ciphertext_size]);
445141
445142 EncryptionNonce nonce(db.GetStorageManager().GetCipher(), db.GetStorageManager().GetEncryptionVersion());
445143 EncryptionTag tag;
445144
445145 // generate nonce
445146 encryption_state->GenerateRandomData(nonce.data(), nonce.size());
445147
445148 stream->Write<uint64_t>(size);
445149 stream->WriteData(nonce.data(), nonce.size());
445150
445152 memcpy(temp_buf.get(), &checksum, sizeof(checksum));
445154 memcpy(temp_buf.get() + sizeof(checksum), memory_stream.GetData(), memory_stream.GetPosition());
445155
445157 encryption_state->InitializeEncryption(nonce, keys.GetKey(encryption_key_id));
445158 encryption_state->Process(temp_buf.get(), ciphertext_size, temp_buf.get(), ciphertext_size);
445159
445161 encryption_state->Finalize(temp_buf.get(), ciphertext_size, tag.data(), tag.size());
445162
445163 // write data to the underlying stream
445164 stream->WriteData(temp_buf.get(), ciphertext_size);
445165
445166 // Write the tag to the stream
445167 if (encryption_state->GetCipher() == EncryptionTypes::CipherType::GCM) {
445168 D_ASSERT(!tag.IsAllZeros());
445169 stream->WriteData(tag.data(), tag.size());
445170 }
445171
445172 // rewind the buffer
445173 memory_stream.Rewind();
445174 }
static constexpr uint64_t DEFAULT_ENCRYPTION_KEY_LENGTH
The encryption key length.
Definition duckdb.hpp:9749
db
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237
Here is the call graph for this function:

◆ GetWAL()

WriteAheadLog & duckdb::ChecksumWriter::GetWAL ( )
inline
445176 {
445177 return wal;
445178 }

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