generated from duckdb/extension-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from ccfelius/secrets
Adding local state, quick fixes for various bugs and new tests
- Loading branch information
Showing
8 changed files
with
128 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include "simple_encryption/common.hpp" | ||
#include "simple_encryption/core/functions/common.hpp" | ||
|
||
namespace simple_encryption { | ||
|
||
namespace core { | ||
|
||
SimpleEncryptionFunctionLocalState::SimpleEncryptionFunctionLocalState(ClientContext &context) : arena(BufferAllocator::Get(context)) { | ||
} | ||
|
||
unique_ptr<FunctionLocalState> | ||
SimpleEncryptionFunctionLocalState::Init(ExpressionState &state, const BoundFunctionExpression &expr, FunctionData *bind_data) { | ||
return make_uniq<SimpleEncryptionFunctionLocalState>(state.GetContext()); | ||
} | ||
|
||
unique_ptr<FunctionLocalState> SimpleEncryptionFunctionLocalState::InitCast(CastLocalStateParameters ¶meters) { | ||
return make_uniq<SimpleEncryptionFunctionLocalState>(*parameters.context.get()); | ||
} | ||
|
||
SimpleEncryptionFunctionLocalState &SimpleEncryptionFunctionLocalState::ResetAndGet(CastParameters ¶meters) { | ||
auto &local_state = parameters.local_state->Cast<SimpleEncryptionFunctionLocalState>(); | ||
local_state.arena.Reset(); | ||
return local_state; | ||
} | ||
|
||
SimpleEncryptionFunctionLocalState &SimpleEncryptionFunctionLocalState::ResetAndGet(ExpressionState &state) { | ||
auto &local_state = ExecuteFunctionState::GetFunctionState(state)->Cast<SimpleEncryptionFunctionLocalState>(); | ||
local_state.arena.Reset(); | ||
return local_state; | ||
} | ||
|
||
} // namespace core | ||
|
||
} // namespace simple_encryption |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#pragma once | ||
#include "simple_encryption/common.hpp" | ||
|
||
namespace simple_encryption { | ||
|
||
namespace core { | ||
|
||
struct SimpleEncryptionFunctionLocalState : FunctionLocalState { | ||
public: | ||
|
||
ArenaAllocator arena; | ||
|
||
public: | ||
explicit SimpleEncryptionFunctionLocalState(ClientContext &context); | ||
static unique_ptr<FunctionLocalState> Init(ExpressionState &state, const BoundFunctionExpression &expr, | ||
FunctionData *bind_data); | ||
static unique_ptr<FunctionLocalState> InitCast(CastLocalStateParameters &context); | ||
static SimpleEncryptionFunctionLocalState &ResetAndGet(ExpressionState &state); | ||
static SimpleEncryptionFunctionLocalState &ResetAndGet(CastParameters ¶meters); | ||
}; | ||
|
||
} // namespace core | ||
|
||
} // namespace simple_encryption |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# name: test/sql/secrets/secrets_encryption.test | ||
# description: Test secret creation for internal encryption | ||
# group: [simple-encryption/secrets] | ||
|
||
require simple_encryption | ||
|
||
# Ensure any currently stored secrets don't interfere with the test | ||
statement ok | ||
set allow_persistent_secrets=false; | ||
|
||
# Create an internal secret (for internal encryption of columns) | ||
statement ok | ||
CREATE SECRET key_1 ( | ||
TYPE ENCRYPTION, | ||
MASTER_KEY '0123456789112345', | ||
LENGTH 16 | ||
); | ||
|
||
#statement ok | ||
#SELECT encrypt('testtest', 'key_1', 'random_message'); | ||
|
||
statement ok | ||
CREATE TABLE rd_data AS | ||
SELECT | ||
SUBSTRING(MD5(RANDOM()::TEXT), 1, 5) AS rd_values | ||
FROM | ||
range(10); | ||
|
||
statement ok | ||
ALTER TABLE rd_data | ||
ADD COLUMN encrypted_value VARCHAR; | ||
|
||
statement ok | ||
ALTER TABLE rd_data | ||
ADD COLUMN decrypted_value VARCHAR; | ||
|
||
statement ok | ||
UPDATE rd_data | ||
SET encrypted_value = encrypt(rd_values, 'key_1', 'random_message'); | ||
|
||
statement ok | ||
UPDATE rd_data | ||
SET decrypted_value = decrypt(encrypted_value, 'key_1', 'random_message'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters