diff options
| author | Neil Conway | 2005-03-21 05:19:55 +0000 |
|---|---|---|
| committer | Neil Conway | 2005-03-21 05:19:55 +0000 |
| commit | b160d6b9dcab2954cf4b500c73dd0998aa371f49 (patch) | |
| tree | 12486a14bf0ed96d5a4f8982cc14766ade535e05 /contrib/pgcrypto/px.c | |
| parent | fa332a06ecffaa027a0b09cdd1907a03d4318911 (diff) | |
pgcrypto update:
* Use error codes instead of -1
* px_strerror for new error codes
* calling convention change for px_gen_salt - return error code
* use px_strerror in pgcrypto.c
Marko Kreen
Diffstat (limited to 'contrib/pgcrypto/px.c')
| -rw-r--r-- | contrib/pgcrypto/px.c | 47 |
1 files changed, 40 insertions, 7 deletions
diff --git a/contrib/pgcrypto/px.c b/contrib/pgcrypto/px.c index 49c4bdc731..259d054bbd 100644 --- a/contrib/pgcrypto/px.c +++ b/contrib/pgcrypto/px.c @@ -26,13 +26,48 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $PostgreSQL: pgsql/contrib/pgcrypto/px.c,v 1.9 2004/05/07 00:24:57 tgl Exp $ + * $PostgreSQL: pgsql/contrib/pgcrypto/px.c,v 1.10 2005/03/21 05:19:55 neilc Exp $ */ #include <postgres.h> #include "px.h" +struct error_desc { + int err; + const char *desc; +}; + +static const struct error_desc px_err_list[] = { + {PXE_OK, "Everything ok"}, + {PXE_ERR_GENERIC, "Some PX error (not specified)"}, + {PXE_NO_HASH, "No such hash algorithm"}, + {PXE_NO_CIPHER, "No such cipher algorithm"}, + {PXE_NOTBLOCKSIZE, "Data not a multiple of block size"}, + {PXE_BAD_OPTION, "Unknown option"}, + {PXE_BAD_FORMAT, "Badly formatted type"}, + {PXE_KEY_TOO_BIG, "Key was too big"}, + {PXE_CIPHER_INIT, "Cipher cannot be initalized ?"}, + {PXE_HASH_UNUSABLE_FOR_HMAC, "This hash algorithm is unusable for HMAC"}, + {PXE_DEV_READ_ERROR, "Error reading from random device"}, + {PXE_OSSL_RAND_ERROR, "OpenSSL PRNG error"}, + {PXE_BUG, "pgcrypto bug"}, + {PXE_ARGUMENT_ERROR, "Illegal argument to function"}, + {PXE_UNKNOWN_SALT_ALGO, "Unknown salt algorithm"}, + {PXE_BAD_SALT_ROUNDS, "Incorrect number of rounds"}, + {PXE_MCRYPT_INTERNAL, "mcrypt internal error"}, + {0, NULL}, +}; + +const char *px_strerror(int err) +{ + const struct error_desc *e; + for (e = px_err_list; e->desc; e++) + if (e->err == err) + return e->desc; + return "Bad error code"; +} + const char * px_resolve_alias(const PX_Alias * list, const char *name) @@ -215,10 +250,8 @@ combo_decrypt(PX_Combo * cx, const uint8 *data, unsigned dlen, return 0; - /* error reporting should be done in pgcrypto.c */ block_error: - elog(WARNING, "Data not a multiple of block size"); - return -1; + return PXE_NOTBLOCKSIZE; } static void @@ -262,10 +295,10 @@ parse_cipher_name(char *full, char **cipher, char **pad) if (!strcmp(p, "pad")) *pad = p2; else - return -1; + return PXE_BAD_OPTION; } else - return -1; + return PXE_BAD_FORMAT; p = q; } @@ -332,5 +365,5 @@ err1: px_cipher_free(cx->cipher); px_free(cx); px_free(buf); - return -1; + return PXE_NO_CIPHER; } |
