Add X509Name.der
diff --git a/src/crypto/x509name.c b/src/crypto/x509name.c
index 93a440e..5827ccb 100644
--- a/src/crypto/x509name.c
+++ b/src/crypto/x509name.c
@@ -249,6 +249,30 @@
     return PyInt_FromLong(hash);
 }
 
+static char crypto_X509Name_der_doc[] = "\n\
+Return the DER encodeing of this name\n\
+\n\
+Arguments: self - The X509 object\n\
+           args - The Python argument tuple, should be empty\n\
+Returns:   None\n\
+";
+
+/*
+ * Arguments: self - The X509Name object
+ * Returns:   The DER form of an X509Name.
+ */
+static PyObject *
+crypto_X509Name_der(crypto_X509NameObj *self, PyObject *args)
+{
+    if (!PyArg_ParseTuple(args, ":der")) {
+	return NULL;
+    }
+
+    i2d_X509_NAME(self->x509_name, 0);
+    return PyString_FromStringAndSize(self->x509_name->bytes->data,
+				      self->x509_name->bytes->length);
+}
+
 
 /*
  * Call the visitproc on all contained objects.
@@ -312,6 +336,7 @@
 static PyMethodDef crypto_X509Name_methods[] =
 {
     ADD_METHOD(hash),
+    ADD_METHOD(der),
     { NULL, NULL }
 };
 #undef ADD_METHOD
diff --git a/test/test_crypto.py b/test/test_crypto.py
index 3ee0392..99a62c3 100644
--- a/test/test_crypto.py
+++ b/test/test_crypto.py
@@ -279,6 +279,17 @@
         self.assertNotEqual(a.hash(), b.hash())
 
 
+    def test_der(self):
+        """
+        L{X509Name.der} returns the DER encoded form of the name.
+        """
+        a = self._x509name(CN="foo", C="US")
+        self.assertEqual(
+            a.der(),
+            '0\x1b1\x0b0\t\x06\x03U\x04\x06\x13\x02US'
+            '1\x0c0\n\x06\x03U\x04\x03\x13\x03foo')
+
+
 
 class _PKeyInteractionTestsMixin:
     """