Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit fa332a0

Browse files
author
Neil Conway
committed
* construct "struct {} list [] = {}" confuses pgindent - split those.
It was a bad style to begin with, and now several loops can be clearer. * pgcrypto.c: Fix function comments * crypt-gensalt.c, crypt-blowfish.c: stop messing with errno * openssl.c: use px_free instead pfree * px.h: make redefining px_alloc/px_realloc/px_free easier Marko Kreen
1 parent 3cc8661 commit fa332a0

File tree

7 files changed

+74
-148
lines changed

7 files changed

+74
-148
lines changed

contrib/pgcrypto/crypt-blowfish.c

-11
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,6 @@
3535
#include "px.h"
3636
#include "px-crypt.h"
3737

38-
#define __set_errno(v)
39-
40-
#ifndef __set_errno
41-
#define __set_errno(val) errno = (val)
42-
#endif
43-
4438
#ifdef __i386__
4539
#define BF_ASM 0 /* 1 */
4640
#define BF_SCALE 1
@@ -600,10 +594,7 @@ _crypt_blowfish_rn(const char *key, const char *setting,
600594
int i;
601595

602596
if (size < 7 + 22 + 31 + 1)
603-
{
604-
__set_errno(ERANGE);
605597
return NULL;
606-
}
607598

608599
if (setting[0] != '$' ||
609600
setting[1] != '2' ||
@@ -613,15 +604,13 @@ _crypt_blowfish_rn(const char *key, const char *setting,
613604
setting[5] < '0' || setting[5] > '9' ||
614605
setting[6] != '$')
615606
{
616-
__set_errno(EINVAL);
617607
return NULL;
618608
}
619609

620610
count = (BF_word) 1 << ((setting[4] - '0') * 10 + (setting[5] - '0'));
621611
if (count < 16 || BF_decode(data.binary.salt, &setting[7], 16))
622612
{
623613
memset(data.binary.salt, 0, sizeof(data.binary.salt));
624-
__set_errno(EINVAL);
625614
return NULL;
626615
}
627616
BF_swap(data.binary.salt, 4);

contrib/pgcrypto/crypt-gensalt.c

-9
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@
1515
#include "px.h"
1616
#include "px-crypt.h"
1717

18-
#include <errno.h>
19-
#ifndef __set_errno
20-
#define __set_errno(val) (errno = (val))
21-
#endif
22-
2318
typedef unsigned int BF_word;
2419

2520
unsigned char _crypt_itoa64[64 + 1] =
@@ -33,7 +28,6 @@ _crypt_gensalt_traditional_rn(unsigned long count,
3328
{
3429
if (output_size > 0)
3530
output[0] = '\0';
36-
__set_errno((output_size < 2 + 1) ? ERANGE : EINVAL);
3731
return NULL;
3832
}
3933

@@ -57,7 +51,6 @@ _crypt_gensalt_extended_rn(unsigned long count,
5751
{
5852
if (output_size > 0)
5953
output[0] = '\0';
60-
__set_errno((output_size < 1 + 4 + 4 + 1) ? ERANGE : EINVAL);
6154
return NULL;
6255
}
6356

@@ -91,7 +84,6 @@ _crypt_gensalt_md5_rn(unsigned long count,
9184
{
9285
if (output_size > 0)
9386
output[0] = '\0';
94-
__set_errno((output_size < 3 + 4 + 1) ? ERANGE : EINVAL);
9587
return NULL;
9688
}
9789

@@ -173,7 +165,6 @@ _crypt_gensalt_blowfish_rn(unsigned long count,
173165
{
174166
if (output_size > 0)
175167
output[0] = '\0';
176-
__set_errno((output_size < 7 + 22 + 1) ? ERANGE : EINVAL);
177168
return NULL;
178169
}
179170

contrib/pgcrypto/internal.c

+19-33
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2727
* SUCH DAMAGE.
2828
*
29-
* $PostgreSQL: pgsql/contrib/pgcrypto/internal.c,v 1.14 2004/10/25 02:15:02 tgl Exp $
29+
* $PostgreSQL: pgsql/contrib/pgcrypto/internal.c,v 1.15 2005/03/21 05:18:45 neilc Exp $
3030
*/
3131

3232

@@ -57,22 +57,17 @@
5757
static void init_md5(PX_MD * h);
5858
static void init_sha1(PX_MD * h);
5959

60-
static struct int_digest
60+
struct int_digest
6161
{
6262
char *name;
6363
void (*init) (PX_MD * h);
64-
} int_digest_list[] =
64+
};
6565

66-
{
67-
{
68-
"md5", init_md5
69-
},
70-
{
71-
"sha1", init_sha1
72-
},
73-
{
74-
NULL, NULL
75-
}
66+
static const struct int_digest
67+
int_digest_list[] = {
68+
{ "md5", init_md5 },
69+
{ "sha1", init_sha1 },
70+
{ NULL, NULL }
7671
};
7772

7873
/* MD5 */
@@ -516,31 +511,22 @@ bf_cbc_load(void)
516511
return bf_load(MODE_CBC);
517512
}
518513

519-
static struct
514+
struct int_cipher
520515
{
521516
char *name;
522517
PX_Cipher *(*load) (void);
523-
} int_ciphers[] =
518+
};
524519

525-
{
526-
{
527-
"bf-cbc", bf_cbc_load
528-
},
529-
{
530-
"bf-ecb", bf_ecb_load
531-
},
532-
{
533-
"aes-128-cbc", rj_128_cbc
534-
},
535-
{
536-
"aes-128-ecb", rj_128_ecb
537-
},
538-
{
539-
NULL, NULL
540-
}
520+
static const struct int_cipher
521+
int_ciphers[] = {
522+
{ "bf-cbc", bf_cbc_load },
523+
{ "bf-ecb", bf_ecb_load },
524+
{ "aes-128-cbc", rj_128_cbc },
525+
{ "aes-128-ecb", rj_128_ecb },
526+
{ NULL, NULL }
541527
};
542528

543-
static PX_Alias int_aliases[] = {
529+
static const PX_Alias int_aliases[] = {
544530
{"bf", "bf-cbc"},
545531
{"blowfish", "bf-cbc"},
546532
{"aes", "aes-128-cbc"},
@@ -557,7 +543,7 @@ static PX_Alias int_aliases[] = {
557543
int
558544
px_find_digest(const char *name, PX_MD ** res)
559545
{
560-
struct int_digest *p;
546+
const struct int_digest *p;
561547
PX_MD *h;
562548

563549
for (p = int_digest_list; p->name; p++)

contrib/pgcrypto/openssl.c

+23-48
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2727
* SUCH DAMAGE.
2828
*
29-
* $PostgreSQL: pgsql/contrib/pgcrypto/openssl.c,v 1.14 2005/03/12 06:53:54 neilc Exp $
29+
* $PostgreSQL: pgsql/contrib/pgcrypto/openssl.c,v 1.15 2005/03/21 05:18:45 neilc Exp $
3030
*/
3131

3232
#include <postgres.h>
@@ -208,8 +208,8 @@ gen_ossl_free(PX_Cipher * c)
208208
ossldata *od = (ossldata *) c->ptr;
209209

210210
memset(od, 0, sizeof(*od));
211-
pfree(od);
212-
pfree(c);
211+
px_free(od);
212+
px_free(c);
213213
}
214214

215215
/* Blowfish */
@@ -473,76 +473,51 @@ static const struct ossl_cipher ossl_cast_cbc = {
473473
/*
474474
* Special handlers
475475
*/
476-
static const struct
476+
struct ossl_cipher_lookup
477477
{
478478
const char *name;
479479
const struct ossl_cipher *ciph;
480-
} ossl_cipher_types[] =
480+
};
481481

482-
{
483-
{
484-
"bf-cbc", &ossl_bf_cbc
485-
},
486-
{
487-
"bf-ecb", &ossl_bf_ecb
488-
},
489-
{
490-
"bf-cfb", &ossl_bf_cfb
491-
},
492-
{
493-
"des-ecb", &ossl_des_ecb
494-
},
495-
{
496-
"des-cbc", &ossl_des_cbc
497-
},
498-
{
499-
"cast5-ecb", &ossl_cast_ecb
500-
},
501-
{
502-
"cast5-cbc", &ossl_cast_cbc
503-
},
504-
{
505-
NULL
506-
}
482+
static const struct ossl_cipher_lookup ossl_cipher_types[] = {
483+
{"bf-cbc", &ossl_bf_cbc},
484+
{"bf-ecb", &ossl_bf_ecb},
485+
{"bf-cfb", &ossl_bf_cfb},
486+
{"des-ecb", &ossl_des_ecb},
487+
{"des-cbc", &ossl_des_cbc},
488+
{"cast5-ecb", &ossl_cast_ecb},
489+
{"cast5-cbc", &ossl_cast_cbc},
490+
{NULL}
507491
};
508492

509493
/* PUBLIC functions */
510494

511495
int
512496
px_find_cipher(const char *name, PX_Cipher ** res)
513497
{
514-
unsigned i;
515-
PX_Cipher *c = NULL,
516-
*csrc;
498+
const struct ossl_cipher_lookup *i;
499+
PX_Cipher *c = NULL;
517500
ossldata *od;
518-
const struct ossl_cipher *ossl_ciph = NULL;
519501

520502
name = px_resolve_alias(ossl_aliases, name);
521-
for (i = 0; ossl_cipher_types[i].name; i++)
522-
{
523-
if (!strcmp(ossl_cipher_types[i].name, name))
524-
{
525-
ossl_ciph = ossl_cipher_types[i].ciph;
503+
for (i = ossl_cipher_types; i->name; i++)
504+
if (!strcmp(i->name, name))
526505
break;
527-
}
528-
}
529-
if (ossl_ciph == NULL)
506+
if (i->name == NULL)
530507
return -1;
531508

532509
od = px_alloc(sizeof(*od));
533510
memset(od, 0, sizeof(*od));
534-
od->ciph = ossl_ciph;
535-
536-
csrc = NULL;
511+
od->ciph = i->ciph;
537512

538513
c = px_alloc(sizeof(*c));
539514
c->block_size = gen_ossl_block_size;
540515
c->key_size = gen_ossl_key_size;
541516
c->iv_size = gen_ossl_iv_size;
542517
c->free = gen_ossl_free;
543-
c->init = ossl_ciph->init;
544-
c->encrypt = ossl_ciph->encrypt;
545-
c->decrypt = ossl_ciph->decrypt;
518+
c->init = od->ciph->init;
519+
c->encrypt = od->ciph->encrypt;
520+
c->decrypt = od->ciph->decrypt;
546521
c->ptr = od;
547522

548523
*res = c;

contrib/pgcrypto/pgcrypto.c

+8-9
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2727
* SUCH DAMAGE.
2828
*
29-
* $PostgreSQL: pgsql/contrib/pgcrypto/pgcrypto.c,v 1.16 2004/05/07 00:24:57 tgl Exp $
29+
* $PostgreSQL: pgsql/contrib/pgcrypto/pgcrypto.c,v 1.17 2005/03/21 05:18:45 neilc Exp $
3030
*/
3131

3232
#include "postgres.h"
@@ -46,7 +46,7 @@ typedef int (*PFN) (const char *name, void **res);
4646
static void *
4747
find_provider(text *name, PFN pf, char *desc, int silent);
4848

49-
/* SQL function: hash(text, text) returns text */
49+
/* SQL function: hash(bytea, text) returns bytea */
5050
PG_FUNCTION_INFO_V1(pg_digest);
5151

5252
Datum
@@ -111,7 +111,7 @@ pg_digest_exists(PG_FUNCTION_ARGS)
111111
PG_RETURN_BOOL(true);
112112
}
113113

114-
/* SQL function: hmac(data:text, key:text, type:text) */
114+
/* SQL function: hmac(data:bytea, key:bytea, type:text) returns bytea */
115115
PG_FUNCTION_INFO_V1(pg_hmac);
116116

117117
Datum
@@ -316,7 +316,7 @@ pg_crypt(PG_FUNCTION_ARGS)
316316
PG_RETURN_TEXT_P(res);
317317
}
318318

319-
/* SQL function: pg_encrypt(text, text, text) returns text */
319+
/* SQL function: pg_encrypt(bytea, bytea, text) returns bytea */
320320
PG_FUNCTION_INFO_V1(pg_encrypt);
321321

322322
Datum
@@ -367,7 +367,7 @@ pg_encrypt(PG_FUNCTION_ARGS)
367367
PG_RETURN_BYTEA_P(res);
368368
}
369369

370-
/* SQL function: pg_decrypt(text, text, text) returns text */
370+
/* SQL function: pg_decrypt(bytea, bytea, text) returns bytea */
371371
PG_FUNCTION_INFO_V1(pg_decrypt);
372372

373373
Datum
@@ -417,7 +417,7 @@ pg_decrypt(PG_FUNCTION_ARGS)
417417
PG_RETURN_BYTEA_P(res);
418418
}
419419

420-
/* SQL function: pg_encrypt(text, text, text) returns text */
420+
/* SQL function: pg_encrypt_iv(bytea, bytea, bytea, text) returns bytea */
421421
PG_FUNCTION_INFO_V1(pg_encrypt_iv);
422422

423423
Datum
@@ -473,7 +473,7 @@ pg_encrypt_iv(PG_FUNCTION_ARGS)
473473
PG_RETURN_BYTEA_P(res);
474474
}
475475

476-
/* SQL function: pg_decrypt_iv(text, text, text) returns text */
476+
/* SQL function: pg_decrypt_iv(bytea, bytea, bytea, text) returns bytea */
477477
PG_FUNCTION_INFO_V1(pg_decrypt_iv);
478478

479479
Datum
@@ -529,7 +529,7 @@ pg_decrypt_iv(PG_FUNCTION_ARGS)
529529
PG_RETURN_BYTEA_P(res);
530530
}
531531

532-
/* SQL function: pg_decrypt(text, text, text) returns text */
532+
/* SQL function: pg_cipher_exists(text) returns bool */
533533
PG_FUNCTION_INFO_V1(pg_cipher_exists);
534534

535535
Datum
@@ -550,7 +550,6 @@ pg_cipher_exists(PG_FUNCTION_ARGS)
550550
PG_RETURN_BOOL((c != NULL) ? true : false);
551551
}
552552

553-
554553
static void *
555554
find_provider(text *name,
556555
PFN provider_lookup,

0 commit comments

Comments
 (0)