Convert more things
diff --git a/OpenSSL/crypto/x509.c b/OpenSSL/crypto/x509.c
index 2f12437..915a3b7 100644
--- a/OpenSSL/crypto/x509.c
+++ b/OpenSSL/crypto/x509.c
@@ -776,8 +776,7 @@
}
PyTypeObject crypto_X509_Type = {
- PyObject_HEAD_INIT(NULL)
- 0,
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"X509",
sizeof(crypto_X509Obj),
0,
diff --git a/OpenSSL/crypto/x509name.c b/OpenSSL/crypto/x509name.c
index 39fdcf8..c288180 100644
--- a/OpenSSL/crypto/x509name.c
+++ b/OpenSSL/crypto/x509name.c
@@ -162,7 +162,7 @@
* See lp#314814.
*/
flush_error_queue();
- return Py_FindMethod(crypto_X509Name_methods, (PyObject *)self, name);
+ return crypto_X509Name_Type.tp_getattr((PyObject*)self, name);
}
len = get_name_by_nid(self->x509_name, nid, &utf8string);
@@ -216,16 +216,50 @@
* m - The second X509Name
* Returns: <0 if n < m, 0 if n == m and >0 if n > m
*/
-static int
-crypto_X509Name_compare(crypto_X509NameObj *n, crypto_X509NameObj *m)
-{
- int result = X509_NAME_cmp(n->x509_name, m->x509_name);
- if (result < 0) {
- return -1;
- } else if (result > 0) {
- return 1;
+static PyObject *
+crypto_X509Name_richcompare(PyObject *n, PyObject *m, int op) {
+ int result;
+
+ if (!crypto_X509Name_Check(n) || !crypto_X509Name_Check(m)) {
+ Py_INCREF(Py_NotImplemented);
+ return Py_NotImplemented;
+ }
+
+ result = X509_NAME_cmp(
+ ((crypto_X509NameObj*)n)->x509_name,
+ ((crypto_X509NameObj*)m)->x509_name);
+
+ switch (op) {
+ case Py_EQ:
+ result = (result == 0);
+
+ case Py_NE:
+ result = (result != 0);
+
+ case Py_LT:
+ result = (result < 0);
+
+ case Py_LE:
+ result = (result <= 0);
+
+ case Py_GT:
+ result = (result > 0);
+
+ case Py_GE:
+ result = (result >= 0);
+
+ default:
+ /* Should be impossible */
+ Py_INCREF(Py_NotImplemented);
+ return Py_NotImplemented;
+ }
+
+ if (result) {
+ Py_INCREF(Py_True);
+ return Py_True;
} else {
- return 0;
+ Py_INCREF(Py_False);
+ return Py_False;
}
}
@@ -250,7 +284,7 @@
{
/* This is safe because tmpbuf is max 512 characters */
sprintf(realbuf, "<X509Name object '%s'>", tmpbuf);
- return PyString_FromString(realbuf);
+ return PyText_FromString(realbuf);
}
}
@@ -275,7 +309,7 @@
return NULL;
}
hash = X509_NAME_hash(self->x509_name);
- return PyInt_FromLong(hash);
+ return PyLong_FromLong(hash);
}
static char crypto_X509Name_der_doc[] = "\n\
@@ -296,8 +330,8 @@
}
i2d_X509_NAME(self->x509_name, 0);
- return PyString_FromStringAndSize(self->x509_name->bytes->data,
- self->x509_name->bytes->length);
+ return PyBytes_FromStringAndSize(self->x509_name->bytes->data,
+ self->x509_name->bytes->length);
}
@@ -342,8 +376,8 @@
/* printf("fname is %s len=%d str=%s\n", OBJ_nid2sn(nid), l, str); */
tuple = PyTuple_New(2);
- PyTuple_SetItem(tuple, 0, PyString_FromString(OBJ_nid2sn(nid)));
- PyTuple_SetItem(tuple, 1, PyString_FromStringAndSize((char *)str, l));
+ PyTuple_SetItem(tuple, 0, PyBytes_FromString(OBJ_nid2sn(nid)));
+ PyTuple_SetItem(tuple, 1, PyBytes_FromStringAndSize((char *)str, l));
PyList_SetItem(list, i, tuple);
}
@@ -421,8 +455,7 @@
#undef ADD_METHOD
PyTypeObject crypto_X509Name_Type = {
- PyObject_HEAD_INIT(NULL)
- 0,
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"X509Name",
sizeof(crypto_X509NameObj),
0,
@@ -430,7 +463,7 @@
NULL, /* print */
(getattrfunc)crypto_X509Name_getattr,
(setattrfunc)crypto_X509Name_setattr,
- (cmpfunc)crypto_X509Name_compare,
+ NULL, /* reserved */
(reprfunc)crypto_X509Name_repr,
NULL, /* as_number */
NULL, /* as_sequence */
@@ -445,7 +478,7 @@
crypto_X509Name_doc, /* tp_doc */
(traverseproc)crypto_X509Name_traverse, /* tp_traverse */
(inquiry)crypto_X509Name_clear, /* tp_clear */
- NULL, /* tp_richcompare */
+ crypto_X509Name_richcompare, /* tp_richcompare */
0, /* tp_weaklistoffset */
NULL, /* tp_iter */
NULL, /* tp_iternext */
diff --git a/OpenSSL/py3k.h b/OpenSSL/py3k.h
index 55bcfda..dc46b43 100644
--- a/OpenSSL/py3k.h
+++ b/OpenSSL/py3k.h
@@ -13,6 +13,8 @@
#else /* (PY_VERSION_HEX >= 0x03000000) */
+#define PyVarObject_HEAD_INIT(type, size) PyObject_HEAD_INIT(NULL) 0
+
#define PyBytes_FromStringAndSize PyString_FromStringAndSize
#define PyLong_FromLong PyInt_FromLong