From: | Abhijit Menon-Sen <ams(at)oryx(dot)com> |
---|---|
To: | pgsql-patches(at)postgresql(dot)org |
Subject: | md5(bytea) |
Date: | 2005-05-19 02:58:10 |
Message-ID: | 20050519025810.GA17298@penne.toroid.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-patches |
The appended patch fiddles with md5_text() until it handles any varlena,
and adds an entry for md5(bytea) to pg_proc.
-- ams
*** src/include/catalog/pg_proc.h~ 2005-05-19 07:45:05.191855191 +0530
--- src/include/catalog/pg_proc.h 2005-05-19 07:56:45.785482224 +0530
***************
*** 3267,3273 ****
DESCR("I/O");
/* cryptographic */
! DATA(insert OID = 2311 ( md5 PGNSP PGUID 12 f f t f i 1 25 "25" _null_ _null_ _null_ md5_text - _null_ ));
DESCR("calculates md5 hash");
/* crosstype operations for date vs. timestamp and timestamptz */
--- 3267,3275 ----
DESCR("I/O");
/* cryptographic */
! DATA(insert OID = 2311 ( md5 PGNSP PGUID 12 f f t f i 1 25 "25" _null_ _null_ _null_ md5_varlena - _null_ ));
! DESCR("calculates md5 hash");
! DATA(insert OID = 2321 ( md5 PGNSP PGUID 12 f f t f i 1 25 "17" _null_ _null_ _null_ md5_varlena - _null_ ));
DESCR("calculates md5 hash");
/* crosstype operations for date vs. timestamp and timestamptz */
*** src/include/utils/builtins.h~ 2005-05-19 07:56:05.737477425 +0530
--- src/include/utils/builtins.h 2005-05-19 07:56:16.249641262 +0530
***************
*** 571,577 ****
extern Datum array_to_text(PG_FUNCTION_ARGS);
extern Datum to_hex32(PG_FUNCTION_ARGS);
extern Datum to_hex64(PG_FUNCTION_ARGS);
! extern Datum md5_text(PG_FUNCTION_ARGS);
extern Datum unknownin(PG_FUNCTION_ARGS);
extern Datum unknownout(PG_FUNCTION_ARGS);
--- 571,577 ----
extern Datum array_to_text(PG_FUNCTION_ARGS);
extern Datum to_hex32(PG_FUNCTION_ARGS);
extern Datum to_hex64(PG_FUNCTION_ARGS);
! extern Datum md5_varlena(PG_FUNCTION_ARGS);
extern Datum unknownin(PG_FUNCTION_ARGS);
extern Datum unknownout(PG_FUNCTION_ARGS);
*** src/backend/utils/adt/varlena.c~ 2005-05-19 07:46:28.895234689 +0530
--- src/backend/utils/adt/varlena.c 2005-05-19 08:20:42.844470560 +0530
***************
*** 2297,2324 ****
}
/*
! * 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)
{
! text *in_text = PG_GETARG_TEXT_P(0);
size_t len;
! char *hexsum;
text *result_text;
/* Calculate the length of the buffer using varlena metadata */
! len = VARSIZE(in_text) - VARHDRSZ;
!
! /* leave room for the terminating '\0' */
! hexsum = (char *) palloc(MD5_HASH_LEN + 1);
/* get the hash result */
! if (md5_hash(VARDATA(in_text), len, hexsum) == false)
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory")));
--- 2297,2323 ----
}
/*
! * Create an md5 hash of a varlena and return it as hex
*
* md5 produces a 16 byte (128 bit) hash; double it for hex
*/
#define MD5_HASH_LEN 32
Datum
! md5_varlena(PG_FUNCTION_ARGS)
{
! /* It would be nice if we could avoid de-toasting the whole varlena,
! * and feed it to md5_hash in small chunks instead. */
! struct varlena *in = PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
size_t len;
! char hexsum[MD5_HASH_LEN+1];
text *result_text;
/* Calculate the length of the buffer using varlena metadata */
! len = VARSIZE(in) - VARHDRSZ;
/* get the hash result */
! if (md5_hash(VARDATA(in), len, hexsum) == false)
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory")));
From | Date | Subject | |
---|---|---|---|
Next Message | Neil Conway | 2005-05-19 03:15:33 | Re: lastval() |
Previous Message | John Burger | 2005-05-19 02:46:50 | Re: numeric precision when raising one numeric to another. |