mirror of https://github.com/postgres/postgres
Minor code cleanup for pgcrypto: for UDFs declared to be strict, checking
for NULL-ness of function arguments is wasted code.
This commit is contained in:
parent
d19798e584
commit
87a50169d2
|
@ -26,7 +26,7 @@
|
|||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $PostgreSQL: pgsql/contrib/pgcrypto/pgcrypto.c,v 1.24 2006/10/04 00:29:46 momjian Exp $
|
||||
* $PostgreSQL: pgsql/contrib/pgcrypto/pgcrypto.c,v 1.25 2006/11/10 06:28:29 neilc Exp $
|
||||
*/
|
||||
|
||||
#include "postgres.h"
|
||||
|
@ -45,8 +45,7 @@ PG_MODULE_MAGIC;
|
|||
/* private stuff */
|
||||
|
||||
typedef int (*PFN) (const char *name, void **res);
|
||||
static void *
|
||||
find_provider(text *name, PFN pf, char *desc, int silent);
|
||||
static void *find_provider(text *name, PFN pf, char *desc, int silent);
|
||||
|
||||
/* SQL function: hash(bytea, text) returns bytea */
|
||||
PG_FUNCTION_INFO_V1(pg_digest);
|
||||
|
@ -61,9 +60,6 @@ pg_digest(PG_FUNCTION_ARGS)
|
|||
PX_MD *md;
|
||||
bytea *res;
|
||||
|
||||
if (PG_ARGISNULL(0) || PG_ARGISNULL(1))
|
||||
PG_RETURN_NULL();
|
||||
|
||||
name = PG_GETARG_TEXT_P(1);
|
||||
|
||||
/* will give error if fails */
|
||||
|
@ -102,9 +98,6 @@ pg_hmac(PG_FUNCTION_ARGS)
|
|||
PX_HMAC *h;
|
||||
bytea *res;
|
||||
|
||||
if (PG_ARGISNULL(0) || PG_ARGISNULL(1) || PG_ARGISNULL(2))
|
||||
PG_RETURN_NULL();
|
||||
|
||||
name = PG_GETARG_TEXT_P(2);
|
||||
|
||||
/* will give error if fails */
|
||||
|
@ -144,9 +137,6 @@ pg_gen_salt(PG_FUNCTION_ARGS)
|
|||
text *res;
|
||||
char buf[PX_MAX_SALT_LEN + 1];
|
||||
|
||||
if (PG_ARGISNULL(0))
|
||||
PG_RETURN_NULL();
|
||||
|
||||
arg0 = PG_GETARG_TEXT_P(0);
|
||||
|
||||
len = VARSIZE(arg0) - VARHDRSZ;
|
||||
|
@ -180,9 +170,6 @@ pg_gen_salt_rounds(PG_FUNCTION_ARGS)
|
|||
text *res;
|
||||
char buf[PX_MAX_SALT_LEN + 1];
|
||||
|
||||
if (PG_ARGISNULL(0) || PG_ARGISNULL(1))
|
||||
PG_RETURN_NULL();
|
||||
|
||||
arg0 = PG_GETARG_TEXT_P(0);
|
||||
rounds = PG_GETARG_INT32(1);
|
||||
|
||||
|
@ -222,9 +209,6 @@ pg_crypt(PG_FUNCTION_ARGS)
|
|||
*resbuf;
|
||||
text *res;
|
||||
|
||||
if (PG_ARGISNULL(0) || PG_ARGISNULL(1))
|
||||
PG_RETURN_NULL();
|
||||
|
||||
arg0 = PG_GETARG_TEXT_P(0);
|
||||
arg1 = PG_GETARG_TEXT_P(1);
|
||||
len0 = VARSIZE(arg0) - VARHDRSZ;
|
||||
|
@ -239,9 +223,7 @@ pg_crypt(PG_FUNCTION_ARGS)
|
|||
buf0[len0] = '\0';
|
||||
buf1[len1] = '\0';
|
||||
|
||||
resbuf = palloc(PX_MAX_CRYPT);
|
||||
|
||||
memset(resbuf, 0, PX_MAX_CRYPT);
|
||||
resbuf = palloc0(PX_MAX_CRYPT);
|
||||
|
||||
cres = px_crypt(buf0, buf1, resbuf, PX_MAX_CRYPT);
|
||||
|
||||
|
@ -282,9 +264,6 @@ pg_encrypt(PG_FUNCTION_ARGS)
|
|||
klen,
|
||||
rlen;
|
||||
|
||||
if (PG_ARGISNULL(0) || PG_ARGISNULL(1) || PG_ARGISNULL(2))
|
||||
PG_RETURN_NULL();
|
||||
|
||||
type = PG_GETARG_TEXT_P(2);
|
||||
c = find_provider(type, (PFN) px_find_combo, "Cipher", 0);
|
||||
|
||||
|
@ -334,9 +313,6 @@ pg_decrypt(PG_FUNCTION_ARGS)
|
|||
klen,
|
||||
rlen;
|
||||
|
||||
if (PG_ARGISNULL(0) || PG_ARGISNULL(1) || PG_ARGISNULL(2))
|
||||
PG_RETURN_NULL();
|
||||
|
||||
type = PG_GETARG_TEXT_P(2);
|
||||
c = find_provider(type, (PFN) px_find_combo, "Cipher", 0);
|
||||
|
||||
|
@ -387,10 +363,6 @@ pg_encrypt_iv(PG_FUNCTION_ARGS)
|
|||
ivlen,
|
||||
rlen;
|
||||
|
||||
if (PG_ARGISNULL(0) || PG_ARGISNULL(1)
|
||||
|| PG_ARGISNULL(2) || PG_ARGISNULL(3))
|
||||
PG_RETURN_NULL();
|
||||
|
||||
type = PG_GETARG_TEXT_P(3);
|
||||
c = find_provider(type, (PFN) px_find_combo, "Cipher", 0);
|
||||
|
||||
|
@ -445,10 +417,6 @@ pg_decrypt_iv(PG_FUNCTION_ARGS)
|
|||
rlen,
|
||||
ivlen;
|
||||
|
||||
if (PG_ARGISNULL(0) || PG_ARGISNULL(1)
|
||||
|| PG_ARGISNULL(2) || PG_ARGISNULL(3))
|
||||
PG_RETURN_NULL();
|
||||
|
||||
type = PG_GETARG_TEXT_P(3);
|
||||
c = find_provider(type, (PFN) px_find_combo, "Cipher", 0);
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $PostgreSQL: pgsql/contrib/pgcrypto/pgp-pgsql.c,v 1.7 2005/11/22 18:17:04 momjian Exp $
|
||||
* $PostgreSQL: pgsql/contrib/pgcrypto/pgp-pgsql.c,v 1.8 2006/11/10 06:28:29 neilc Exp $
|
||||
*/
|
||||
|
||||
#include "postgres.h"
|
||||
|
@ -74,18 +74,6 @@ PG_FUNCTION_INFO_V1(pgp_key_id_w);
|
|||
PG_FUNCTION_INFO_V1(pg_armor);
|
||||
PG_FUNCTION_INFO_V1(pg_dearmor);
|
||||
|
||||
/*
|
||||
* check for NULL arguments
|
||||
*/
|
||||
#define CHECK_ARGS() \
|
||||
do { \
|
||||
int a; \
|
||||
for (a = 0; a < PG_NARGS(); a++) { \
|
||||
if (PG_ARGISNULL(a)) \
|
||||
PG_RETURN_NULL(); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/*
|
||||
* Mix a block of data into RNG.
|
||||
*/
|
||||
|
@ -660,7 +648,6 @@ pgp_sym_encrypt_bytea(PG_FUNCTION_ARGS)
|
|||
text *arg = NULL;
|
||||
text *res;
|
||||
|
||||
CHECK_ARGS();
|
||||
data = PG_GETARG_BYTEA_P(0);
|
||||
key = PG_GETARG_BYTEA_P(1);
|
||||
if (PG_NARGS() > 2)
|
||||
|
@ -683,7 +670,6 @@ pgp_sym_encrypt_text(PG_FUNCTION_ARGS)
|
|||
text *arg = NULL;
|
||||
text *res;
|
||||
|
||||
CHECK_ARGS();
|
||||
data = PG_GETARG_BYTEA_P(0);
|
||||
key = PG_GETARG_BYTEA_P(1);
|
||||
if (PG_NARGS() > 2)
|
||||
|
@ -707,7 +693,6 @@ pgp_sym_decrypt_bytea(PG_FUNCTION_ARGS)
|
|||
text *arg = NULL;
|
||||
text *res;
|
||||
|
||||
CHECK_ARGS();
|
||||
data = PG_GETARG_BYTEA_P(0);
|
||||
key = PG_GETARG_BYTEA_P(1);
|
||||
if (PG_NARGS() > 2)
|
||||
|
@ -730,7 +715,6 @@ pgp_sym_decrypt_text(PG_FUNCTION_ARGS)
|
|||
text *arg = NULL;
|
||||
text *res;
|
||||
|
||||
CHECK_ARGS();
|
||||
data = PG_GETARG_BYTEA_P(0);
|
||||
key = PG_GETARG_BYTEA_P(1);
|
||||
if (PG_NARGS() > 2)
|
||||
|
@ -757,7 +741,6 @@ pgp_pub_encrypt_bytea(PG_FUNCTION_ARGS)
|
|||
text *arg = NULL;
|
||||
text *res;
|
||||
|
||||
CHECK_ARGS();
|
||||
data = PG_GETARG_BYTEA_P(0);
|
||||
key = PG_GETARG_BYTEA_P(1);
|
||||
if (PG_NARGS() > 2)
|
||||
|
@ -780,7 +763,6 @@ pgp_pub_encrypt_text(PG_FUNCTION_ARGS)
|
|||
text *arg = NULL;
|
||||
text *res;
|
||||
|
||||
CHECK_ARGS();
|
||||
data = PG_GETARG_BYTEA_P(0);
|
||||
key = PG_GETARG_BYTEA_P(1);
|
||||
if (PG_NARGS() > 2)
|
||||
|
@ -805,7 +787,6 @@ pgp_pub_decrypt_bytea(PG_FUNCTION_ARGS)
|
|||
*arg = NULL;
|
||||
text *res;
|
||||
|
||||
CHECK_ARGS();
|
||||
data = PG_GETARG_BYTEA_P(0);
|
||||
key = PG_GETARG_BYTEA_P(1);
|
||||
if (PG_NARGS() > 2)
|
||||
|
@ -833,7 +814,6 @@ pgp_pub_decrypt_text(PG_FUNCTION_ARGS)
|
|||
*arg = NULL;
|
||||
text *res;
|
||||
|
||||
CHECK_ARGS();
|
||||
data = PG_GETARG_BYTEA_P(0);
|
||||
key = PG_GETARG_BYTEA_P(1);
|
||||
if (PG_NARGS() > 2)
|
||||
|
@ -866,9 +846,6 @@ pg_armor(PG_FUNCTION_ARGS)
|
|||
res_len,
|
||||
guess_len;
|
||||
|
||||
if (PG_ARGISNULL(0))
|
||||
PG_RETURN_NULL();
|
||||
|
||||
data = PG_GETARG_BYTEA_P(0);
|
||||
data_len = VARSIZE(data) - VARHDRSZ;
|
||||
|
||||
|
@ -896,9 +873,6 @@ pg_dearmor(PG_FUNCTION_ARGS)
|
|||
res_len,
|
||||
guess_len;
|
||||
|
||||
if (PG_ARGISNULL(0))
|
||||
PG_RETURN_NULL();
|
||||
|
||||
data = PG_GETARG_TEXT_P(0);
|
||||
data_len = VARSIZE(data) - VARHDRSZ;
|
||||
|
||||
|
@ -933,9 +907,6 @@ pgp_key_id_w(PG_FUNCTION_ARGS)
|
|||
int res_len;
|
||||
MBuf *buf;
|
||||
|
||||
if (PG_ARGISNULL(0))
|
||||
PG_RETURN_NULL();
|
||||
|
||||
data = PG_GETARG_BYTEA_P(0);
|
||||
buf = create_mbuf_from_vardata(data);
|
||||
res = palloc(VARHDRSZ + 17);
|
||||
|
|
Loading…
Reference in New Issue