summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Paul Calderone <exarkun@divmod.com>2009-05-13 15:45:07 -0400
committerJean-Paul Calderone <exarkun@divmod.com>2009-05-13 15:45:07 -0400
commitd338e4e2b7fc4605a98b87da97471c3966cd5293 (patch)
tree42bf509de1ff92188e91f9b23e200797358aea96
parent49f93ab110d88df63b52f98f682150683dd21015 (diff)
downloadpyopenssl-d338e4e2b7fc4605a98b87da97471c3966cd5293.tar.gz
Switch from returning False to raising an Error if the key doesn't check out - this provides more information
-rw-r--r--OpenSSL/crypto/pkey.c12
-rw-r--r--OpenSSL/test/test_crypto.py2
2 files changed, 9 insertions, 5 deletions
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 @@ Check the consistency of an RSA private key.\n\
\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 @@ crypto_PKey_check(crypto_PKeyObj *self, PyObject *args)
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 @@ class PKeyTests(TestCase):
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):