diff options
author | Bruce Momjian <bruce@momjian.us> | 2002-12-06 05:20:28 +0000 |
---|---|---|
committer | Bruce Momjian <bruce@momjian.us> | 2002-12-06 05:20:28 +0000 |
commit | e87e82d2b7c6407551988ad8c3f153128163f4a4 (patch) | |
tree | aeeb31ede91f36ad58bd11254588f07ca876a5b3 /src/backend/utils | |
parent | 88ae9cd4118a0eb4a6fd8acc87f453ec113c113d (diff) | |
download | postgresql-e87e82d2b7c6407551988ad8c3f153128163f4a4.tar.gz postgresql-e87e82d2b7c6407551988ad8c3f153128163f4a4.zip |
Attached are two small patches to expose md5 as a user function -- including
documentation and regression test mods. It seemed small and unobtrusive enough
to not require a specific proposal on the hackers list -- but if not, let me
know and I'll make a pitch. Otherwise, if there are no objections please apply.
Joe Conway
Diffstat (limited to 'src/backend/utils')
-rw-r--r-- | src/backend/utils/adt/varlena.c | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/src/backend/utils/adt/varlena.c b/src/backend/utils/adt/varlena.c index 1dd2901bd0c..e98a2dfe0e3 100644 --- a/src/backend/utils/adt/varlena.c +++ b/src/backend/utils/adt/varlena.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.93 2002/11/17 23:01:30 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.94 2002/12/06 05:20:17 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -23,6 +23,7 @@ #include "utils/builtins.h" #include "utils/pg_locale.h" +extern bool md5_hash(const void *buff, size_t len, char *hexsum); typedef struct varlena unknown; @@ -1839,3 +1840,29 @@ to_hex64(PG_FUNCTION_ARGS) result_text = PG_STR_GET_TEXT(ptr); PG_RETURN_TEXT_P(result_text); } + +/* + * Create an md5 hash of a text string and return it as hex + * + * md5 produces a 16 byte (128 bit) hash; double it for hex + */ +#define MD5_HASH_LEN 32 + +Datum +md5_text(PG_FUNCTION_ARGS) +{ + char *buff = PG_TEXT_GET_STR(PG_GETARG_TEXT_P(0)); + size_t len = strlen(buff); + char *hexsum; + text *result_text; + + /* leave room for the terminating '\0' */ + hexsum = (char *) palloc(MD5_HASH_LEN + 1); + + /* get the hash result */ + md5_hash((void *) buff, len, hexsum); + + /* convert to text and return it */ + result_text = PG_STR_GET_TEXT(hexsum); + PG_RETURN_TEXT_P(result_text); +} |