Skip to content

Commit d8e531b

Browse files
committed
simplifying signatures
1 parent eba9446 commit d8e531b

2 files changed

Lines changed: 24 additions & 24 deletions

File tree

src/processing/encryptors/basic_xor_encryptor.cpp

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ using namespace dbps::external;
3030
// Functions for encrypting and decrypting byte arrays.
3131
// ---------------------------------------------------------------------------
3232

33-
std::vector<uint8_t> BasicXorEncryptor::XorEncrypt(tcb::span<const uint8_t> data, size_t key_hash) {
33+
std::vector<uint8_t> BasicXorEncryptor::XorEncrypt(tcb::span<const uint8_t> data) {
3434
if (data.empty()) {
3535
return {};
3636
}
37+
size_t key_hash = key_id_hash_;
3738
std::vector<uint8_t> out(data.size());
3839
for (size_t i = 0; i < data.size(); ++i) {
3940
out[i] = data[i] ^ (key_hash & 0xFF);
@@ -42,20 +43,20 @@ std::vector<uint8_t> BasicXorEncryptor::XorEncrypt(tcb::span<const uint8_t> data
4243
return out;
4344
}
4445

45-
std::vector<uint8_t> BasicXorEncryptor::XorDecrypt(tcb::span<const uint8_t> data, size_t key_hash) {
46-
return XorEncrypt(data, key_hash);
46+
std::vector<uint8_t> BasicXorEncryptor::XorDecrypt(tcb::span<const uint8_t> data) {
47+
return XorEncrypt(data);
4748
}
4849

4950
// ---------------------------------------------------------------------------
5051
// Block encryption
5152
// ---------------------------------------------------------------------------
5253

5354
std::vector<uint8_t> BasicXorEncryptor::EncryptBlock(tcb::span<const uint8_t> data) {
54-
return XorEncrypt(data, key_id_hash_);
55+
return XorEncrypt(data);
5556
}
5657

5758
std::vector<uint8_t> BasicXorEncryptor::DecryptBlock(tcb::span<const uint8_t> data) {
58-
return XorDecrypt(data, key_id_hash_);
59+
return XorDecrypt(data);
5960
}
6061

6162
// ---------------------------------------------------------------------------
@@ -89,7 +90,7 @@ std::vector<uint8_t> BasicXorEncryptor::DecryptBlock(tcb::span<const uint8_t> da
8990

9091
template <typename TypedBuffer>
9192
std::vector<uint8_t> BasicXorEncryptor::EncryptTypedElements(
92-
const TypedBuffer& input_buffer, size_t key_hash) {
93+
const TypedBuffer& input_buffer) {
9394
constexpr bool is_fixed = TypedBuffer::is_fixed_sized;
9495
constexpr size_t prefix_length = is_fixed ? kFixedHeaderLength : kVariableHeaderLength;
9596
const size_t num_elements = input_buffer.GetNumElements();
@@ -116,7 +117,7 @@ std::vector<uint8_t> BasicXorEncryptor::EncryptTypedElements(
116117
num_elements, prefix_length, RawBytesFixedSizedCodec{element_size}};
117118
size_t output_index = 0;
118119
for (const auto raw_bytes : input_buffer.raw_elements()) {
119-
auto encrypted = XorEncrypt(raw_bytes, key_hash);
120+
auto encrypted = XorEncrypt(raw_bytes);
120121
output_buffer.SetElement(output_index, tcb::span<const uint8_t>(encrypted));
121122
output_index++;
122123
}
@@ -130,7 +131,7 @@ std::vector<uint8_t> BasicXorEncryptor::EncryptTypedElements(
130131
num_elements, reserved_bytes_hint, true, prefix_length};
131132
size_t output_index = 0;
132133
for (const auto raw_bytes : input_buffer.raw_elements()) {
133-
auto encrypted = XorEncrypt(raw_bytes, key_hash);
134+
auto encrypted = XorEncrypt(raw_bytes);
134135
output_buffer.SetElement(output_index, tcb::span<const uint8_t>(encrypted));
135136
output_index++;
136137
}
@@ -161,7 +162,7 @@ std::vector<uint8_t> BasicXorEncryptor::EncryptValueList(
161162
// std::visit extracts the concrete buffer type from the TypedValuesBuffer variant
162163
// and forwards it to EncryptTypedElements, which handles all buffer types generically.
163164
return std::visit([&](const auto& input_buffer) {
164-
return EncryptTypedElements(input_buffer, key_id_hash_);
165+
return EncryptTypedElements(input_buffer);
165166
}, typed_buffer);
166167
}
167168

@@ -175,10 +176,10 @@ std::vector<uint8_t> BasicXorEncryptor::EncryptValueList(
175176
// Helper function to decrypt fixed-size elements into the output TypedBuffer type.
176177
template <typename TypedBuffer>
177178
TypedBuffer BasicXorEncryptor::DecryptFixedSizedElementsIntoTypedBuffer(
178-
const TypedBufferRawBytesFixedSized& encrypted_buffer, size_t key_hash, TypedBuffer output_buffer) {
179+
const TypedBufferRawBytesFixedSized& encrypted_buffer, TypedBuffer output_buffer) {
179180
size_t output_index = 0;
180181
for (const auto raw_bytes : encrypted_buffer.raw_elements()) {
181-
auto decrypted_bytes = XorDecrypt(raw_bytes, key_hash);
182+
auto decrypted_bytes = XorDecrypt(raw_bytes);
182183
output_buffer.SetRawElement(output_index, tcb::span<const uint8_t>(decrypted_bytes));
183184
output_index++;
184185
}
@@ -202,22 +203,22 @@ TypedValuesBuffer BasicXorEncryptor::DecryptValueList(
202203
switch (datatype_) {
203204
case Type::INT32:
204205
return DecryptFixedSizedElementsIntoTypedBuffer(
205-
encrypted_buffer, key_id_hash_, TypedBufferI32{num_elements});
206+
encrypted_buffer, TypedBufferI32{num_elements});
206207
case Type::INT64:
207208
return DecryptFixedSizedElementsIntoTypedBuffer(
208-
encrypted_buffer, key_id_hash_, TypedBufferI64{num_elements});
209+
encrypted_buffer, TypedBufferI64{num_elements});
209210
case Type::INT96:
210211
return DecryptFixedSizedElementsIntoTypedBuffer(
211-
encrypted_buffer, key_id_hash_, TypedBufferInt96{num_elements});
212+
encrypted_buffer, TypedBufferInt96{num_elements});
212213
case Type::FLOAT:
213214
return DecryptFixedSizedElementsIntoTypedBuffer(
214-
encrypted_buffer, key_id_hash_, TypedBufferFloat{num_elements});
215+
encrypted_buffer, TypedBufferFloat{num_elements});
215216
case Type::DOUBLE:
216217
return DecryptFixedSizedElementsIntoTypedBuffer(
217-
encrypted_buffer, key_id_hash_, TypedBufferDouble{num_elements});
218+
encrypted_buffer, TypedBufferDouble{num_elements});
218219
case Type::FIXED_LEN_BYTE_ARRAY:
219220
return DecryptFixedSizedElementsIntoTypedBuffer(
220-
encrypted_buffer, key_id_hash_,
221+
encrypted_buffer,
221222
TypedBufferRawBytesFixedSized{num_elements, 0, RawBytesFixedSizedCodec{header.element_size}});
222223
default:
223224
throw InvalidInputException(
@@ -238,7 +239,7 @@ TypedValuesBuffer BasicXorEncryptor::DecryptValueList(
238239
TypedBufferRawBytesVariableSized output_buffer{num_elements, reserved_bytes_hint, true};
239240
size_t output_index = 0;
240241
for (const auto element : encrypted_buffer) {
241-
auto decrypted_bytes = XorDecrypt(element, key_id_hash_);
242+
auto decrypted_bytes = XorDecrypt(element);
242243
output_buffer.SetElement(output_index, tcb::span<const uint8_t>(decrypted_bytes));
243244
output_index++;
244245
}

src/processing/encryptors/basic_xor_encryptor.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,15 @@ class DBPS_EXPORT BasicXorEncryptor : public DBPSEncryptor {
6666
private:
6767
const size_t key_id_hash_;
6868

69-
static std::vector<uint8_t> XorEncrypt(tcb::span<const uint8_t> data, size_t key_hash);
70-
static std::vector<uint8_t> XorDecrypt(tcb::span<const uint8_t> data, size_t key_hash);
69+
std::vector<uint8_t> XorEncrypt(tcb::span<const uint8_t> data);
70+
std::vector<uint8_t> XorDecrypt(tcb::span<const uint8_t> data);
7171

7272
template <typename InputBuffer>
73-
static std::vector<uint8_t> EncryptTypedElements(
74-
const InputBuffer& input_buffer, size_t key_hash);
73+
std::vector<uint8_t> EncryptTypedElements(const InputBuffer& input_buffer);
7574

7675
template <typename TypedBuffer>
77-
static TypedBuffer DecryptFixedSizedElementsIntoTypedBuffer(
76+
TypedBuffer DecryptFixedSizedElementsIntoTypedBuffer(
7877
const TypedBufferRawBytesFixedSized& encrypted_buffer,
79-
size_t key_hash, TypedBuffer output_buffer);
78+
TypedBuffer output_buffer);
8079
};
8180

0 commit comments

Comments
 (0)