Skip to content

Commit

Permalink
Fix/trg fire only altered masks (#89)
Browse files Browse the repository at this point in the history
* checkpoint to pause this work and cherry pick out trigger fix.

* cherry pick only trigger fix.

* schema updates
  • Loading branch information
michelp authored Jul 17, 2023
1 parent 9ab96e1 commit 54c06ac
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 6 deletions.
4 changes: 2 additions & 2 deletions META.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "pgsodium",
"abstract": "Postgres extension for libsodium functions",
"description": "pgsodium is a PostgreSQL extension that exposes modern libsodium based cryptographic functions to SQL.",
"version": "3.1.7",
"version": "3.1.8",
"maintainer": [
"Michel Pelletier <pelletier.michel@gmail.com>"
],
Expand All @@ -13,7 +13,7 @@
"abstract": "Postgres extension for libsodium functions",
"file": "src/pgsodium.h",
"docfile": "README.md",
"version": "3.1.7"
"version": "3.1.8"
}
},
"prereqs": {
Expand Down
3 changes: 2 additions & 1 deletion example/tce.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ CREATE SCHEMA "tce-example";
SET search_path = "tce-example", pg_catalog;

CREATE TABLE test (
secret text
secret text,
name text unique
);

CREATE TABLE test2 (
Expand Down
2 changes: 1 addition & 1 deletion pgsodium.control
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# pgsodium extension
comment = 'Postgres extension for libsodium functions'
default_version = '3.1.7'
default_version = '3.1.8'
relocatable = false
schema = pgsodium
34 changes: 34 additions & 0 deletions sql/pgsodium--3.1.7--3.1.8.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

CREATE OR REPLACE FUNCTION pgsodium.trg_mask_update()
RETURNS EVENT_TRIGGER AS
$$
DECLARE
r record;
BEGIN
IF (SELECT bool_or(in_extension) FROM pg_event_trigger_ddl_commands()) THEN
RAISE NOTICE 'skipping pgsodium mask regeneration in extension';
RETURN;
END IF;

FOR r IN
SELECT e.*
FROM pg_event_trigger_ddl_commands() e
WHERE EXISTS (
SELECT FROM pg_catalog.pg_class c
JOIN pg_catalog.pg_seclabel s ON s.classoid = c.tableoid
AND s.objoid = c.oid
WHERE c.tableoid = e.classid
AND e.objid = c.oid
AND s.provider = 'pgsodium'
)
LOOP
IF r.object_type in ('table', 'table column')
THEN
PERFORM pgsodium.update_mask(r.objid);
END IF;
END LOOP;
END
$$
LANGUAGE plpgsql
SET search_path=''
;
4 changes: 2 additions & 2 deletions test/pgsodium_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ SELECT cmp_ok(current_setting('server_version_num')::int, '>=', 130000, format('


---- EXTENSION VERSION
SELECT results_eq('SELECT pgsodium.version()', $$VALUES ('3.1.7'::text)$$, 'Version of pgsodium is 3.1.7');
SELECT results_eq('SELECT pgsodium.version()', $$VALUES ('3.1.8'::text)$$, 'Version of pgsodium is 3.1.8');


---- EXTENSION OBJECTS
Expand Down Expand Up @@ -5604,7 +5604,7 @@ SELECT function_privs_are('pgsodium'::name, proname, proargtypes::regtype[]::tex
AND oidvectortypes(proargtypes) = 'bytea';

SELECT unnest(ARRAY[
is(md5(prosrc), '4db22ce073ebb842d305c906da664e72',
is(md5(prosrc), 'b8b02682e0138dc894512f55587db8d4',
format('Function pgsodium.%s(%s) body should match checksum',
proname, pg_get_function_identity_arguments(oid))
),
Expand Down
2 changes: 2 additions & 0 deletions test/test.sql
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ SELECT * FROM no_plan();

SET search_path = pgsodium, public;

select (current_setting('server_version_num')::int / 10000) = 15 pg15 \gset

\ir random.sql
\ir secretbox.sql
\ir secretstream.sql
Expand Down

0 comments on commit 54c06ac

Please sign in to comment.