Stretch compat back to Python 2.4
diff --git a/OpenSSL/crypto/x509.c b/OpenSSL/crypto/x509.c
index efec663..0b54c8d 100644
--- a/OpenSSL/crypto/x509.c
+++ b/OpenSSL/crypto/x509.c
@@ -106,7 +106,7 @@
goto err;
}
- if ((hex = PyNumber_ToBase(serial, 16)) == NULL) {
+ if ((hex = PyOpenSSL_LongToHex(serial)) == NULL) {
goto err;
}
diff --git a/OpenSSL/py3k.h b/OpenSSL/py3k.h
index 5811a6d..2191526 100644
--- a/OpenSSL/py3k.h
+++ b/OpenSSL/py3k.h
@@ -33,7 +33,9 @@
#define PyBytes_Check PyString_Check
#define PyBytes_CheckExact PyString_CheckExact
#define PyBytes_AsString PyString_AsString
+#define PyBytes_FromString PyString_FromString
#define PyBytes_FromStringAndSize PyString_FromStringAndSize
+#define _PyBytes_Resize _PyString_Resize
#define PyText_CheckExact PyString_CheckExact
#define PyText_FromString PyString_FromString
diff --git a/OpenSSL/util.c b/OpenSSL/util.c
index ae6ee5e..76a4a25 100644
--- a/OpenSSL/util.c
+++ b/OpenSSL/util.c
@@ -59,3 +59,35 @@
PyObject *list = error_queue_to_list();
Py_DECREF(list);
}
+
+PyObject* PyOpenSSL_LongToHex(PyObject *o) {
+ PyObject *hex = NULL;
+ PyObject *format = NULL;
+ PyObject *format_args = NULL;
+
+ if ((format_args = Py_BuildValue("(O)", o)) == NULL) {
+ goto err;
+ }
+
+ if ((format = PyString_FromString("%x")) == NULL) {
+ goto err;
+ }
+
+ if ((hex = PyString_Format(format, format_args)) == NULL) {
+ goto err;
+ }
+
+ return hex;
+
+ err:
+ if (format_args) {
+ Py_DECREF(format_args);
+ }
+ if (format) {
+ Py_DECREF(format);
+ }
+ if (hex) {
+ Py_DECREF(hex);
+ }
+ return NULL;
+}
diff --git a/OpenSSL/util.h b/OpenSSL/util.h
index 73accbf..f9e3a77 100644
--- a/OpenSSL/util.h
+++ b/OpenSSL/util.h
@@ -131,4 +131,10 @@
#define PY_SSIZE_T_MIN INT_MIN
#endif
+#if !defined(PyNumber_ToBase)
+extern PyObject* PyOpenSSL_LongToHex(PyObject *o);
+#else
+#define PyOpenSSL_LongToHex(o) PyNumber_ToBase(o, 16)
+#endif
+
#endif