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;
@@ -143,7 +144,7 @@ class DBPARemoteTestApp {
143144 " demo_fixed_len_key_001" , // column_key_id
144145 Type::FIXED_LEN_BYTE_ARRAY, // datatype
145146 8 , // datatype_length (8 bytes per element)
146- CompressionCodec::UNCOMPRESSED, // compression_type
147+ CompressionCodec::SNAPPY, // compression_type (input will be Snappy-compressed)
147148 VALID_ENCRYPTION_METADATA // column_encryption_metadata
148149 );
149150
@@ -464,11 +465,16 @@ class DBPARemoteTestApp {
464465 }
465466
466467 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;
468+ std::cout << " Original size: " << fixed_length_data.size () << " bytes" << std::endl;
468469
470+ // Compress the test data using Snappy before sending to server
471+ std::vector<uint8_t > fixed_length_data_compressed = Compress (fixed_length_data, CompressionCodec::SNAPPY);
472+ std::cout << " Compressed size: " << fixed_length_data_compressed.size () << " bytes" << std::endl;
473+
469474 // Test encryption with FIXED_LEN_BYTE_ARRAY and datatype_length
475+ // The server will decompress the fixed_length_data_compressed, encrypt it, and compress the encrypted result
470476 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);
477+ auto encrypt_result = fixed_len_agent_->Encrypt (span<const uint8_t >(fixed_length_data_compressed ), fixed_len_encoding_attributes);
472478
473479 if (!encrypt_result || !encrypt_result->success ()) {
474480 std::cout << " ERROR: FIXED_LEN_BYTE_ARRAY encryption failed" << std::endl;
@@ -493,13 +499,22 @@ class DBPARemoteTestApp {
493499
494500 std::cout << " OK: FIXED_LEN_BYTE_ARRAY decrypted successfully" << std::endl;
495501
502+ // The server returns compressed plaintext (same compression as input)
503+ // Decompress it before comparing with original data
504+ auto decrypted_compressed_span = decrypt_result->plaintext ();
505+ std::vector<uint8_t > decrypted_compressed (decrypted_compressed_span.begin (), decrypted_compressed_span.end ());
506+ std::vector<uint8_t > decrypted_data = Decompress (decrypted_compressed, CompressionCodec::SNAPPY);
507+ std::cout << " Decrypted compressed size: " << decrypted_compressed.size () << " bytes" << std::endl;
508+ std::cout << " Decrypted uncompressed size: " << decrypted_data.size () << " bytes" << std::endl;
509+
496510 // Verify data integrity
497- auto decrypted_data = decrypt_result->plaintext ();
498511 if (decrypted_data.size () == fixed_length_data.size () &&
499- std::equal (decrypted_data.begin (), decrypted_data.end (), fixed_length_data.begin ())) {
512+ std::equal (decrypted_data.begin (), decrypted_data.end (), fixed_length_data.begin (), fixed_length_data. end () )) {
500513 std::cout << " OK: FIXED_LEN_BYTE_ARRAY data integrity verified" << std::endl;
501514 } else {
502515 std::cout << " ERROR: FIXED_LEN_BYTE_ARRAY data integrity check failed" << std::endl;
516+ std::cout << " Expected size: " << fixed_length_data.size () << " bytes" << std::endl;
517+ std::cout << " Got size: " << decrypted_data.size () << " bytes" << std::endl;
503518 return false ;
504519 }
505520
0 commit comments