diff options
-rw-r--r-- | OpenSSL/crypto/pkey.c | 2 | ||||
-rw-r--r-- | OpenSSL/test/test_crypto.py | 14 |
2 files changed, 15 insertions, 1 deletions
diff --git a/OpenSSL/crypto/pkey.c b/OpenSSL/crypto/pkey.c index 711306d..b9472ec 100644 --- a/OpenSSL/crypto/pkey.c +++ b/OpenSSL/crypto/pkey.c @@ -127,7 +127,7 @@ crypto_PKey_check(crypto_PKeyObj *self, PyObject *args) { if (self->only_public) { PyErr_SetString(PyExc_TypeError, "public key only"); return NULL; - } + } if (self->pkey->type == EVP_PKEY_RSA) { RSA *rsa; diff --git a/OpenSSL/test/test_crypto.py b/OpenSSL/test/test_crypto.py index e0d7b27..62b9429 100644 --- a/OpenSSL/test/test_crypto.py +++ b/OpenSSL/test/test_crypto.py @@ -630,6 +630,20 @@ class PKeyTests(TestCase): self.assertRaises(TypeError, PKey().check, 1) + def test_check_public_key(self): + """ + :py:meth:`PKeyType.check` raises :py:exc:`TypeError` if only the public + part of the key is available. + """ + # A trick to get a public-only key + key = PKey() + key.generate_key(TYPE_RSA, 512) + cert = X509() + cert.set_pubkey(key) + pub = cert.get_pubkey() + self.assertRaises(TypeError, pub.check) + + class X509NameTests(TestCase): """ |