Switch from returning False to raising an Error if the key doesn't check out - this provides more information
diff --git a/OpenSSL/crypto/pkey.c b/OpenSSL/crypto/pkey.c
index 7d5c6a8..f037fd4 100644
--- a/OpenSSL/crypto/pkey.c
+++ b/OpenSSL/crypto/pkey.c
@@ -112,7 +112,10 @@
\n\
Arguments: self - The PKey object\n\
args - The Python argument tuple, should be empty\n\
-Returns: True if key is consistent. False if not.\n\
+Returns: True if key is consistent.\n\
+Raises: Error if the key is inconsistent.\n\
+ TypeError if the key is of a type which cannot be checked. Only RSA\n\
+ keys can currently be checked.\n\
";
static PyObject *
@@ -127,10 +130,11 @@
RSA *rsa;
rsa = EVP_PKEY_get1_RSA(self->pkey);
r = RSA_check_key(rsa);
- if (r == 1)
+ if (r == 1) {
return PyBool_FromLong(1L);
- else
- return PyBool_FromLong(0L);
+ } else {
+ FAIL();
+ }
} else {
PyErr_SetString( PyExc_TypeError, "key type unsupported");
return NULL;
diff --git a/OpenSSL/test/test_crypto.py b/OpenSSL/test/test_crypto.py
index a22ad12..cda0137 100644
--- a/OpenSSL/test/test_crypto.py
+++ b/OpenSSL/test/test_crypto.py
@@ -618,7 +618,7 @@
L{PKeyType.check} returns C{False} if the key is not consistent.
"""
key = load_privatekey(FILETYPE_PEM, inconsistentPrivateKeyPEM)
- self.assertFalse(key.check())
+ self.assertRaises(Error, key.check)
class X509NameTests(TestCase):