Skip to content

Commit 22e042e

Browse files
committed
1.0.0, bytea all the things.
1 parent 7ca793c commit 22e042e

File tree

5 files changed

+43
-50
lines changed

5 files changed

+43
-50
lines changed
Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,22 @@ RETURNS bytea
2626
AS '$libdir/pgsodium', 'pgsodium_crypto_secretbox_noncegen'
2727
LANGUAGE C VOLATILE;
2828

29-
CREATE FUNCTION crypto_secretbox(message text, nonce bytea, key bytea)
29+
CREATE FUNCTION crypto_secretbox(message bytea, nonce bytea, key bytea)
3030
RETURNS bytea
3131
AS '$libdir/pgsodium', 'pgsodium_crypto_secretbox'
3232
LANGUAGE C IMMUTABLE STRICT;
3333

3434
CREATE FUNCTION crypto_secretbox_open(ciphertext bytea, nonce bytea, key bytea)
35-
RETURNS text
35+
RETURNS bytea
3636
AS '$libdir/pgsodium', 'pgsodium_crypto_secretbox_open'
3737
LANGUAGE C IMMUTABLE STRICT;
3838

39-
CREATE FUNCTION crypto_auth(message text, key bytea)
39+
CREATE FUNCTION crypto_auth(message bytea, key bytea)
4040
RETURNS bytea
4141
AS '$libdir/pgsodium', 'pgsodium_crypto_auth'
4242
LANGUAGE C IMMUTABLE STRICT;
4343

44-
CREATE FUNCTION crypto_auth_verify(mac bytea, message text, key bytea)
44+
CREATE FUNCTION crypto_auth_verify(mac bytea, message bytea, key bytea)
4545
RETURNS boolean
4646
AS '$libdir/pgsodium', 'pgsodium_crypto_auth_verify'
4747
LANGUAGE C IMMUTABLE STRICT;
@@ -51,12 +51,12 @@ RETURNS bytea
5151
AS '$libdir/pgsodium', 'pgsodium_crypto_auth_keygen'
5252
LANGUAGE C VOLATILE;
5353

54-
CREATE FUNCTION crypto_generichash(message text, key bytea DEFAULT NULL)
54+
CREATE FUNCTION crypto_generichash(message bytea, key bytea DEFAULT NULL)
5555
RETURNS bytea
5656
AS '$libdir/pgsodium', 'pgsodium_crypto_generichash'
5757
LANGUAGE C VOLATILE;
5858

59-
CREATE FUNCTION crypto_shorthash(message text, key bytea)
59+
CREATE FUNCTION crypto_shorthash(message bytea, key bytea)
6060
RETURNS bytea
6161
AS '$libdir/pgsodium', 'pgsodium_crypto_shorthash'
6262
LANGUAGE C VOLATILE STRICT;
@@ -73,13 +73,13 @@ RETURNS bytea
7373
AS '$libdir/pgsodium', 'pgsodium_crypto_box_noncegen'
7474
LANGUAGE C VOLATILE;
7575

76-
CREATE FUNCTION crypto_box(message text, nonce bytea, public bytea, secret bytea)
76+
CREATE FUNCTION crypto_box(message bytea, nonce bytea, public bytea, secret bytea)
7777
RETURNS bytea
7878
AS '$libdir/pgsodium', 'pgsodium_crypto_box'
7979
LANGUAGE C IMMUTABLE STRICT;
8080

8181
CREATE FUNCTION crypto_box_open(ciphertext bytea, nonce bytea, public bytea, secret bytea)
82-
RETURNS text
82+
RETURNS bytea
8383
AS '$libdir/pgsodium', 'pgsodium_crypto_box_open'
8484
LANGUAGE C IMMUTABLE STRICT;
8585

@@ -90,13 +90,13 @@ RETURNS SETOF crypto_sign_keypair
9090
AS '$libdir/pgsodium', 'pgsodium_crypto_sign_keypair'
9191
LANGUAGE C VOLATILE;
9292

93-
CREATE OR REPLACE FUNCTION crypto_sign(message text, key bytea)
93+
CREATE OR REPLACE FUNCTION crypto_sign(message bytea, key bytea)
9494
RETURNS bytea
9595
AS '$libdir/pgsodium', 'pgsodium_crypto_sign'
9696
LANGUAGE C IMMUTABLE STRICT;
9797

9898
CREATE OR REPLACE FUNCTION crypto_sign_open(signed_message bytea, key bytea)
99-
RETURNS text
99+
RETURNS bytea
100100
AS '$libdir/pgsodium', 'pgsodium_crypto_sign_open'
101101
LANGUAGE C IMMUTABLE STRICT;
102102

@@ -115,27 +115,27 @@ RETURNS bytea
115115
AS '$libdir/pgsodium', 'pgsodium_crypto_pwhash_saltgen'
116116
LANGUAGE C VOLATILE;
117117

118-
CREATE OR REPLACE FUNCTION crypto_pwhash(password text, salt bytea)
118+
CREATE OR REPLACE FUNCTION crypto_pwhash(password bytea, salt bytea)
119119
RETURNS bytea
120120
AS '$libdir/pgsodium', 'pgsodium_crypto_pwhash'
121121
LANGUAGE C IMMUTABLE STRICT;
122122

123-
CREATE OR REPLACE FUNCTION crypto_pwhash_str(password text)
124-
RETURNS text
123+
CREATE OR REPLACE FUNCTION crypto_pwhash_str(password bytea)
124+
RETURNS bytea
125125
AS '$libdir/pgsodium', 'pgsodium_crypto_pwhash_str'
126126
LANGUAGE C VOLATILE STRICT;
127127

128-
CREATE OR REPLACE FUNCTION crypto_pwhash_str_verify(hashed_password text, password text)
128+
CREATE OR REPLACE FUNCTION crypto_pwhash_str_verify(hashed_password bytea, password bytea)
129129
RETURNS bool
130130
AS '$libdir/pgsodium', 'pgsodium_crypto_pwhash_str_verify'
131131
LANGUAGE C IMMUTABLE STRICT;
132132

133-
CREATE OR REPLACE FUNCTION crypto_box_seal(message text, public_key bytea)
133+
CREATE OR REPLACE FUNCTION crypto_box_seal(message bytea, public_key bytea)
134134
RETURNS bytea
135135
AS '$libdir/pgsodium', 'pgsodium_crypto_box_seal'
136136
LANGUAGE C VOLATILE STRICT;
137137

138138
CREATE OR REPLACE FUNCTION crypto_box_seal_open(ciphertext bytea, public_key bytea, secret_key bytea)
139-
RETURNS text
139+
RETURNS bytea
140140
AS '$libdir/pgsodium', 'pgsodium_crypto_box_seal_open'
141141
LANGUAGE C VOLATILE STRICT;

pgsodium.control

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# pgsodium extension
22
comment = 'Postgres extension for libsodium functions'
3-
default_version = '0.0.1'
3+
default_version = '1.0.0'
44
relocatable = true
55
requires = ''

src/pgsodium.c

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ PG_FUNCTION_INFO_V1(pgsodium_crypto_secretbox);
6363
Datum
6464
pgsodium_crypto_secretbox(PG_FUNCTION_ARGS)
6565
{
66-
text *message = PG_GETARG_TEXT_P(0);
66+
bytea *message = PG_GETARG_BYTEA_P(0);
6767
bytea *nonce = PG_GETARG_BYTEA_P(1);
6868
bytea *key = PG_GETARG_BYTEA_P(2);
6969
size_t message_size = crypto_secretbox_MACBYTES + VARSIZE_ANY_EXHDR(message);
@@ -92,7 +92,7 @@ pgsodium_crypto_secretbox_open(PG_FUNCTION_ARGS)
9292
bytea *key = PG_GETARG_BYTEA_P(2);
9393
size_t message_size = VARSIZE_ANY_EXHDR(message) - crypto_secretbox_MACBYTES;
9494
unsigned long long result_size = VARHDRSZ + message_size;
95-
text *result = (text *) palloc(result_size);
95+
bytea *result = (bytea *) palloc(result_size);
9696
ZERO_BUFF_CB(result, result_size);
9797
SET_VARSIZE(result, result_size);
9898

@@ -109,14 +109,14 @@ pgsodium_crypto_secretbox_open(PG_FUNCTION_ARGS)
109109
(errcode(ERRCODE_DATA_EXCEPTION),
110110
errmsg("invalid message")));
111111

112-
PG_RETURN_TEXT_P(result);
112+
PG_RETURN_BYTEA_P(result);
113113
}
114114

115115
PG_FUNCTION_INFO_V1(pgsodium_crypto_auth);
116116
Datum
117117
pgsodium_crypto_auth(PG_FUNCTION_ARGS)
118118
{
119-
text *message = PG_GETARG_TEXT_P(0);
119+
bytea *message = PG_GETARG_BYTEA_P(0);
120120
bytea *key = PG_GETARG_BYTEA_P(1);
121121
int result_size = VARHDRSZ + crypto_auth_BYTES;
122122
bytea *result = (bytea*)palloc(result_size);
@@ -137,7 +137,7 @@ pgsodium_crypto_auth_verify(PG_FUNCTION_ARGS)
137137
{
138138
int success;
139139
bytea *mac = PG_GETARG_BYTEA_P(0);
140-
text *message = PG_GETARG_BYTEA_P(1);
140+
bytea *message = PG_GETARG_BYTEA_P(1);
141141
bytea *key = PG_GETARG_BYTEA_P(2);
142142

143143
success = crypto_auth_verify(
@@ -164,14 +164,14 @@ PG_FUNCTION_INFO_V1(pgsodium_crypto_generichash);
164164
Datum
165165
pgsodium_crypto_generichash(PG_FUNCTION_ARGS)
166166
{
167-
text *data;
167+
bytea *data;
168168
bytea *result;
169169
bytea *keyarg;
170170
unsigned char *key = NULL;
171171
size_t keylen = 0;
172172
unsigned long long result_size;
173173

174-
data = PG_GETARG_TEXT_P(0);
174+
data = PG_GETARG_BYTEA_P(0);
175175
if (!PG_ARGISNULL(1))
176176
{
177177
keyarg = PG_GETARG_BYTEA_P(1);
@@ -198,12 +198,12 @@ PG_FUNCTION_INFO_V1(pgsodium_crypto_shorthash);
198198
Datum
199199
pgsodium_crypto_shorthash(PG_FUNCTION_ARGS)
200200
{
201-
text *data;
201+
bytea *data;
202202
bytea *result;
203203
bytea *key;
204204
int result_size = VARHDRSZ + crypto_shorthash_BYTES;
205205

206-
data = PG_GETARG_TEXT_P(0);
206+
data = PG_GETARG_BYTEA_P(0);
207207
key = PG_GETARG_BYTEA_P(1);
208208
if (VARSIZE_ANY_EXHDR(key) != crypto_shorthash_KEYBYTES)
209209
PG_RETURN_NULL();
@@ -275,7 +275,7 @@ PG_FUNCTION_INFO_V1(pgsodium_crypto_box);
275275
Datum
276276
pgsodium_crypto_box(PG_FUNCTION_ARGS)
277277
{
278-
text *message = PG_GETARG_TEXT_P(0);
278+
bytea *message = PG_GETARG_BYTEA_P(0);
279279
bytea *nonce = PG_GETARG_BYTEA_P(1);
280280
bytea *publickey = PG_GETARG_BYTEA_P(2);
281281
bytea *secretkey = PG_GETARG_BYTEA_P(3);
@@ -313,7 +313,7 @@ pgsodium_crypto_box_open(PG_FUNCTION_ARGS)
313313
bytea *secretkey = PG_GETARG_BYTEA_P(3);
314314

315315
size_t message_size = VARSIZE_ANY_EXHDR(message) - crypto_box_MACBYTES;
316-
text *result = (text *) palloc(VARHDRSZ + message_size);
316+
bytea *result = (bytea *) palloc(VARHDRSZ + message_size);
317317
ZERO_BUFF_CB(result, VARHDRSZ + message_size);
318318
SET_VARSIZE(result, VARHDRSZ + message_size);
319319
success = crypto_box_open_easy(
@@ -328,7 +328,7 @@ pgsodium_crypto_box_open(PG_FUNCTION_ARGS)
328328
ERROR,
329329
(errcode(ERRCODE_DATA_EXCEPTION),
330330
errmsg("invalid message")));
331-
PG_RETURN_TEXT_P(result);
331+
PG_RETURN_BYTEA_P(result);
332332
}
333333

334334
PG_FUNCTION_INFO_V1(pgsodium_crypto_sign_keypair);
@@ -375,7 +375,7 @@ Datum
375375
pgsodium_crypto_sign(PG_FUNCTION_ARGS)
376376
{
377377
int success;
378-
text *message = PG_GETARG_TEXT_P(0);
378+
bytea *message = PG_GETARG_BYTEA_P(0);
379379
bytea *secretkey = PG_GETARG_BYTEA_P(1);
380380
unsigned long long signed_message_len;
381381
size_t message_size = crypto_sign_BYTES + VARSIZE_ANY_EXHDR(message);
@@ -409,7 +409,7 @@ pgsodium_crypto_sign_open(PG_FUNCTION_ARGS)
409409
bytea *publickey = PG_GETARG_BYTEA_P(1);
410410
size_t message_size = VARSIZE_ANY_EXHDR(message) - crypto_sign_BYTES;
411411
unsigned long long result_size = VARHDRSZ + message_size;
412-
text *result = (text *) palloc(result_size);
412+
bytea *result = (bytea *) palloc(result_size);
413413
ZERO_BUFF_CB(result, result_size);
414414

415415
SET_VARSIZE(result, result_size);
@@ -425,7 +425,7 @@ pgsodium_crypto_sign_open(PG_FUNCTION_ARGS)
425425
ERROR,
426426
(errcode(ERRCODE_DATA_EXCEPTION),
427427
errmsg("invalid message")));
428-
PG_RETURN_TEXT_P(result);
428+
PG_RETURN_BYTEA_P(result);
429429
}
430430

431431
PG_FUNCTION_INFO_V1(pgsodium_crypto_sign_detached);
@@ -494,13 +494,13 @@ PG_FUNCTION_INFO_V1(pgsodium_crypto_pwhash);
494494
Datum
495495
pgsodium_crypto_pwhash(PG_FUNCTION_ARGS)
496496
{
497-
text *data;
497+
bytea *data;
498498
bytea *result;
499499
bytea *salt;
500500
int result_size = VARHDRSZ + crypto_box_SEEDBYTES;
501501
int success;
502502

503-
data = PG_GETARG_TEXT_P(0);
503+
data = PG_GETARG_BYTEA_P(0);
504504
salt = PG_GETARG_BYTEA_P(1);
505505
if (VARSIZE_ANY_EXHDR(salt) != crypto_pwhash_SALTBYTES)
506506
PG_RETURN_NULL();
@@ -532,8 +532,8 @@ Datum
532532
pgsodium_crypto_pwhash_str(PG_FUNCTION_ARGS)
533533
{
534534
int success;
535-
text *password = PG_GETARG_TEXT_P(0);
536-
text *result = (text *)palloc(crypto_pwhash_STRBYTES);
535+
bytea *password = PG_GETARG_BYTEA_P(0);
536+
bytea *result = (bytea *)palloc(crypto_pwhash_STRBYTES);
537537
ZERO_BUFF_CB(result, crypto_pwhash_STRBYTES);
538538
SET_VARSIZE(result, crypto_pwhash_STRBYTES);
539539

@@ -549,16 +549,16 @@ pgsodium_crypto_pwhash_str(PG_FUNCTION_ARGS)
549549
ERROR,
550550
(errcode(ERRCODE_DATA_EXCEPTION),
551551
errmsg("out of memory in pwhash_str")));
552-
PG_RETURN_TEXT_P(result);
552+
PG_RETURN_BYTEA_P(result);
553553
}
554554

555555
PG_FUNCTION_INFO_V1(pgsodium_crypto_pwhash_str_verify);
556556
Datum
557557
pgsodium_crypto_pwhash_str_verify(PG_FUNCTION_ARGS)
558558
{
559559
int success;
560-
text *hashed_password = PG_GETARG_TEXT_P(0);
561-
text *password = PG_GETARG_TEXT_P(1);
560+
bytea *hashed_password = PG_GETARG_BYTEA_P(0);
561+
bytea *password = PG_GETARG_BYTEA_P(1);
562562
success = crypto_pwhash_str_verify(
563563
VARDATA(hashed_password),
564564
VARDATA(password),
@@ -572,7 +572,7 @@ PG_FUNCTION_INFO_V1(pgsodium_crypto_box_seal);
572572
Datum
573573
pgsodium_crypto_box_seal(PG_FUNCTION_ARGS)
574574
{
575-
text *message = PG_GETARG_TEXT_P(0);
575+
bytea *message = PG_GETARG_BYTEA_P(0);
576576
bytea *public_key = PG_GETARG_BYTEA_P(1);
577577
unsigned long long result_size = crypto_box_SEALBYTES + VARSIZE(message);
578578

@@ -598,7 +598,7 @@ pgsodium_crypto_box_seal_open(PG_FUNCTION_ARGS)
598598
bytea *secret_key = PG_GETARG_BYTEA_P(2);
599599

600600
unsigned long long result_size = VARSIZE(ciphertext) - crypto_box_SEALBYTES;
601-
text *result = (text *)palloc(result_size);
601+
bytea *result = (bytea *)palloc(result_size);
602602
ZERO_BUFF_CB(result, result_size);
603603
SET_VARSIZE(result, result_size);
604604

@@ -614,7 +614,7 @@ pgsodium_crypto_box_seal_open(PG_FUNCTION_ARGS)
614614
ERROR,
615615
(errcode(ERRCODE_DATA_EXCEPTION),
616616
errmsg("crypto_box_seal_open: invalid message")));
617-
PG_RETURN_TEXT_P(result);
617+
PG_RETURN_BYTEA_P(result);
618618
}
619619

620620
void _PG_init(void)

test.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,3 @@ do
3131
echo destroying test container and image
3232
docker rm --force "$DB_HOST"
3333
done
34-

test.sql

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,21 +75,15 @@ SELECT crypto_sign('bob is your uncle', :'sign_secret') signed \gset
7575
SELECT is(crypto_sign_open(:'signed', :'sign_public'),
7676
'bob is your uncle', 'crypto_sign/open');
7777

78-
-- MM Start Tests for crypto_sign_detached. You may want to move
79-
-- these if you want to preserve the previous test numbering
80-
8178
-- We will sign our previously generated sealed box
8279
SELECT crypto_sign_detached(:'sealed', :'sign_secret') detached \gset
8380

8481
SELECT is(crypto_sign_verify_detached(:'detached', :'sealed', :'sign_public'),
8582
true, 'crypto_sign_detached/verify');
8683

87-
SELECT is(crypto_sign_verify_detached(:'detached', 'xyzzy'::bytea, :'sign_public'),
84+
SELECT is(crypto_sign_verify_detached(:'detached', 'xyzzy', :'sign_public'),
8885
false, 'crypto_sign_detached/verify (incorrect message)');
8986

90-
-- MM End
91-
92-
9387
SELECT lives_ok($$SELECT crypto_pwhash_saltgen()$$, 'crypto_pwhash_saltgen');
9488

9589
SELECT is(crypto_pwhash('Correct Horse Battery Staple', '\xccfe2b51d426f88f6f8f18c24635616b'),

0 commit comments

Comments
 (0)