From 01a3f2b17cc5dd1ca2419f9e12a71bb6194d8224 Mon Sep 17 00:00:00 2001 From: Sofia Brenes Date: Sat, 15 Nov 2025 22:41:21 -0600 Subject: [PATCH 1/3] Fixed bug with compressed dictionaries --- src/common/dbpa_local_test.cpp | 18 ++++++++++++++++++ src/server/encryption_sequencer.cpp | 7 +++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/common/dbpa_local_test.cpp b/src/common/dbpa_local_test.cpp index 3f1643d..799d1cb 100644 --- a/src/common/dbpa_local_test.cpp +++ b/src/common/dbpa_local_test.cpp @@ -49,6 +49,24 @@ TEST_F(LocalDataBatchProtectionAgentTest, SuccessfulEncryption) { EXPECT_GT(result->size(), 0); } +TEST_F(LocalDataBatchProtectionAgentTest, SuccessfulEncryptionCompressedDictionary) { + LocalDataBatchProtectionAgent agent; + + std::map connection_config; + std::string app_context = R"({"user_id": "test_user"})"; + + EXPECT_NO_THROW(agent.init("test_column", connection_config, app_context, "test_key", + Type::BYTE_ARRAY, std::nullopt, CompressionCodec::SNAPPY, std::nullopt)); + + std::vector test_data = {1, 2, 3, 4}; + std::map encoding_attributes = {{"page_encoding", "PLAIN"}, {"page_type", "DICTIONARY_PAGE"}}; + auto result = agent.Encrypt(test_data, encoding_attributes); + + ASSERT_NE(result, nullptr); + EXPECT_TRUE(result->success()); + EXPECT_GT(result->size(), 0); +} + // Test successful initialization and decryption TEST_F(LocalDataBatchProtectionAgentTest, SuccessfulDecryption) { LocalDataBatchProtectionAgent agent; diff --git a/src/server/encryption_sequencer.cpp b/src/server/encryption_sequencer.cpp index 9d8591e..c91094f 100644 --- a/src/server/encryption_sequencer.cpp +++ b/src/server/encryption_sequencer.cpp @@ -123,8 +123,11 @@ LevelAndValueBytes DataBatchEncryptionSequencer::DecompressAndSplit( } if (page_type == "DICTIONARY_PAGE") { - // TODO: Check whether dictionary pages can be compressed. - result.value_bytes = plaintext; + if (compression_ == CompressionCodec::UNCOMPRESSED) { + result.value_bytes = plaintext; + } else { + result.value_bytes = Decompress(plaintext); + } result.level_bytes = std::vector(); return result; } From 3ed5dd6d28469ea5c969b98cbb0738f704fb8f11 Mon Sep 17 00:00:00 2001 From: Sofia Brenes Date: Mon, 17 Nov 2025 10:07:11 -0600 Subject: [PATCH 2/3] Iterated PR --- src/server/encryption_sequencer.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/server/encryption_sequencer.cpp b/src/server/encryption_sequencer.cpp index c91094f..143160a 100644 --- a/src/server/encryption_sequencer.cpp +++ b/src/server/encryption_sequencer.cpp @@ -123,11 +123,7 @@ LevelAndValueBytes DataBatchEncryptionSequencer::DecompressAndSplit( } if (page_type == "DICTIONARY_PAGE") { - if (compression_ == CompressionCodec::UNCOMPRESSED) { - result.value_bytes = plaintext; - } else { - result.value_bytes = Decompress(plaintext); - } + result.value_bytes = Decompress(plaintext); result.level_bytes = std::vector(); return result; } From 2f05d157f2d4364d1eea0edabe7015ded9c27dda Mon Sep 17 00:00:00 2001 From: sofia-tekdatum <160549600+sofia-tekdatum@users.noreply.github.com> Date: Tue, 18 Nov 2025 15:08:50 -0600 Subject: [PATCH 3/3] Update dbpa_local_test.cpp Updated test data --- src/common/dbpa_local_test.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/common/dbpa_local_test.cpp b/src/common/dbpa_local_test.cpp index 799d1cb..74e1dae 100644 --- a/src/common/dbpa_local_test.cpp +++ b/src/common/dbpa_local_test.cpp @@ -56,11 +56,17 @@ TEST_F(LocalDataBatchProtectionAgentTest, SuccessfulEncryptionCompressedDictiona std::string app_context = R"({"user_id": "test_user"})"; EXPECT_NO_THROW(agent.init("test_column", connection_config, app_context, "test_key", - Type::BYTE_ARRAY, std::nullopt, CompressionCodec::SNAPPY, std::nullopt)); - - std::vector test_data = {1, 2, 3, 4}; + Type::BYTE_ARRAY, std::nullopt, CompressionCodec::GZIP, std::nullopt)); + + // GZIP compressed data for strings "apple" and "banana" + std::vector test_data_gzip = { + 0x1F, 0x8B, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xFF, + 0x63, 0x65, 0x60, 0x60, 0x48, 0x2C, 0x28, 0xC8, 0x49, 0x65, + 0x03, 0x32, 0x92, 0x12, 0xF3, 0x80, 0x10, 0x00, 0xC7, 0xB8, + 0x50, 0xFC, 0x13, 0x00, 0x00, 0x00 + }; std::map encoding_attributes = {{"page_encoding", "PLAIN"}, {"page_type", "DICTIONARY_PAGE"}}; - auto result = agent.Encrypt(test_data, encoding_attributes); + auto result = agent.Encrypt(test_data_gzip, encoding_attributes); ASSERT_NE(result, nullptr); EXPECT_TRUE(result->success());