Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/blake3/compare.sql
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
CREATE FUNCTION eql_v2.compare_blake3(a eql_v2_encrypted, b eql_v2_encrypted)
RETURNS integer
IMMUTABLE STRICT PARALLEL SAFE
SET search_path = pg_catalog, extensions, public
AS $$
DECLARE
a_term eql_v2.blake3;
Expand Down
4 changes: 4 additions & 0 deletions src/blake3/functions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
CREATE FUNCTION eql_v2.blake3(val jsonb)
RETURNS eql_v2.blake3
IMMUTABLE STRICT PARALLEL SAFE
SET search_path = pg_catalog, extensions, public
AS $$
BEGIN
IF val IS NULL THEN
Expand Down Expand Up @@ -45,6 +46,7 @@ $$ LANGUAGE plpgsql;
CREATE FUNCTION eql_v2.blake3(val eql_v2_encrypted)
RETURNS eql_v2.blake3
IMMUTABLE STRICT PARALLEL SAFE
SET search_path = pg_catalog, extensions, public
AS $$
BEGIN
RETURN (SELECT eql_v2.blake3(val.data));
Expand All @@ -64,6 +66,7 @@ $$ LANGUAGE plpgsql;
CREATE FUNCTION eql_v2.has_blake3(val jsonb)
RETURNS boolean
IMMUTABLE STRICT PARALLEL SAFE
SET search_path = pg_catalog, extensions, public
AS $$
BEGIN
RETURN val ->> 'b3' IS NOT NULL;
Expand All @@ -83,6 +86,7 @@ $$ LANGUAGE plpgsql;
CREATE FUNCTION eql_v2.has_blake3(val eql_v2_encrypted)
RETURNS boolean
IMMUTABLE STRICT PARALLEL SAFE
SET search_path = pg_catalog, extensions, public
AS $$
BEGIN
RETURN eql_v2.has_blake3(val.data);
Expand Down
4 changes: 4 additions & 0 deletions src/bloom_filter/functions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
CREATE FUNCTION eql_v2.bloom_filter(val jsonb)
RETURNS eql_v2.bloom_filter
IMMUTABLE STRICT PARALLEL SAFE
SET search_path = pg_catalog, extensions, public
AS $$
BEGIN
IF val IS NULL THEN
Expand Down Expand Up @@ -42,6 +43,7 @@ $$ LANGUAGE plpgsql;
CREATE FUNCTION eql_v2.bloom_filter(val eql_v2_encrypted)
RETURNS eql_v2.bloom_filter
IMMUTABLE STRICT PARALLEL SAFE
SET search_path = pg_catalog, extensions, public
AS $$
BEGIN
RETURN (SELECT eql_v2.bloom_filter(val.data));
Expand All @@ -61,6 +63,7 @@ $$ LANGUAGE plpgsql;
CREATE FUNCTION eql_v2.has_bloom_filter(val jsonb)
RETURNS boolean
IMMUTABLE STRICT PARALLEL SAFE
SET search_path = pg_catalog, extensions, public
AS $$
BEGIN
RETURN val ->> 'bf' IS NOT NULL;
Expand All @@ -80,6 +83,7 @@ $$ LANGUAGE plpgsql;
CREATE FUNCTION eql_v2.has_bloom_filter(val eql_v2_encrypted)
RETURNS boolean
IMMUTABLE STRICT PARALLEL SAFE
SET search_path = pg_catalog, extensions, public
AS $$
BEGIN
RETURN eql_v2.has_bloom_filter(val.data);
Expand Down
10 changes: 8 additions & 2 deletions src/common.sql
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
--!
--! @note Returns false immediately if lengths differ (length is not secret)
--! @note Used for secure comparison of cryptographic values
CREATE FUNCTION eql_v2.bytea_eq(a bytea, b bytea) RETURNS boolean AS $$
CREATE FUNCTION eql_v2.bytea_eq(a bytea, b bytea) RETURNS boolean
SET search_path = pg_catalog, extensions, public
AS $$
DECLARE
result boolean;
differing bytea;
Expand Down Expand Up @@ -59,7 +61,9 @@ $$ LANGUAGE plpgsql;
--! @note Returns NULL if input is JSON null
--! @note Each array element is hex-decoded to bytea
CREATE FUNCTION eql_v2.jsonb_array_to_bytea_array(val jsonb)
RETURNS bytea[] AS $$
RETURNS bytea[]
SET search_path = pg_catalog, extensions, public
AS $$
DECLARE
terms_arr bytea[];
BEGIN
Expand Down Expand Up @@ -87,6 +91,7 @@ $$ LANGUAGE plpgsql;
--! @see eql_v2.log(text, text) for contextual logging
CREATE FUNCTION eql_v2.log(s text)
RETURNS void
SET search_path = pg_catalog, extensions, public
AS $$
BEGIN
RAISE NOTICE '[LOG] %', s;
Expand All @@ -106,6 +111,7 @@ $$ LANGUAGE plpgsql;
--! @see eql_v2.log(text)
CREATE FUNCTION eql_v2.log(ctx text, s text)
RETURNS void
SET search_path = pg_catalog, extensions, public
AS $$
BEGIN
RAISE NOTICE '[LOG] % %', ctx, s;
Expand Down
4 changes: 4 additions & 0 deletions src/config/constraints.sql
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ END;
CREATE FUNCTION eql_v2.config_check_indexes(val jsonb)
RETURNS BOOLEAN
IMMUTABLE STRICT PARALLEL SAFE
SET search_path = pg_catalog, extensions, public
AS $$
BEGIN

Expand Down Expand Up @@ -75,6 +76,7 @@ $$ LANGUAGE plpgsql;
CREATE FUNCTION eql_v2.config_check_cast(val jsonb)
RETURNS BOOLEAN
IMMUTABLE STRICT PARALLEL SAFE
SET search_path = pg_catalog, extensions, public
AS $$
DECLARE
_valid_types text[] := '{text, int, small_int, big_int, real, double, boolean, date, jsonb, json, float, decimal, timestamp}';
Expand Down Expand Up @@ -113,6 +115,7 @@ $$ LANGUAGE plpgsql;
--! @note Used in CHECK constraint on eql_v2_configuration table
CREATE FUNCTION eql_v2.config_check_tables(val jsonb)
RETURNS boolean
SET search_path = pg_catalog, extensions, public
AS $$
BEGIN
IF (val ? 'tables') THEN
Expand All @@ -136,6 +139,7 @@ $$ LANGUAGE plpgsql;
--! @note Used in CHECK constraint on eql_v2_configuration table
CREATE FUNCTION eql_v2.config_check_version(val jsonb)
RETURNS boolean
SET search_path = pg_catalog, extensions, public
AS $$
BEGIN
IF (val ? 'v') THEN
Expand Down
9 changes: 9 additions & 0 deletions src/config/functions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
CREATE FUNCTION eql_v2.add_search_config(table_name text, column_name text, index_name text, cast_as text DEFAULT 'text', opts jsonb DEFAULT '{}', migrating boolean DEFAULT false)
RETURNS jsonb

SET search_path = pg_catalog, extensions, public
AS $$
DECLARE
o jsonb;
Expand Down Expand Up @@ -108,6 +109,7 @@ $$ LANGUAGE plpgsql;
--! @see eql_v2.modify_search_config
CREATE FUNCTION eql_v2.remove_search_config(table_name text, column_name text, index_name text, migrating boolean DEFAULT false)
RETURNS jsonb
SET search_path = pg_catalog, extensions, public
AS $$
DECLARE
_config jsonb;
Expand Down Expand Up @@ -178,6 +180,7 @@ $$ LANGUAGE plpgsql;
--! @see eql_v2.remove_search_config
CREATE FUNCTION eql_v2.modify_search_config(table_name text, column_name text, index_name text, cast_as text DEFAULT 'text', opts jsonb DEFAULT '{}', migrating boolean DEFAULT false)
RETURNS jsonb
SET search_path = pg_catalog, extensions, public
AS $$
BEGIN
PERFORM eql_v2.remove_search_config(table_name, column_name, index_name, migrating);
Expand All @@ -204,6 +207,7 @@ $$ LANGUAGE plpgsql;
--! @see eql_v2.add_column
CREATE FUNCTION eql_v2.migrate_config()
RETURNS boolean
SET search_path = pg_catalog, extensions, public
AS $$
BEGIN

Expand Down Expand Up @@ -241,6 +245,7 @@ $$ LANGUAGE plpgsql;
--! @see eql_v2.add_column
CREATE FUNCTION eql_v2.activate_config()
RETURNS boolean
SET search_path = pg_catalog, extensions, public
AS $$
BEGIN

Expand Down Expand Up @@ -270,6 +275,7 @@ $$ LANGUAGE plpgsql;
--! @see eql_v2.add_search_config
CREATE FUNCTION eql_v2.discard()
RETURNS boolean
SET search_path = pg_catalog, extensions, public
AS $$
BEGIN
IF EXISTS (SELECT FROM public.eql_v2_configuration c WHERE c.state = 'pending') THEN
Expand Down Expand Up @@ -305,6 +311,7 @@ $$ LANGUAGE plpgsql;
--! @see eql_v2.remove_column
CREATE FUNCTION eql_v2.add_column(table_name text, column_name text, cast_as text DEFAULT 'text', migrating boolean DEFAULT false)
RETURNS jsonb
SET search_path = pg_catalog, extensions, public
AS $$
DECLARE
key text;
Expand Down Expand Up @@ -368,6 +375,7 @@ $$ LANGUAGE plpgsql;
--! @see eql_v2.remove_search_config
CREATE FUNCTION eql_v2.remove_column(table_name text, column_name text, migrating boolean DEFAULT false)
RETURNS jsonb
SET search_path = pg_catalog, extensions, public
AS $$
DECLARE
key text;
Expand Down Expand Up @@ -466,6 +474,7 @@ CREATE FUNCTION eql_v2.config() RETURNS TABLE (
decrypts_as text,
indexes jsonb
)
SET search_path = pg_catalog, extensions, public
AS $$
BEGIN
RETURN QUERY
Expand Down
5 changes: 5 additions & 0 deletions src/config/functions_private.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
CREATE FUNCTION eql_v2.config_default(config jsonb)
RETURNS jsonb
IMMUTABLE PARALLEL SAFE
SET search_path = pg_catalog, extensions, public
AS $$
BEGIN
IF config IS NULL THEN
Expand All @@ -32,6 +33,7 @@ $$ LANGUAGE plpgsql;
CREATE FUNCTION eql_v2.config_add_table(table_name text, config jsonb)
RETURNS jsonb
IMMUTABLE PARALLEL SAFE
SET search_path = pg_catalog, extensions, public
AS $$
DECLARE
tbl jsonb;
Expand All @@ -56,6 +58,7 @@ $$ LANGUAGE plpgsql;
CREATE FUNCTION eql_v2.config_add_column(table_name text, column_name text, config jsonb)
RETURNS jsonb
IMMUTABLE PARALLEL SAFE
SET search_path = pg_catalog, extensions, public
AS $$
DECLARE
col jsonb;
Expand All @@ -82,6 +85,7 @@ $$ LANGUAGE plpgsql;
CREATE FUNCTION eql_v2.config_add_cast(table_name text, column_name text, cast_as text, config jsonb)
RETURNS jsonb
IMMUTABLE PARALLEL SAFE
SET search_path = pg_catalog, extensions, public
AS $$
BEGIN
SELECT jsonb_set(config, array['tables', table_name, column_name, 'cast_as'], to_jsonb(cast_as)) INTO config;
Expand All @@ -104,6 +108,7 @@ $$ LANGUAGE plpgsql;
CREATE FUNCTION eql_v2.config_add_index(table_name text, column_name text, index_name text, opts jsonb, config jsonb)
RETURNS jsonb
IMMUTABLE PARALLEL SAFE
SET search_path = pg_catalog, extensions, public
AS $$
BEGIN
SELECT jsonb_insert(config, array['tables', table_name, column_name, 'indexes', index_name], opts) INTO config;
Expand Down
2 changes: 2 additions & 0 deletions src/encrypted/aggregates.sql
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
CREATE FUNCTION eql_v2.min(a eql_v2_encrypted, b eql_v2_encrypted)
RETURNS eql_v2_encrypted
STRICT
SET search_path = pg_catalog, extensions, public
AS $$
BEGIN
IF a < b THEN
Expand Down Expand Up @@ -66,6 +67,7 @@ CREATE AGGREGATE eql_v2.min(eql_v2_encrypted)
CREATE FUNCTION eql_v2.max(a eql_v2_encrypted, b eql_v2_encrypted)
RETURNS eql_v2_encrypted
STRICT
SET search_path = pg_catalog, extensions, public
AS $$
BEGIN
IF a > b THEN
Expand Down
4 changes: 4 additions & 0 deletions src/encrypted/constraints.sql
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
--! @see eql_v2.check_encrypted
CREATE FUNCTION eql_v2._encrypted_check_i(val jsonb)
RETURNS boolean
SET search_path = pg_catalog, extensions, public
AS $$
BEGIN
IF val ? 'i' THEN
Expand All @@ -41,6 +42,7 @@ $$ LANGUAGE plpgsql;
--! @see eql_v2.check_encrypted
CREATE FUNCTION eql_v2._encrypted_check_i_ct(val jsonb)
RETURNS boolean
SET search_path = pg_catalog, extensions, public
AS $$
BEGIN
IF (val->'i' ?& array['t', 'c']) THEN
Expand All @@ -64,6 +66,7 @@ $$ LANGUAGE plpgsql;
--! @see eql_v2.check_encrypted
CREATE FUNCTION eql_v2._encrypted_check_v(val jsonb)
RETURNS boolean
SET search_path = pg_catalog, extensions, public
AS $$
BEGIN
IF (val ? 'v') THEN
Expand Down Expand Up @@ -94,6 +97,7 @@ $$ LANGUAGE plpgsql;
--! @see eql_v2.check_encrypted
CREATE FUNCTION eql_v2._encrypted_check_c(val jsonb)
RETURNS boolean
SET search_path = pg_catalog, extensions, public
AS $$
BEGIN
IF (val ? 'c') THEN
Expand Down
6 changes: 5 additions & 1 deletion src/encrypted/functions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
CREATE FUNCTION eql_v2.ciphertext(val jsonb)
RETURNS text
IMMUTABLE STRICT PARALLEL SAFE
SET search_path = pg_catalog, extensions, public
AS $$
BEGIN
IF val ? 'c' THEN
Expand Down Expand Up @@ -65,7 +66,8 @@ $$;
--!
--! @see eql_v2.grouped_value
CREATE FUNCTION eql_v2._first_grouped_value(jsonb, jsonb)
RETURNS jsonb AS $$
RETURNS jsonb
AS $$
SELECT COALESCE($1, $2);
$$ LANGUAGE sql IMMUTABLE;

Expand Down Expand Up @@ -119,6 +121,7 @@ CREATE AGGREGATE eql_v2.grouped_value(jsonb) (
--! @see eql_v2.remove_encrypted_constraint
CREATE FUNCTION eql_v2.add_encrypted_constraint(table_name TEXT, column_name TEXT)
RETURNS void
SET search_path = pg_catalog, extensions, public
AS $$
BEGIN
EXECUTE format('ALTER TABLE %I ADD CONSTRAINT eql_v2_encrypted_constraint_%I_%I CHECK (eql_v2.check_encrypted(%I))', table_name, table_name, column_name, column_name);
Expand Down Expand Up @@ -147,6 +150,7 @@ $$ LANGUAGE plpgsql;
--! @see eql_v2.add_encrypted_constraint
CREATE FUNCTION eql_v2.remove_encrypted_constraint(table_name TEXT, column_name TEXT)
RETURNS void
SET search_path = pg_catalog, extensions, public
AS $$
BEGIN
EXECUTE format('ALTER TABLE %I DROP CONSTRAINT IF EXISTS eql_v2_encrypted_constraint_%I_%I', table_name, table_name, column_name);
Expand Down
1 change: 1 addition & 0 deletions src/encrypted/hash.sql
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
CREATE FUNCTION eql_v2.hash_encrypted(val eql_v2_encrypted)
RETURNS integer
IMMUTABLE STRICT PARALLEL SAFE
SET search_path = pg_catalog, extensions, public
AS $$
DECLARE
ste_val eql_v2_encrypted;
Expand Down
5 changes: 5 additions & 0 deletions src/encryptindex/functions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
CREATE FUNCTION eql_v2.diff_config(a JSONB, b JSONB)
RETURNS TABLE(table_name TEXT, column_name TEXT)
IMMUTABLE STRICT PARALLEL SAFE
SET search_path = pg_catalog, extensions, public
AS $$
BEGIN
RETURN QUERY
Expand Down Expand Up @@ -65,6 +66,7 @@ $$ LANGUAGE plpgsql;
--! @see eql_v2.select_target_columns
CREATE FUNCTION eql_v2.select_pending_columns()
RETURNS TABLE(table_name TEXT, column_name TEXT)
SET search_path = pg_catalog, extensions, public
AS $$
DECLARE
active JSONB;
Expand Down Expand Up @@ -155,6 +157,7 @@ $$ LANGUAGE sql;
--! @see eql_v2.rename_encrypted_columns
CREATE FUNCTION eql_v2.create_encrypted_columns()
RETURNS TABLE(table_name TEXT, column_name TEXT)
SET search_path = pg_catalog, extensions, public
AS $$
BEGIN
FOR table_name, column_name IN
Expand Down Expand Up @@ -182,6 +185,7 @@ $$ LANGUAGE plpgsql;
--! @see eql_v2.create_encrypted_columns
CREATE FUNCTION eql_v2.rename_encrypted_columns()
RETURNS TABLE(table_name TEXT, column_name TEXT, target_column TEXT)
SET search_path = pg_catalog, extensions, public
AS $$
BEGIN
FOR table_name, column_name, target_column IN
Expand Down Expand Up @@ -209,6 +213,7 @@ $$ LANGUAGE plpgsql;
--! @note Configuration tracking mechanism is implementation-specific
CREATE FUNCTION eql_v2.count_encrypted_with_active_config(table_name TEXT, column_name TEXT)
RETURNS BIGINT
SET search_path = pg_catalog, extensions, public
AS $$
DECLARE
result BIGINT;
Expand Down
1 change: 1 addition & 0 deletions src/hmac_256/compare.sql
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
CREATE FUNCTION eql_v2.compare_hmac_256(a eql_v2_encrypted, b eql_v2_encrypted)
RETURNS integer
IMMUTABLE STRICT PARALLEL SAFE
SET search_path = pg_catalog, extensions, public
AS $$
DECLARE
a_term eql_v2.hmac_256;
Expand Down
Loading
Loading