2828#include " ../common/dbpa_remote.h"
2929#include " ../client/httplib_client.h"
3030#include " ../common/enums.h"
31+ #include " ../server/compression_utils.h"
3132#include " tcb/span.hpp"
3233
3334using namespace dbps ::external;
3435using namespace dbps ::enum_utils;
36+ using namespace dbps ::compression;
3537
3638template <typename T>
3739using span = tcb::span<T>;
@@ -143,7 +145,7 @@ class DBPARemoteTestApp {
143145 " demo_fixed_len_key_001" , // column_key_id
144146 Type::FIXED_LEN_BYTE_ARRAY , // datatype
145147 8 , // datatype_length (8 bytes per element)
146- CompressionCodec::UNCOMPRESSED , // compression_type
148+ CompressionCodec::SNAPPY , // compression_type (input will be Snappy-compressed)
147149 VALID_ENCRYPTION_METADATA // column_encryption_metadata
148150 );
149151
@@ -464,11 +466,16 @@ class DBPARemoteTestApp {
464466 }
465467
466468 std::cout << " Test data: 3 fixed-length strings (8 bytes each)" << std::endl;
467- std::cout << " Total size: " << fixed_length_data.size () << " bytes" << std::endl;
469+ std::cout << " Original size: " << fixed_length_data.size () << " bytes" << std::endl;
468470
471+ // Compress the test data using Snappy before sending to server
472+ std::vector<uint8_t > fixed_length_data_compressed = Compress (fixed_length_data, CompressionCodec::SNAPPY );
473+ std::cout << " Compressed size: " << fixed_length_data_compressed.size () << " bytes" << std::endl;
474+
469475 // Test encryption with FIXED_LEN_BYTE_ARRAY and datatype_length
476+ // The server will decompress the fixed_length_data_compressed, encrypt it, and compress the encrypted result
470477 std::map<std::string, std::string> fixed_len_encoding_attributes = {{" page_encoding" , " PLAIN" }, {" page_type" , " DICTIONARY_PAGE" }};
471- auto encrypt_result = fixed_len_agent_->Encrypt (span<const uint8_t >(fixed_length_data ), fixed_len_encoding_attributes);
478+ auto encrypt_result = fixed_len_agent_->Encrypt (span<const uint8_t >(fixed_length_data_compressed ), fixed_len_encoding_attributes);
472479
473480 if (!encrypt_result || !encrypt_result->success ()) {
474481 std::cout << " ERROR: FIXED_LEN_BYTE_ARRAY encryption failed" << std::endl;
@@ -493,13 +500,22 @@ class DBPARemoteTestApp {
493500
494501 std::cout << " OK: FIXED_LEN_BYTE_ARRAY decrypted successfully" << std::endl;
495502
503+ // The server returns compressed plaintext (same compression as input)
504+ // Decompress it before comparing with original data
505+ auto decrypted_compressed_span = decrypt_result->plaintext ();
506+ std::vector<uint8_t > decrypted_compressed (decrypted_compressed_span.begin (), decrypted_compressed_span.end ());
507+ std::vector<uint8_t > decrypted_data = Decompress (decrypted_compressed, CompressionCodec::SNAPPY );
508+ std::cout << " Decrypted compressed size: " << decrypted_compressed.size () << " bytes" << std::endl;
509+ std::cout << " Decrypted uncompressed size: " << decrypted_data.size () << " bytes" << std::endl;
510+
496511 // Verify data integrity
497- auto decrypted_data = decrypt_result->plaintext ();
498512 if (decrypted_data.size () == fixed_length_data.size () &&
499- std::equal (decrypted_data.begin (), decrypted_data.end (), fixed_length_data.begin ())) {
513+ std::equal (decrypted_data.begin (), decrypted_data.end (), fixed_length_data.begin (), fixed_length_data. end () )) {
500514 std::cout << " OK: FIXED_LEN_BYTE_ARRAY data integrity verified" << std::endl;
501515 } else {
502516 std::cout << " ERROR: FIXED_LEN_BYTE_ARRAY data integrity check failed" << std::endl;
517+ std::cout << " Expected size: " << fixed_length_data.size () << " bytes" << std::endl;
518+ std::cout << " Got size: " << decrypted_data.size () << " bytes" << std::endl;
503519 return false ;
504520 }
505521
0 commit comments