Add error code for encryption failure in pgcrypto
authorMichael Paquier <[email protected]>
Sun, 1 Nov 2020 10:22:59 +0000 (19:22 +0900)
committerMichael Paquier <[email protected]>
Sun, 1 Nov 2020 10:22:59 +0000 (19:22 +0900)
PXE_DECRYPT_FAILED exists already for decryption errors, and an
equivalent for encryption did not exist.  There is one code path that
deals with such failures for OpenSSL but it used PXE_ERR_GENERIC, which
was inconsistent.  This switches this code path to use the new error
PXE_ENCRYPT_FAILED instead of PXE_ERR_GENERIC, making the code used for
encryption more consistent with the decryption.

Author: Daniel Gustafsson
Discussion: https://postgr.es/m/03049139-CB7A-436E-B71B-42696D3E2EF7@yesql.se

contrib/pgcrypto/openssl.c
contrib/pgcrypto/px.c
contrib/pgcrypto/px.h

index ed96e4ce5359b80b3c6f20d9c5d61409b81892fd..5ebe213406938818aed99f6a0162415d892460d7 100644 (file)
@@ -400,7 +400,7 @@ gen_ossl_encrypt(PX_Cipher *c, const uint8 *data, unsigned dlen,
    }
 
    if (!EVP_EncryptUpdate(od->evp_ctx, res, &outlen, data, dlen))
-       return PXE_ERR_GENERIC;
+       return PXE_ENCRYPT_FAILED;
 
    return 0;
 }
index 6a4681dae989e5057fa04a83cb40ac07a0a37d59..a243f575d3be9490d3b0f073be828a616e914449 100644 (file)
@@ -58,6 +58,7 @@ static const struct error_desc px_err_list[] = {
    {PXE_MCRYPT_INTERNAL, "mcrypt internal error"},
    {PXE_NO_RANDOM, "Failed to generate strong random bits"},
    {PXE_DECRYPT_FAILED, "Decryption failed"},
+   {PXE_ENCRYPT_FAILED, "Encryption failed"},
    {PXE_PGP_CORRUPT_DATA, "Wrong key or corrupt data"},
    {PXE_PGP_CORRUPT_ARMOR, "Corrupt ascii-armor"},
    {PXE_PGP_UNSUPPORTED_COMPR, "Unsupported compression algorithm"},
index 5487923edb3e9cafb9623dfdc8551adfceb8deff..17d6f2249870f7deb713f925643a4fe9ce0e67d4 100644 (file)
@@ -61,6 +61,7 @@
 #define PXE_MCRYPT_INTERNAL            -16
 #define PXE_NO_RANDOM              -17
 #define PXE_DECRYPT_FAILED         -18
+#define PXE_ENCRYPT_FAILED         -19
 
 #define PXE_PGP_CORRUPT_DATA       -100
 #define PXE_PGP_CORRUPT_ARMOR      -101