Expose the data in the extension, and tests.
diff --git a/OpenSSL/crypto/x509ext.c b/OpenSSL/crypto/x509ext.c
index a874204..75c3311 100644
--- a/OpenSSL/crypto/x509ext.c
+++ b/OpenSSL/crypto/x509ext.c
@@ -51,6 +51,26 @@
}
+static char crypto_X509Extension_get_data_doc[] = "\n\
+Returns the data of the X509Extension\n\
+\n\
+@return: A C{str} giving the X509Extension's data.\n\
+";
+
+static PyObject *
+crypto_X509Extension_get_data(crypto_X509ExtensionObj *self, PyObject *args) {
+ ASN1_OCTET_STRING *data;
+ PyObject *result;
+
+ if (!PyArg_ParseTuple(args, ":get_data")) {
+ return NULL;
+ }
+
+ data = X509_EXTENSION_get_data(self->x509_extension);
+ result = PyBytes_FromStringAndSize((const char*)data->data, data->length);
+ return result;
+}
+
/*
* ADD_METHOD(name) expands to a correct PyMethodDef declaration
* { 'name', (PyCFunction)crypto_X509Extension_name, METH_VARARGS }
@@ -62,6 +82,7 @@
{
ADD_METHOD(get_critical),
ADD_METHOD(get_short_name),
+ ADD_METHOD(get_data),
{ NULL, NULL }
};
#undef ADD_METHOD
diff --git a/OpenSSL/test/test_crypto.py b/OpenSSL/test/test_crypto.py
index 000778f..753a262 100644
--- a/OpenSSL/test/test_crypto.py
+++ b/OpenSSL/test/test_crypto.py
@@ -353,6 +353,26 @@
self.assertEqual(ext.get_short_name(), b('nsComment'))
+ def test_get_data(self):
+ """
+ L{X509Extension.get_data} returns a string giving the data of the
+ extension.
+ """
+ ext = X509Extension(b('basicConstraints'), True, b('CA:true'))
+ # Expect to get back the DER encoded form of CA:true.
+ self.assertEqual(ext.get_data(), b('0\x03\x01\x01\xff'))
+
+
+ def test_get_data_wrong_args(self):
+ """
+ L{X509Extension.get_data} raises L{TypeError} if passed any arguments.
+ """
+ ext = X509Extension(b('basicConstraints'), True, b('CA:true'))
+ self.assertRaises(TypeError, ext.get_data, None)
+ self.assertRaises(TypeError, ext.get_data, "foo")
+ self.assertRaises(TypeError, ext.get_data, 7)
+
+
def test_unused_subject(self):
"""
The C{subject} parameter to L{X509Extension} may be provided for an