Skip to content

Commit ce89060

Browse files
committed
- Added datatype parameter to DBPSEncryptor constructor.
1 parent 31f3492 commit ce89060

5 files changed

Lines changed: 26 additions & 11 deletions

File tree

src/server/encryption_sequencer.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,11 @@ static std::unique_ptr<DBPSEncryptor> CreateEncryptor(
4848
const std::string& key_id,
4949
const std::string& column_name,
5050
const std::string& user_id,
51-
const std::string& application_context) {
51+
const std::string& application_context,
52+
Type::type datatype) {
5253

5354
// Return a BasicEncryptor instance.
54-
return std::make_unique<BasicEncryptor>(key_id, column_name, user_id, application_context);
55+
return std::make_unique<BasicEncryptor>(key_id, column_name, user_id, application_context, datatype);
5556
}
5657

5758
// Constructor implementation
@@ -78,7 +79,7 @@ DataBatchEncryptionSequencer::DataBatchEncryptionSequencer(
7879
user_id_(user_id),
7980
application_context_(application_context),
8081
encryption_metadata_(encryption_metadata),
81-
encryptor_(CreateEncryptor(key_id, column_name, user_id, application_context)) {}
82+
encryptor_(CreateEncryptor(key_id, column_name, user_id, application_context, datatype)) {}
8283

8384
// Constructor with pre-built encryptor
8485
DataBatchEncryptionSequencer::DataBatchEncryptionSequencer(

src/server/encryptors/basic_encryptor.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "basic_encryptor.h"
1919
#include "../decoding_utils.h"
2020
#include "../exceptions.h"
21+
#include "../../common/enum_utils.h"
2122
#include <functional>
2223
#include <iostream>
2324

@@ -65,6 +66,7 @@ std::vector<uint8_t> BasicEncryptor::EncryptValueList(
6566
<< " user_id: " << user_id_ << "\n"
6667
<< " key_id: " << key_id_ << "\n"
6768
<< " application_context: " << application_context_ << "\n"
69+
<< " datatype: " << dbps::enum_utils::to_string(datatype_) << "\n"
6870
<< std::endl;
6971

7072
throw DBPSUnsupportedException("EncryptTypedList not implemented");

src/server/encryptors/basic_encryptor.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,16 @@ class DBPS_EXPORT BasicEncryptor : public DBPSEncryptor {
4242
* @param column_name The name of the column being encrypted/decrypted
4343
* @param user_id The user identifier for context
4444
* @param application_context Additional application context information
45+
* @param datatype The data type of the column being encrypted/decrypted.
46+
* It is needed for correct type specific parsing during the DecryptValueList call.
4547
*/
4648
BasicEncryptor(
4749
const std::string& key_id,
4850
const std::string& column_name,
4951
const std::string& user_id,
50-
const std::string& application_context)
51-
: DBPSEncryptor(key_id, column_name, user_id, application_context) {}
52+
const std::string& application_context,
53+
dbps::external::Type::type datatype)
54+
: DBPSEncryptor(key_id, column_name, user_id, application_context, datatype) {}
5255

5356
~BasicEncryptor() override = default;
5457

src/server/encryptors/basic_encryptor_test.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,14 @@
1818
#include "basic_encryptor.h"
1919
#include "../exceptions.h"
2020
#include "../decoding_utils.h"
21+
#include "../common/enums.h"
2122
#include <gtest/gtest.h>
2223
#include <vector>
2324

25+
using namespace dbps::external;
26+
2427
TEST(BasicEncryptor, EncryptDecryptBlock_RoundTrip) {
25-
BasicEncryptor encryptor("test_key", "test_column", "test_user", "test_context");
28+
BasicEncryptor encryptor("test_key", "test_column", "test_user", "test_context", Type::BYTE_ARRAY);
2629

2730
std::vector<uint8_t> original = {1, 2, 3, 4, 5, 10, 20, 30, 40, 50};
2831
std::vector<uint8_t> encrypted = encryptor.EncryptBlock(original);
@@ -33,7 +36,7 @@ TEST(BasicEncryptor, EncryptDecryptBlock_RoundTrip) {
3336
}
3437

3538
TEST(BasicEncryptor, EncryptBlock_EmptyData) {
36-
BasicEncryptor encryptor("test_key", "test_column", "test_user", "test_context");
39+
BasicEncryptor encryptor("test_key", "test_column", "test_user", "test_context", Type::BYTE_ARRAY);
3740

3841
std::vector<uint8_t> empty;
3942
std::vector<uint8_t> encrypted = encryptor.EncryptBlock(empty);
@@ -42,8 +45,8 @@ TEST(BasicEncryptor, EncryptBlock_EmptyData) {
4245
}
4346

4447
TEST(BasicEncryptor, EncryptBlock_DifferentKeys) {
45-
BasicEncryptor encryptor1("key1", "test_column", "test_user", "test_context");
46-
BasicEncryptor encryptor2("key2", "test_column", "test_user", "test_context");
48+
BasicEncryptor encryptor1("key1", "test_column", "test_user", "test_context", Type::BYTE_ARRAY);
49+
BasicEncryptor encryptor2("key2", "test_column", "test_user", "test_context", Type::BYTE_ARRAY);
4750

4851
std::vector<uint8_t> data = {1, 2, 3, 4, 5};
4952
std::vector<uint8_t> encrypted1 = encryptor1.EncryptBlock(data);

src/server/encryptors/dbps_encryptor.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <vector>
2424
#include "../exceptions.h"
2525
#include "../decoding_utils.h"
26+
#include "../common/enums.h"
2627

2728
#ifndef DBPS_EXPORT
2829
#define DBPS_EXPORT
@@ -46,16 +47,20 @@ class DBPS_EXPORT DBPSEncryptor {
4647
* @param column_name The name of the column being encrypted/decrypted
4748
* @param user_id The user identifier for context
4849
* @param application_context Additional application context information
50+
* @param datatype The data type of the column being encrypted/decrypted.
51+
* It is needed for correct type specific parsing during the DecryptValueList call.
4952
*/
5053
DBPSEncryptor(
5154
const std::string& key_id,
5255
const std::string& column_name,
5356
const std::string& user_id,
54-
const std::string& application_context)
57+
const std::string& application_context,
58+
dbps::external::Type::type datatype)
5559
: key_id_(key_id),
5660
column_name_(column_name),
5761
user_id_(user_id),
58-
application_context_(application_context) {}
62+
application_context_(application_context),
63+
datatype_(datatype) {}
5964

6065
virtual ~DBPSEncryptor() = default;
6166

@@ -114,4 +119,5 @@ class DBPS_EXPORT DBPSEncryptor {
114119
std::string column_name_;
115120
std::string user_id_;
116121
std::string application_context_;
122+
dbps::external::Type::type datatype_;
117123
};

0 commit comments

Comments
 (0)