-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpg_crypt4gh.sql
43 lines (33 loc) · 1.26 KB
/
pg_crypt4gh.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION pg_crypt4gh" to load this file. \quit
DO $$
BEGIN
IF current_setting('crypt4gh.master_seckey') IS NULL
THEN
RAISE EXCEPTION 'Missing Crypt4GH settings'
USING HINT = 'Add crypt4gh.master_seckey = ''...'' (in hex format) in postgresql.conf ';
END IF;
END;
$$;
-- STRICT = NULL parameters return NULL immediately
-- Extract 32 bytes from pubkey text
CREATE OR REPLACE FUNCTION parse_pubkey(text)
RETURNS bytea
AS 'MODULE_PATHNAME', 'pg_crypt4gh_parse_pubkey'
LANGUAGE C IMMUTABLE STRICT;
-- Re-encrypt header for given pubkey (as 32-bytes)
CREATE OR REPLACE FUNCTION header_reencrypt(bytea, bytea)
RETURNS bytea
AS 'MODULE_PATHNAME', 'pg_crypt4gh_header_reencrypt'
LANGUAGE C VOLATILE STRICT;
-- Re-encrypt header for given array of pubkeys (as 32-bytes)
CREATE OR REPLACE FUNCTION header_reencrypt(bytea, bytea[])
RETURNS bytea
AS 'MODULE_PATHNAME', 'pg_crypt4gh_header_reencrypt_multiple'
LANGUAGE C VOLATILE STRICT;
-- Decrypts header and output the session keys
-- OBS: output sensitive material!
CREATE OR REPLACE FUNCTION header_session_keys(bytea)
RETURNS SETOF bytea
AS 'MODULE_PATHNAME', 'pg_crypt4gh_header_session_keys'
LANGUAGE C IMMUTABLE STRICT;