Apply get_signature_algorithm parts of okuda's patch
diff --git a/OpenSSL/crypto/x509.c b/OpenSSL/crypto/x509.c
index a12220b..d62b504 100644
--- a/OpenSSL/crypto/x509.c
+++ b/OpenSSL/crypto/x509.c
@@ -519,6 +519,29 @@
return Py_None;
}
+static char crypto_X509_get_signature_algorithm_doc[] = "\n\
+Retrieve the signature algorithm used in the certificate\n\
+\n\
+Arguments: self - The X509 object\n\
+ args - The Python argument tuple, should be empty\n\
+Returns: None\n\
+";
+
+static PyObject *
+crypto_X509_get_signature_algorithm(crypto_X509Obj *self, PyObject *args)
+{
+ ASN1_OBJECT *alg;
+ int nid;
+
+ if (!PyArg_ParseTuple(args, ":get_signature_algorithm"))
+ return NULL;
+
+ alg = self->x509->cert_info->signature->algorithm;
+ nid = OBJ_obj2nid(alg);
+ return PyString_FromString(OBJ_nid2ln(nid));
+}
+
+
static char crypto_X509_sign_doc[] = "\n\
Sign the certificate using the supplied key and digest\n\
\n\
@@ -757,6 +780,7 @@
ADD_METHOD(set_notAfter),
ADD_METHOD(gmtime_adj_notBefore),
ADD_METHOD(gmtime_adj_notAfter),
+ ADD_METHOD(get_signature_algorithm),
ADD_METHOD(sign),
ADD_METHOD(has_expired),
ADD_METHOD(subject_name_hash),
diff --git a/OpenSSL/test/test_crypto.py b/OpenSSL/test/test_crypto.py
index 496dc59..fcf834f 100644
--- a/OpenSSL/test/test_crypto.py
+++ b/OpenSSL/test/test_crypto.py
@@ -652,6 +652,15 @@
name = self._x509name()
self.assertRaises(AttributeError, setattr, name, "no such thing", None)
+ def test_get_signature_algorithm(self):
+ """
+ L{X509Type.get_signature_algorithm} returns a string which means
+ the algorithm used to sign the certificate.
+ """
+ cert = load_certificate(FILETYPE_PEM, self.pemData)
+ self.assertEqual(cert.get_signature_algorithm(), "sha1WithRSAEncryption")
+
+
def test_attributes(self):
"""
diff --git a/doc/pyOpenSSL.tex b/doc/pyOpenSSL.tex
index 239133f..575eb8e 100644
--- a/doc/pyOpenSSL.tex
+++ b/doc/pyOpenSSL.tex
@@ -321,6 +321,10 @@
Return the certificate serial number.
\end{methoddesc}
+\begin{methoddesc}[X509]{get_signature_algorithm}{}
+Return the signature algorithem used in the certificate.
+\end{methoddesc}
+
\begin{methoddesc}[X509]{get_subject}{}
Return an X509Name object representing the subject of the certificate.
\end{methoddesc}