-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Any column that can cast to text can be associated. (#28)
- Loading branch information
Showing
4 changed files
with
96 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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.0.3", | ||
"version": "3.0.4", | ||
"maintainer": [ | ||
"Michel Pelletier <[email protected]>" | ||
], | ||
|
@@ -13,7 +13,7 @@ | |
"abstract": "Postgres extension for libsodium functions", | ||
"file": "src/pgsodium.h", | ||
"docfile": "README.md", | ||
"version": "3.0.3" | ||
"version": "3.0.4" | ||
} | ||
}, | ||
"prereqs": { | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# pgsodium extension | ||
comment = 'Postgres extension for libsodium functions' | ||
default_version = '3.0.3' | ||
default_version = '3.0.4' | ||
relocatable = false |
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,88 @@ | ||
CREATE OR REPLACE FUNCTION @[email protected]_columns( | ||
relid OID | ||
) | ||
RETURNS TEXT AS | ||
$$ | ||
DECLARE | ||
m RECORD; | ||
expression TEXT; | ||
comma TEXT; | ||
BEGIN | ||
expression := ''; | ||
comma := E' '; | ||
FOR m IN SELECT * FROM @[email protected]_columns(relid) LOOP | ||
IF m.key_id IS NULL AND m.key_id_column is NULL THEN | ||
CONTINUE; | ||
ELSE | ||
expression := expression || comma; | ||
expression := expression || format( | ||
$f$%s = pg_catalog.encode( | ||
@[email protected]_aead_det_encrypt( | ||
pg_catalog.convert_to(%s, 'utf8'), | ||
pg_catalog.convert_to(%s::text, 'utf8'), | ||
%s::uuid, | ||
%s | ||
), | ||
'base64')$f$, | ||
'new.' || quote_ident(m.attname), | ||
'new.' || quote_ident(m.attname), | ||
COALESCE('new.' || quote_ident(m.associated_column), quote_literal('')), | ||
COALESCE('new.' || quote_ident(m.key_id_column), quote_literal(m.key_id)), | ||
COALESCE('new.' || quote_ident(m.nonce_column), 'NULL') | ||
); | ||
END IF; | ||
comma := E';\n '; | ||
END LOOP; | ||
RETURN expression; | ||
END | ||
$$ | ||
LANGUAGE plpgsql | ||
VOLATILE | ||
SET search_path='' | ||
; | ||
|
||
CREATE OR REPLACE FUNCTION @[email protected]_columns( | ||
relid OID | ||
) | ||
RETURNS TEXT AS | ||
$$ | ||
DECLARE | ||
m RECORD; | ||
expression TEXT; | ||
comma TEXT; | ||
padding text = ' '; | ||
BEGIN | ||
expression := E'\n'; | ||
comma := padding; | ||
FOR m IN SELECT * FROM @[email protected]_columns(relid) LOOP | ||
expression := expression || comma; | ||
IF m.key_id IS NULL AND m.key_id_column IS NULL THEN | ||
expression := expression || padding || quote_ident(m.attname); | ||
ELSE | ||
expression := expression || padding || quote_ident(m.attname) || E',\n'; | ||
expression := expression || format( | ||
$f$ | ||
pg_catalog.convert_from( | ||
@[email protected]_aead_det_decrypt( | ||
pg_catalog.decode(%s, 'base64'), | ||
pg_catalog.convert_to(%s::text, 'utf8'), | ||
%s::uuid, | ||
%s | ||
), | ||
'utf8') AS %s$f$, | ||
quote_ident(m.attname), | ||
coalesce(quote_ident(m.associated_column), quote_literal('')), | ||
coalesce(quote_ident(m.key_id_column), quote_literal(m.key_id)), | ||
coalesce(quote_ident(m.nonce_column), 'NULL'), | ||
'decrypted_' || quote_ident(m.attname) | ||
); | ||
END IF; | ||
comma := E', \n'; | ||
END LOOP; | ||
RETURN expression; | ||
END | ||
$$ | ||
LANGUAGE plpgsql | ||
VOLATILE | ||
SET search_path='' | ||
; |
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