-
Notifications
You must be signed in to change notification settings - Fork 0
Multiple changes to optimize and cleanup typed_buffers, BasicXorEncryptor, and Sequencer #231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 18 commits
1ddbed9
a997cce
f52a9e1
dec9c18
2d551a2
99d8c34
91b76db
fb0566f
971903a
097d919
6d8944d
44357ac
2d7689a
ccfb079
af827a0
55c9baa
3ad364d
f7c57e4
145f85c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,7 @@ _deps/ | |
|
|
||
| # macOS | ||
| .DS_Store | ||
| **/.!*.DS_Store | ||
|
|
||
| # Editor/IDE config | ||
| .vscode/ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,7 +23,6 @@ | |
| #include "../common/exceptions.h" | ||
| #include "encryptors/basic_xor_encryptor.h" | ||
| #include <functional> | ||
| #include <iomanip> | ||
| #include <iostream> | ||
| #include <sstream> | ||
| #include <optional> | ||
|
|
@@ -138,19 +137,20 @@ bool DataBatchEncryptionSequencer::DecodeAndEncrypt(tcb::span<const uint8_t> pla | |
| */ | ||
| try { | ||
| // Decompress and split plaintext into level and value bytes | ||
| auto [level_bytes, value_bytes] = DecompressAndSplit( | ||
| auto [level_bytes, value_bytes, num_elements] = DecompressAndSplit( | ||
| plaintext, compression_, encoding_attributes_converted_); | ||
|
|
||
| // Parse value bytes into typed values buffer | ||
| auto typed_buffer = ReinterpretValueBytesAsTypedValuesBuffer(value_bytes, datatype_, datatype_length_, encoding_); | ||
| auto typed_buffer = ReinterpretValueBytesAsTypedValuesBuffer( | ||
| value_bytes, num_elements, datatype_, datatype_length_, encoding_); | ||
|
|
||
| // Encrypt the typed values buffer and level bytes, then join them into a single encrypted byte vector. | ||
| auto encrypted_value_bytes = encryptor_->EncryptValueList(typed_buffer); | ||
| auto encrypted_level_bytes = encryptor_->EncryptBlock(level_bytes); | ||
| auto joined_encrypted_bytes = JoinWithLengthPrefix(encrypted_level_bytes, encrypted_value_bytes); | ||
|
|
||
| // Compress the joined encrypted bytes | ||
| encrypted_result_ = Compress(joined_encrypted_bytes, encrypted_compression_); | ||
|
|
||
| // Encrypted payloads mostly have a low-compression ratio, so the gains in size from compression are minimal or negative. | ||
| // Therefore, the final joined encrypted bytes are returned as-is without compression. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: this comment may end up generating more questions than answering them (i.e. the reviewers of the final version may not have context of the version where we did have compression). I'd suggest removing or rephrasing
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, removing it then. |
||
| encrypted_result_ = JoinWithLengthPrefix(encrypted_level_bytes, encrypted_value_bytes); | ||
|
|
||
| // Set the encryption type to per-value | ||
| encryption_metadata_[encryption_mode_key] = ENCRYPTION_MODE_PER_VALUE; | ||
|
|
@@ -226,16 +226,15 @@ bool DataBatchEncryptionSequencer::DecryptAndEncode(tcb::span<const uint8_t> cip | |
| error_message_ = "Failed to get encryption_mode from encryption_metadata"; | ||
| return false; | ||
| } | ||
| std::string encryption_mode = encryption_mode_opt.value(); | ||
| const std::string& encryption_mode = encryption_mode_opt.value(); | ||
|
|
||
| // Per-value encryption | ||
| if (encryption_mode == ENCRYPTION_MODE_PER_VALUE) { | ||
| // Decompress the encrypted bytes | ||
| auto decompressed_encrypted_bytes = Decompress(ciphertext, encrypted_compression_); | ||
|
|
||
|
|
||
| // Split the joined encrypted bytes, then decrypt the level and value bytes separately. | ||
| auto [encrypted_level_bytes, encrypted_value_bytes] = | ||
| SplitWithLengthPrefix(tcb::span<const uint8_t>(decompressed_encrypted_bytes)); | ||
| // The ciphertext payload is already the joined bytes without compression. | ||
| auto [encrypted_level_bytes, encrypted_value_bytes] = SplitWithLengthPrefix(ciphertext); | ||
|
|
||
| auto level_bytes = encryptor_->DecryptBlock(encrypted_level_bytes); | ||
| auto typed_buffer = encryptor_->DecryptValueList(encrypted_value_bytes); | ||
|
|
||
|
|
@@ -294,7 +293,7 @@ bool DataBatchEncryptionSequencer::ConvertEncodingAttributesToValues() { | |
| add_int("page_v2_num_nulls"); | ||
| add_bool("page_v2_is_compressed"); | ||
| } else if (page_type == "DICTIONARY_PAGE") { | ||
| // DICTIONARY_PAGE has no specific encoding attributes | ||
| add_int("dict_page_num_values"); | ||
| } else { | ||
| throw InvalidInputException("Unexpected page type: " + page_type); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should have a test for this function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.