Skip to content

Commit

Permalink
put support for 13 back in, had to remove some 14+ specific code.
Browse files Browse the repository at this point in the history
  • Loading branch information
michelp committed Nov 3, 2022
1 parent 975123f commit d78481e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
15 changes: 8 additions & 7 deletions sql/pgsodium--2.0.2--3.0.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ GRANT USAGE ON SCHEMA @extschema@_masks TO pgsodium_keyiduser;

CREATE OR REPLACE FUNCTION @[email protected]()
RETURNS text
RETURN (SELECT extversion FROM pg_extension WHERE extname = 'pgsodium');
AS $$ SELECT extversion FROM pg_extension WHERE extname = 'pgsodium') $$
LANGUAGE sql;

-- Internal Key Management

Expand Down Expand Up @@ -90,7 +91,7 @@ CREATE FUNCTION @[email protected]_key(
key_context bytea = 'pgsodium',
expires timestamp = null,
user_data jsonb = null) RETURNS @[email protected]
BEGIN ATOMIC
AS $$
INSERT INTO @[email protected] (key_id, key_context, key_type, expires, comment, user_data)
VALUES (case when key_id is null then nextval('@[email protected]_key_id_seq'::regclass) else key_id
end,
Expand All @@ -99,7 +100,7 @@ CREATE FUNCTION @[email protected]_key(
expires,
comment,
user_data) RETURNING *;
END;
$$ LANGUAGE sql;

-- Deterministic AEAD functions by key uuid

Expand Down Expand Up @@ -279,20 +280,20 @@ GRANT SELECT ON @[email protected]_rule TO PUBLIC;


CREATE FUNCTION @[email protected]_mask(role regrole, source_name text)
RETURNS BOOLEAN RETURN (
RETURNS boolean AS $$
SELECT EXISTS(
SELECT 1
FROM pg_shseclabel
WHERE objoid = role
AND provider = 'pgsodium'
AND label ilike 'ACCESS%' || source_name || '%')
);
$$ LANGUAGE sql;

-- Display all columns of the relation with the masking function (if any)
CREATE FUNCTION @[email protected]_columns(source_relid oid)
RETURNS TABLE (attname name, key_id text, key_id_column text,
associated_column text, nonce_column text, format_type text)
BEGIN ATOMIC
AS $$
SELECT
a.attname,
m.key_id,
Expand All @@ -308,7 +309,7 @@ BEGIN ATOMIC
AND a.attnum > 0 -- exclude ctid, cmin, cmax
AND NOT a.attisdropped
ORDER BY a.attnum;
END;
$$ LANGUAGE sql;

-- get the "select filters" that will decrypt the real data of a table
CREATE FUNCTION @[email protected]_columns(
Expand Down
6 changes: 3 additions & 3 deletions sql/pgsodium--3.0.4--3.0.5.sql
Original file line number Diff line number Diff line change
Expand Up @@ -605,13 +605,13 @@ CREATE VIEW pgsodium.mask_columns AS SELECT

CREATE OR REPLACE FUNCTION pgsodium.quote_assoc(text, boolean = false)
RETURNS text
BEGIN ATOMIC
AS $$
WITH a AS (SELECT array_agg(CASE WHEN $2 THEN
'new.' || quote_ident(trim(v))
ELSE quote_ident(trim(v)) END) as r
FROM string_to_table($1, ',') as v)
FROM regexp_split_to_table($1, '\s*,\s*') as v)
SELECT array_to_string(a.r, '::text || ') || '::text' FROM a;
END;
$$ LANGUAGE sql;

CREATE OR REPLACE FUNCTION pgsodium.encrypted_columns(relid OID)
RETURNS TEXT AS
Expand Down
2 changes: 1 addition & 1 deletion test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -e

versions=${1:-14 15}
versions=${1:-13 14 15}

for version in $versions
do
Expand Down

0 comments on commit d78481e

Please sign in to comment.