-
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.
First cut adding random data generation function.
- Loading branch information
Showing
6 changed files
with
73 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#http://blog.pgxn.org/post/4783001135/extension-makefiles pg makefiles | ||
EXTENSION = pgsodium | ||
PG_CONFIG ?= pg_config | ||
DATA = $(wildcard *--*.sql) | ||
PGXS := $(shell $(PG_CONFIG) --pgxs) | ||
MODULE_big = pgsodium | ||
OBJS = $(patsubst %.c,%.o,$(wildcard src/*.c)) | ||
#TESTS = $(wildcard test/sql/*.sql) | ||
#REGRESS = $(patsubst test/sql/%.sql,%,$(TESTS)) | ||
#REGRESS_OPTS = --inputdir=test --load-language=plpgsql | ||
include $(PGXS) | ||
|
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 +1,3 @@ | ||
# pgsodium | ||
# pgsodium | ||
|
||
Postgres extension to expose libsodium functions to SQL. |
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,3 @@ | ||
-- complain if script is sourced in psql, rather than via CREATE EXTENSION | ||
\echo Use "CREATE EXTENSION pgsodium" to load this file. \quit | ||
|
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,5 @@ | ||
# pgsodium extension | ||
comment = 'Postgres extension for libsodium functions' | ||
default_version = '0.0.1' | ||
relocatable = true | ||
requires = '' |
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,36 @@ | ||
#include "pgsodium.h" | ||
#include <sodium.h> | ||
PG_MODULE_MAGIC; | ||
|
||
PG_FUNCTION_INFO_V1(pgsodium_randombytes_random); | ||
Datum | ||
pgsodium_randombytes_random(PG_FUNCTION_ARGS) | ||
{ | ||
PG_RETURN_UINT32(randombytes_random()); | ||
} | ||
|
||
PG_FUNCTION_INFO_V1(pgsodium_randombytes_uniform); | ||
Datum | ||
pgsodium_randombytes_uniform(PG_FUNCTION_ARGS) | ||
{ | ||
uint32_t upper_bound = PG_GETARG_UINT32(0); | ||
PG_RETURN_UINT32(randombytes_uniform(upper_bound)); | ||
} | ||
|
||
PG_FUNCTION_INFO_V1(pgsodium_randombytes_buf); | ||
Datum | ||
pgsodium_randombytes_buf(PG_FUNCTION_ARGS) | ||
{ | ||
size_t size = PG_GETARG_UINT32(0); | ||
bytea *ret = (bytea *) palloc(VARHDRSZ + size); | ||
SET_VARSIZE(ret, VARHDRSZ + size); | ||
randombytes_buf(VARDATA(ret), size); | ||
PG_RETURN_BYTEA_P(ret); | ||
} | ||
|
||
void _PG_init(void) { | ||
if (sodium_init() == -1) { | ||
elog(ERROR, "_PG_init: sodium_init() failed cannot initialize pgsodium"); | ||
return; | ||
} | ||
} |
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,14 @@ | ||
#ifndef PGSODIUM_H | ||
#define PGSODIUM_H | ||
|
||
#include "postgres.h" | ||
#include "utils/builtins.h" | ||
#include "libpq/pqformat.h" | ||
|
||
void _PG_init(void); | ||
|
||
Datum pgsodium_randombytes_random(PG_FUNCTION_ARGS); | ||
Datum pgsodium_randombytes_uniform(PG_FUNCTION_ARGS); | ||
Datum pgsodium_randombytes_buf(PG_FUNCTION_ARGS); | ||
|
||
#endif // PGSODIUM_H |