Apply pyOpenSSL_rsa_check.diff
diff --git a/OpenSSL/crypto/pkey.c b/OpenSSL/crypto/pkey.c
index 0a13aa3..cfedfda 100644
--- a/OpenSSL/crypto/pkey.c
+++ b/OpenSSL/crypto/pkey.c
@@ -107,6 +107,39 @@
return PyLong_FromLong(self->pkey->type);
}
+static char crypto_PKey_check_doc[] = "\n\
+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\
+";
+
+static PyObject *
+crypto_PKey_check(crypto_PKeyObj *self, PyObject *args)
+{
+ int r;
+ EVP_PKEY *pkey;
+
+ if (!PyArg_ParseTuple(args, ":check"))
+ return NULL;
+ pkey = self->pkey;
+ if(pkey == NULL)
+ return NULL;
+
+ if(pkey->type == EVP_PKEY_RSA) {
+ RSA *rsa;
+ rsa = EVP_PKEY_get1_RSA(pkey);
+ r = RSA_check_key(rsa);
+ if (r == 1)
+ return PyInt_FromLong(1L);
+ else
+ return PyInt_FromLong(0L);
+ } else {
+ PyErr_SetString( PyExc_TypeError, "key type unsupported");
+ return NULL;
+ }
+}
/*
* ADD_METHOD(name) expands to a correct PyMethodDef declaration
@@ -120,6 +153,7 @@
ADD_METHOD(generate_key),
ADD_METHOD(bits),
ADD_METHOD(type),
+ ADD_METHOD(check),
{ NULL, NULL }
};
#undef ADD_METHOD