File tree 9 files changed +67
-3
lines changed
9 files changed +67
-3
lines changed Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ MODULE_big = pgcrypto
26
26
OBJS = $(SRCS:.c=.o )
27
27
28
28
EXTENSION = pgcrypto
29
- DATA = pgcrypto--1.0 .sql pgcrypto--unpackaged--1.0.sql
29
+ DATA = pgcrypto--1.1.sql pgcrypto--1.0--1.1 .sql pgcrypto--unpackaged--1.0.sql
30
30
31
31
REGRESS = init md5 sha1 hmac-md5 hmac-sha1 blowfish rijndael \
32
32
$(CF_TESTS ) \
Original file line number Diff line number Diff line change
1
+ /* contrib/pgcrypto/pgcrypto--1.0--1.1.sql */
2
+
3
+ -- complain if script is sourced in psql, rather than via ALTER EXTENSION
4
+ \echo Use " ALTER EXTENSION pgcrypto UPDATE TO '1.1'" to load this file. \quit
5
+
6
+ CREATE FUNCTION gen_random_uuid ()
7
+ RETURNS uuid
8
+ AS ' MODULE_PATHNAME' , ' pg_random_uuid'
9
+ LANGUAGE C VOLATILE;
Original file line number Diff line number Diff line change 1
- /* contrib/pgcrypto/pgcrypto--1.0 .sql */
1
+ /* contrib/pgcrypto/pgcrypto--1.1 .sql */
2
2
3
3
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
4
4
\echo Use " CREATE EXTENSION pgcrypto" to load this file. \quit
@@ -63,6 +63,11 @@ RETURNS bytea
63
63
AS ' MODULE_PATHNAME' , ' pg_random_bytes'
64
64
LANGUAGE C VOLATILE STRICT;
65
65
66
+ CREATE FUNCTION gen_random_uuid ()
67
+ RETURNS uuid
68
+ AS ' MODULE_PATHNAME' , ' pg_random_uuid'
69
+ LANGUAGE C VOLATILE;
70
+
66
71
--
67
72
-- pgp_sym_encrypt(data, key)
68
73
--
Original file line number Diff line number Diff line change 35
35
36
36
#include "parser/scansup.h"
37
37
#include "utils/builtins.h"
38
+ #include "utils/uuid.h"
38
39
39
40
#include "px.h"
40
41
#include "px-crypt.h"
@@ -443,6 +444,32 @@ pg_random_bytes(PG_FUNCTION_ARGS)
443
444
PG_RETURN_BYTEA_P (res );
444
445
}
445
446
447
+ /* SQL function: gen_random_uuid() returns uuid */
448
+ PG_FUNCTION_INFO_V1 (pg_random_uuid );
449
+
450
+ Datum
451
+ pg_random_uuid (PG_FUNCTION_ARGS )
452
+ {
453
+ uint8 * buf = (uint8 * ) palloc (UUID_LEN );
454
+ int err ;
455
+
456
+ /* generate random bits */
457
+ err = px_get_pseudo_random_bytes (buf , UUID_LEN );
458
+ if (err < 0 )
459
+ ereport (ERROR ,
460
+ (errcode (ERRCODE_EXTERNAL_ROUTINE_INVOCATION_EXCEPTION ),
461
+ errmsg ("Random generator error: %s" , px_strerror (err ))));
462
+
463
+ /*
464
+ * Set magic numbers for a "version 4" (pseudorandom) UUID, see
465
+ * http://tools.ietf.org/html/rfc4122#section-4.4
466
+ */
467
+ buf [6 ] = (buf [6 ] & 0x0f ) | 0x40 ; /* "version" field */
468
+ buf [8 ] = (buf [8 ] & 0x3f ) | 0x80 ; /* "variant" field */
469
+
470
+ PG_RETURN_UUID_P ((pg_uuid_t * ) buf );
471
+ }
472
+
446
473
static void *
447
474
find_provider (text * name ,
448
475
PFN provider_lookup ,
Original file line number Diff line number Diff line change 1
1
# pgcrypto extension
2
2
comment = 'cryptographic functions'
3
- default_version = '1.0 '
3
+ default_version = '1.1 '
4
4
module_pathname = '$libdir/pgcrypto'
5
5
relocatable = true
Original file line number Diff line number Diff line change @@ -45,5 +45,6 @@ Datum pg_decrypt(PG_FUNCTION_ARGS);
45
45
Datum pg_encrypt_iv (PG_FUNCTION_ARGS );
46
46
Datum pg_decrypt_iv (PG_FUNCTION_ARGS );
47
47
Datum pg_random_bytes (PG_FUNCTION_ARGS );
48
+ Datum pg_random_uuid (PG_FUNCTION_ARGS );
48
49
49
50
#endif
Original file line number Diff line number Diff line change @@ -4015,6 +4015,8 @@ a0ee-bc99-9c0b-4ef8-bb6d-6bb9-bd38-0a11
4015
4015
suited for every application. The <xref
4016
4016
linkend="uuid-ossp"> module
4017
4017
provides functions that implement several standard algorithms.
4018
+ The <xref linkend="pgcrypto"> module also provides a generation
4019
+ function for random UUIDs.
4018
4020
Alternatively, UUIDs could be generated by client applications or
4019
4021
other libraries invoked through a server-side function.
4020
4022
</para>
Original file line number Diff line number Diff line change @@ -1084,6 +1084,17 @@ gen_random_bytes(count integer) returns bytea
1084
1084
At most 1024 bytes can be extracted at a time. This is to avoid
1085
1085
draining the randomness generator pool.
1086
1086
</para>
1087
+
1088
+ <indexterm>
1089
+ <primary>gen_random_uuid</primary>
1090
+ </indexterm>
1091
+
1092
+ <synopsis>
1093
+ gen_random_uuid() returns uuid
1094
+ </synopsis>
1095
+ <para>
1096
+ Returns a version 4 (random) UUID.
1097
+ </para>
1087
1098
</sect2>
1088
1099
1089
1100
<sect2>
Original file line number Diff line number Diff line change 18
18
<ulink url="http://www.ossp.org/pkg/lib/uuid/"></ulink>.
19
19
</para>
20
20
21
+ <note>
22
+ <para>
23
+ The OSSP UUID library is not well maintained, and is becoming increasingly
24
+ difficult to port to newer platforms. If you only need randomly-generated
25
+ (version 4) UUIDs, consider using the <function>gen_random_uuid()</>
26
+ function from the <xref linkend="pgcrypto"> module instead.
27
+ </para>
28
+ </note>
29
+
21
30
<sect2>
22
31
<title><literal>uuid-ossp</literal> Functions</title>
23
32
You can’t perform that action at this time.
0 commit comments