-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpg_crypt4gh.sql
More file actions
45 lines (35 loc) · 1.38 KB
/
pg_crypt4gh.sql
File metadata and controls
45 lines (35 loc) · 1.38 KB
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
42
43
-- 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 IMMUTABLE 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 IMMUTABLE STRICT;
-- Decrypts header and output the sha256 of the session keys
-- Note: does not output the session keys!
CREATE OR REPLACE FUNCTION header_session_keys_sha256(IN header bytea,
OUT pubkey bytea,
OUT sha256 bytea)
RETURNS SETOF record
AS 'MODULE_PATHNAME', 'pg_crypt4gh_header_session_keys_sha256'
LANGUAGE C IMMUTABLE STRICT;