blob: 705683e6ae5ed07a156f7df293a4e0a8c2c9c398 [file] [log] [blame]
Jean-Paul Calderone897bc252008-02-18 20:50:23 -05001/*
2 * x509name.c
3 *
Jean-Paul Calderone8671c852011-03-02 19:26:20 -05004 * Copyright (C) AB Strakt
5 * Copyright (C) Jean-Paul Calderone
6 * See LICENSE for details.
Jean-Paul Calderone897bc252008-02-18 20:50:23 -05007 *
8 * X.509 Name handling, mostly thin wrapping.
9 * See the file RATIONALE for a short explanation of why this module was written.
10 *
11 * Reviewed 2001-07-23
12 */
13#include <Python.h>
14#define crypto_MODULE
15#include "crypto.h"
16
Jean-Paul Calderone28ebb302008-12-29 16:25:30 -050017static PyMethodDef crypto_X509Name_methods[4];
Jean-Paul Calderone110cd092008-03-24 17:27:42 -040018
Jean-Paul Calderone897bc252008-02-18 20:50:23 -050019/*
20 * Constructor for X509Name, never called by Python code directly
21 *
22 * Arguments: name - A "real" X509_NAME object
23 * dealloc - Boolean value to specify whether the destructor should
24 * free the "real" X509_NAME object
25 * Returns: The newly created X509Name object
26 */
27crypto_X509NameObj *
28crypto_X509Name_New(X509_NAME *name, int dealloc)
29{
30 crypto_X509NameObj *self;
31
32 self = PyObject_GC_New(crypto_X509NameObj, &crypto_X509Name_Type);
33
34 if (self == NULL)
35 return NULL;
36
37 self->x509_name = name;
38 self->dealloc = dealloc;
39 self->parent_cert = NULL;
40
41 PyObject_GC_Track(self);
42 return self;
43}
44
Jean-Paul Calderone2cd7a922009-06-27 11:02:46 -040045
46static char crypto_X509Name_doc[] = "\n\
47X509Name(name) -> New X509Name object\n\
48\n\
49Create a new X509Name, copying the given X509Name instance.\n\
50\n\
Jonathan Ballet78b92a22011-07-16 08:07:26 +090051:param name: An X509Name object to copy\n\
52:return: The X509Name object\n\
Jean-Paul Calderone2cd7a922009-06-27 11:02:46 -040053";
54
55static PyObject *
56crypto_X509Name_new(PyTypeObject *subtype, PyObject *args, PyObject *kwargs)
57{
58 crypto_X509NameObj *name;
59
60 if (!PyArg_ParseTuple(args, "O!:X509Name", &crypto_X509Name_Type, &name)) {
61 return NULL;
62 }
63
64 return (PyObject *)crypto_X509Name_New(X509_NAME_dup(name->x509_name), 1);
65}
66
67
Jean-Paul Calderone897bc252008-02-18 20:50:23 -050068/*
69 * Return a name string given a X509_NAME object and a name identifier. Used
70 * by the getattr function.
71 *
72 * Arguments: name - The X509_NAME object
73 * nid - The name identifier
74 * Returns: The name as a Python string object
75 */
76static int
77get_name_by_nid(X509_NAME *name, int nid, char **utf8string)
78{
79 int entry_idx;
80 X509_NAME_ENTRY *entry;
81 ASN1_STRING *data;
82 int len;
83
84 if ((entry_idx = X509_NAME_get_index_by_NID(name, nid, -1)) == -1)
85 {
86 return 0;
87 }
88 entry = X509_NAME_get_entry(name, entry_idx);
89 data = X509_NAME_ENTRY_get_data(entry);
90 if ((len = ASN1_STRING_to_UTF8((unsigned char **)utf8string, data)) < 0)
91 {
Rick Deand369c932009-07-08 11:48:33 -050092 exception_from_error_queue(crypto_Error);
Jean-Paul Calderone897bc252008-02-18 20:50:23 -050093 return -1;
94 }
95
96 return len;
97}
98
99/*
100 * Given a X509_NAME object and a name identifier, set the corresponding
101 * attribute to the given string. Used by the setattr function.
102 *
103 * Arguments: name - The X509_NAME object
104 * nid - The name identifier
105 * value - The string to set
106 * Returns: 0 for success, -1 on failure
107 */
108static int
109set_name_by_nid(X509_NAME *name, int nid, char *utf8string)
110{
111 X509_NAME_ENTRY *ne;
112 int i, entry_count, temp_nid;
113
114 /* If there's an old entry for this NID, remove it */
115 entry_count = X509_NAME_entry_count(name);
116 for (i = 0; i < entry_count; i++)
117 {
118 ne = X509_NAME_get_entry(name, i);
119 temp_nid = OBJ_obj2nid(X509_NAME_ENTRY_get_object(ne));
120 if (temp_nid == nid)
121 {
122 ne = X509_NAME_delete_entry(name, i);
123 X509_NAME_ENTRY_free(ne);
124 break;
125 }
126 }
127
128 /* Add the new entry */
Jean-Paul Calderone28ebb302008-12-29 16:25:30 -0500129 if (!X509_NAME_add_entry_by_NID(name, nid, MBSTRING_UTF8,
130 (unsigned char *)utf8string,
131 -1, -1, 0))
Jean-Paul Calderone897bc252008-02-18 20:50:23 -0500132 {
Rick Deand369c932009-07-08 11:48:33 -0500133 exception_from_error_queue(crypto_Error);
Jean-Paul Calderone897bc252008-02-18 20:50:23 -0500134 return -1;
135 }
136 return 0;
137}
138
139
140/*
141 * Find attribute. An X509Name object has the following attributes:
142 * countryName (alias C), stateOrProvince (alias ST), locality (alias L),
143 * organization (alias O), organizationalUnit (alias OU), commonName (alias
144 * CN) and more...
145 *
146 * Arguments: self - The X509Name object
147 * name - The attribute name
148 * Returns: A Python object for the attribute, or NULL if something went
149 * wrong
150 */
151static PyObject *
Jean-Paul Calderone0f31ec52010-08-11 22:56:42 -0400152crypto_X509Name_getattro(crypto_X509NameObj *self, PyObject *nameobj)
Jean-Paul Calderone897bc252008-02-18 20:50:23 -0500153{
154 int nid, len;
155 char *utf8string;
Jean-Paul Calderone3fe7f672010-08-11 23:55:10 -0400156 char *name;
157#ifdef PY3
Jean-Paul Calderonedc3275f2010-08-22 17:04:09 -0400158 name = PyBytes_AsString(PyUnicode_AsASCIIString(nameobj));
159#else
Jean-Paul Calderone3fe7f672010-08-11 23:55:10 -0400160 name = PyBytes_AsString(nameobj);
Jean-Paul Calderonedc3275f2010-08-22 17:04:09 -0400161#endif
Jean-Paul Calderone897bc252008-02-18 20:50:23 -0500162
Jean-Paul Calderoneef414d52009-07-16 16:21:04 -0400163 if ((nid = OBJ_txt2nid(name)) == NID_undef) {
164 /*
165 * This is a bit weird. OBJ_txt2nid indicated failure, but it seems
166 * a lower level function, a2d_ASN1_OBJECT, also feels the need to
167 * push something onto the error queue. If we don't clean that up
168 * now, someone else will bump into it later and be quite confused.
169 * See lp#314814.
170 */
171 flush_error_queue();
Jean-Paul Calderone0f31ec52010-08-11 22:56:42 -0400172 return PyObject_GenericGetAttr((PyObject*)self, nameobj);
Jean-Paul Calderone897bc252008-02-18 20:50:23 -0500173 }
174
175 len = get_name_by_nid(self->x509_name, nid, &utf8string);
176 if (len < 0)
177 return NULL;
178 else if (len == 0)
179 {
180 Py_INCREF(Py_None);
181 return Py_None;
182 }
Jean-Paul Calderone5b8c5ee2008-02-19 00:43:02 -0500183 else {
184 PyObject* result = PyUnicode_Decode(utf8string, len, "utf-8", NULL);
185 OPENSSL_free(utf8string);
186 return result;
187 }
Jean-Paul Calderone897bc252008-02-18 20:50:23 -0500188}
189
190/*
191 * Set attribute
192 *
193 * Arguments: self - The X509Name object
194 * name - The attribute name
195 * value - The value to set
196 */
197static int
Jean-Paul Calderone9ce9afb2011-04-22 18:16:22 -0400198crypto_X509Name_setattro(crypto_X509NameObj *self, PyObject *nameobj, PyObject *value)
Jean-Paul Calderone897bc252008-02-18 20:50:23 -0500199{
200 int nid;
Jean-Paul Calderone7b0443a2008-02-19 00:25:30 -0500201 int result;
Jean-Paul Calderone897bc252008-02-18 20:50:23 -0500202 char *buffer;
Jean-Paul Calderone9ce9afb2011-04-22 18:16:22 -0400203 char *name;
204
Jean-Paul Calderone5163f572011-04-22 18:38:16 -0400205 if (!PyBytes_CheckExact(nameobj) && !PyUnicode_CheckExact(nameobj)) {
Jean-Paul Calderone9ce9afb2011-04-22 18:16:22 -0400206 PyErr_Format(PyExc_TypeError,
207 "attribute name must be string, not '%.200s'",
208 Py_TYPE(nameobj)->tp_name);
209 return -1;
210 }
Jean-Paul Calderone897bc252008-02-18 20:50:23 -0500211
Jean-Paul Calderone5163f572011-04-22 18:38:16 -0400212#ifdef PY3
213 name = PyBytes_AsString(PyUnicode_AsASCIIString(nameobj));
214#else
215 name = PyBytes_AsString(nameobj);
216#endif
217
Jean-Paul Calderone897bc252008-02-18 20:50:23 -0500218 if ((nid = OBJ_txt2nid(name)) == NID_undef)
219 {
Jean-Paul Calderone9ce9afb2011-04-22 18:16:22 -0400220 /* Just like the case in the getattr function */
221 flush_error_queue();
Jean-Paul Calderone897bc252008-02-18 20:50:23 -0500222 PyErr_SetString(PyExc_AttributeError, "No such attribute");
223 return -1;
224 }
225
226 /* Something of a hack to get nice unicode behaviour */
227 if (!PyArg_Parse(value, "es:setattr", "utf-8", &buffer))
228 return -1;
Jean-Paul Calderone5b8c5ee2008-02-19 00:43:02 -0500229
Jean-Paul Calderone7b0443a2008-02-19 00:25:30 -0500230 result = set_name_by_nid(self->x509_name, nid, buffer);
231 PyMem_Free(buffer);
232 return result;
Jean-Paul Calderone897bc252008-02-18 20:50:23 -0500233}
234
235/*
236 * Compare two X509Name structures.
237 *
238 * Arguments: n - The first X509Name
239 * m - The second X509Name
240 * Returns: <0 if n < m, 0 if n == m and >0 if n > m
241 */
Jean-Paul Calderone4d0c3212010-08-10 22:57:42 -0400242static PyObject *
243crypto_X509Name_richcompare(PyObject *n, PyObject *m, int op) {
244 int result;
245
246 if (!crypto_X509Name_Check(n) || !crypto_X509Name_Check(m)) {
247 Py_INCREF(Py_NotImplemented);
248 return Py_NotImplemented;
249 }
250
251 result = X509_NAME_cmp(
252 ((crypto_X509NameObj*)n)->x509_name,
253 ((crypto_X509NameObj*)m)->x509_name);
254
255 switch (op) {
256 case Py_EQ:
257 result = (result == 0);
Jean-Paul Calderone072195d2010-08-12 20:09:57 -0400258 break;
Jean-Paul Calderone4d0c3212010-08-10 22:57:42 -0400259
260 case Py_NE:
261 result = (result != 0);
Jean-Paul Calderone072195d2010-08-12 20:09:57 -0400262 break;
Jean-Paul Calderone4d0c3212010-08-10 22:57:42 -0400263
264 case Py_LT:
265 result = (result < 0);
Jean-Paul Calderone072195d2010-08-12 20:09:57 -0400266 break;
Jean-Paul Calderone4d0c3212010-08-10 22:57:42 -0400267
268 case Py_LE:
269 result = (result <= 0);
Jean-Paul Calderone072195d2010-08-12 20:09:57 -0400270 break;
Jean-Paul Calderone4d0c3212010-08-10 22:57:42 -0400271
272 case Py_GT:
273 result = (result > 0);
Jean-Paul Calderone072195d2010-08-12 20:09:57 -0400274 break;
Jean-Paul Calderone4d0c3212010-08-10 22:57:42 -0400275
276 case Py_GE:
277 result = (result >= 0);
Jean-Paul Calderone072195d2010-08-12 20:09:57 -0400278 break;
Jean-Paul Calderone4d0c3212010-08-10 22:57:42 -0400279
280 default:
281 /* Should be impossible */
282 Py_INCREF(Py_NotImplemented);
283 return Py_NotImplemented;
284 }
285
286 if (result) {
287 Py_INCREF(Py_True);
288 return Py_True;
Jean-Paul Calderone138a3122008-12-30 15:05:38 -0500289 } else {
Jean-Paul Calderone4d0c3212010-08-10 22:57:42 -0400290 Py_INCREF(Py_False);
291 return Py_False;
Jean-Paul Calderone138a3122008-12-30 15:05:38 -0500292 }
Jean-Paul Calderone897bc252008-02-18 20:50:23 -0500293}
294
295/*
296 * String representation of an X509Name
297 *
298 * Arguments: self - The X509Name object
299 * Returns: A string representation of the object
300 */
301static PyObject *
302crypto_X509Name_repr(crypto_X509NameObj *self)
303{
304 char tmpbuf[512] = "";
305 char realbuf[512+64];
306
307 if (X509_NAME_oneline(self->x509_name, tmpbuf, 512) == NULL)
308 {
Rick Deand369c932009-07-08 11:48:33 -0500309 exception_from_error_queue(crypto_Error);
Jean-Paul Calderone897bc252008-02-18 20:50:23 -0500310 return NULL;
311 }
312 else
313 {
314 /* This is safe because tmpbuf is max 512 characters */
315 sprintf(realbuf, "<X509Name object '%s'>", tmpbuf);
Jean-Paul Calderone4d0c3212010-08-10 22:57:42 -0400316 return PyText_FromString(realbuf);
Jean-Paul Calderone897bc252008-02-18 20:50:23 -0500317 }
318}
319
Jean-Paul Calderone110cd092008-03-24 17:27:42 -0400320static char crypto_X509Name_hash_doc[] = "\n\
Jean-Paul Calderone54bcc832009-05-27 14:06:48 -0400321Return the hash value of this name\n\
Jean-Paul Calderone110cd092008-03-24 17:27:42 -0400322\n\
Jonathan Ballet78b92a22011-07-16 08:07:26 +0900323:return: None\n\
Jean-Paul Calderone110cd092008-03-24 17:27:42 -0400324";
325
326/*
327 * First four bytes of the MD5 digest of the DER form of an X509Name.
328 *
329 * Arguments: self - The X509Name object
330 * Returns: An integer giving the hash.
331 */
332static PyObject *
333crypto_X509Name_hash(crypto_X509NameObj *self, PyObject* args)
334{
335 unsigned long hash;
336
337 if (!PyArg_ParseTuple(args, ":hash")) {
338 return NULL;
339 }
340 hash = X509_NAME_hash(self->x509_name);
Jean-Paul Calderone4d0c3212010-08-10 22:57:42 -0400341 return PyLong_FromLong(hash);
Jean-Paul Calderone110cd092008-03-24 17:27:42 -0400342}
343
Jean-Paul Calderonee957a002008-03-25 15:16:51 -0400344static char crypto_X509Name_der_doc[] = "\n\
Jean-Paul Calderone54bcc832009-05-27 14:06:48 -0400345Return the DER encoding of this name\n\
Jean-Paul Calderonee957a002008-03-25 15:16:51 -0400346\n\
Jonathan Ballet78b92a22011-07-16 08:07:26 +0900347:return: None\n\
Jean-Paul Calderonee957a002008-03-25 15:16:51 -0400348";
349
350/*
351 * Arguments: self - The X509Name object
352 * Returns: The DER form of an X509Name.
353 */
354static PyObject *
355crypto_X509Name_der(crypto_X509NameObj *self, PyObject *args)
356{
357 if (!PyArg_ParseTuple(args, ":der")) {
358 return NULL;
359 }
360
361 i2d_X509_NAME(self->x509_name, 0);
Jean-Paul Calderone4d0c3212010-08-10 22:57:42 -0400362 return PyBytes_FromStringAndSize(self->x509_name->bytes->data,
363 self->x509_name->bytes->length);
Jean-Paul Calderonee957a002008-03-25 15:16:51 -0400364}
365
Jean-Paul Calderone110cd092008-03-24 17:27:42 -0400366
Jean-Paul Calderonec54cc182008-03-26 21:11:07 -0400367static char crypto_X509Name_get_components_doc[] = "\n\
368Returns the split-up components of this name.\n\
369\n\
Jonathan Ballet78b92a22011-07-16 08:07:26 +0900370:return: List of tuples (name, value).\n\
Jean-Paul Calderonec54cc182008-03-26 21:11:07 -0400371";
372
373static PyObject *
374crypto_X509Name_get_components(crypto_X509NameObj *self, PyObject *args)
375{
376 int n, i;
377 X509_NAME *name = self->x509_name;
378 PyObject *list;
379
380 if (!PyArg_ParseTuple(args, ":get_components"))
381 return NULL;
382
383 n = X509_NAME_entry_count(name);
384 list = PyList_New(n);
385 for (i = 0; i < n; i++)
386 {
387 X509_NAME_ENTRY *ent;
388 ASN1_OBJECT *fname;
389 ASN1_STRING *fval;
390 int nid;
391 int l;
Jean-Paul Calderonec54cc182008-03-26 21:11:07 -0400392 unsigned char *str;
393 PyObject *tuple;
394
395 ent = X509_NAME_get_entry(name, i);
396
397 fname = X509_NAME_ENTRY_get_object(ent);
398 fval = X509_NAME_ENTRY_get_data(ent);
399
400 l = ASN1_STRING_length(fval);
401 str = ASN1_STRING_data(fval);
402
403 nid = OBJ_obj2nid(fname);
404
405 /* printf("fname is %s len=%d str=%s\n", OBJ_nid2sn(nid), l, str); */
406
407 tuple = PyTuple_New(2);
Jean-Paul Calderone4d0c3212010-08-10 22:57:42 -0400408 PyTuple_SetItem(tuple, 0, PyBytes_FromString(OBJ_nid2sn(nid)));
409 PyTuple_SetItem(tuple, 1, PyBytes_FromStringAndSize((char *)str, l));
Jean-Paul Calderonec54cc182008-03-26 21:11:07 -0400410
411 PyList_SetItem(list, i, tuple);
412 }
413
414 return list;
415}
416
417
Jean-Paul Calderone897bc252008-02-18 20:50:23 -0500418/*
419 * Call the visitproc on all contained objects.
420 *
421 * Arguments: self - The Connection object
422 * visit - Function to call
423 * arg - Extra argument to visit
424 * Returns: 0 if all goes well, otherwise the return code from the first
425 * call that gave non-zero result.
426 */
427static int
428crypto_X509Name_traverse(crypto_X509NameObj *self, visitproc visit, void *arg)
429{
430 int ret = 0;
431
432 if (ret == 0 && self->parent_cert != NULL)
433 ret = visit(self->parent_cert, arg);
434 return ret;
435}
436
437/*
438 * Decref all contained objects and zero the pointers.
439 *
440 * Arguments: self - The Connection object
441 * Returns: Always 0.
442 */
443static int
444crypto_X509Name_clear(crypto_X509NameObj *self)
445{
446 Py_XDECREF(self->parent_cert);
447 self->parent_cert = NULL;
448 return 0;
449}
450
451/*
452 * Deallocate the memory used by the X509Name object
453 *
454 * Arguments: self - The X509Name object
455 * Returns: None
456 */
457static void
458crypto_X509Name_dealloc(crypto_X509NameObj *self)
459{
460 PyObject_GC_UnTrack(self);
461 /* Sometimes we don't have to dealloc this */
462 if (self->dealloc)
463 X509_NAME_free(self->x509_name);
464
465 crypto_X509Name_clear(self);
466
467 PyObject_GC_Del(self);
468}
469
Jean-Paul Calderone110cd092008-03-24 17:27:42 -0400470/*
471 * ADD_METHOD(name) expands to a correct PyMethodDef declaration
472 * { 'name', (PyCFunction)crypto_X509_name, METH_VARARGS }
473 * for convenience
474 */
475#define ADD_METHOD(name) \
476 { #name, (PyCFunction)crypto_X509Name_##name, METH_VARARGS, crypto_X509Name_##name##_doc }
477static PyMethodDef crypto_X509Name_methods[] =
478{
479 ADD_METHOD(hash),
Jean-Paul Calderonee957a002008-03-25 15:16:51 -0400480 ADD_METHOD(der),
Jean-Paul Calderonec54cc182008-03-26 21:11:07 -0400481 ADD_METHOD(get_components),
Jean-Paul Calderone110cd092008-03-24 17:27:42 -0400482 { NULL, NULL }
483};
484#undef ADD_METHOD
485
Jean-Paul Calderone897bc252008-02-18 20:50:23 -0500486PyTypeObject crypto_X509Name_Type = {
Jean-Paul Calderone3fe7f672010-08-11 23:55:10 -0400487 PyOpenSSL_HEAD_INIT(&PyType_Type, 0)
Jean-Paul Calderone897bc252008-02-18 20:50:23 -0500488 "X509Name",
489 sizeof(crypto_X509NameObj),
490 0,
491 (destructor)crypto_X509Name_dealloc,
492 NULL, /* print */
Jean-Paul Calderone0f31ec52010-08-11 22:56:42 -0400493 NULL, /* getattr */
Jean-Paul Calderone9ce9afb2011-04-22 18:16:22 -0400494 NULL, /* setattr */
Jean-Paul Calderone4d0c3212010-08-10 22:57:42 -0400495 NULL, /* reserved */
Jean-Paul Calderone897bc252008-02-18 20:50:23 -0500496 (reprfunc)crypto_X509Name_repr,
497 NULL, /* as_number */
498 NULL, /* as_sequence */
499 NULL, /* as_mapping */
500 NULL, /* hash */
501 NULL, /* call */
502 NULL, /* str */
Jean-Paul Calderone0f31ec52010-08-11 22:56:42 -0400503 (getattrofunc)crypto_X509Name_getattro, /* getattro */
Jean-Paul Calderone9ce9afb2011-04-22 18:16:22 -0400504 (setattrofunc)crypto_X509Name_setattro, /* setattro */
Jean-Paul Calderone897bc252008-02-18 20:50:23 -0500505 NULL, /* as_buffer */
Jean-Paul Calderone110cd092008-03-24 17:27:42 -0400506 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */
Jean-Paul Calderone2cd7a922009-06-27 11:02:46 -0400507 crypto_X509Name_doc, /* tp_doc */
Jean-Paul Calderone110cd092008-03-24 17:27:42 -0400508 (traverseproc)crypto_X509Name_traverse, /* tp_traverse */
509 (inquiry)crypto_X509Name_clear, /* tp_clear */
Jean-Paul Calderone4d0c3212010-08-10 22:57:42 -0400510 crypto_X509Name_richcompare, /* tp_richcompare */
Jean-Paul Calderone2cd7a922009-06-27 11:02:46 -0400511 0, /* tp_weaklistoffset */
512 NULL, /* tp_iter */
513 NULL, /* tp_iternext */
514 crypto_X509Name_methods, /* tp_methods */
515 NULL, /* tp_members */
516 NULL, /* tp_getset */
517 NULL, /* tp_base */
518 NULL, /* tp_dict */
519 NULL, /* tp_descr_get */
520 NULL, /* tp_descr_set */
521 0, /* tp_dictoffset */
522 NULL, /* tp_init */
523 NULL, /* tp_alloc */
524 crypto_X509Name_new, /* tp_new */
Jean-Paul Calderone897bc252008-02-18 20:50:23 -0500525};
526
Jean-Paul Calderone897bc252008-02-18 20:50:23 -0500527/*
528 * Initialize the X509Name part of the crypto module
529 *
Jean-Paul Calderone2cd7a922009-06-27 11:02:46 -0400530 * Arguments: module - The crypto module
Jean-Paul Calderone897bc252008-02-18 20:50:23 -0500531 * Returns: None
532 */
533int
Jean-Paul Calderone2cd7a922009-06-27 11:02:46 -0400534init_crypto_x509name(PyObject *module)
Jean-Paul Calderone897bc252008-02-18 20:50:23 -0500535{
Jean-Paul Calderone2cd7a922009-06-27 11:02:46 -0400536 if (PyType_Ready(&crypto_X509Name_Type) < 0) {
537 return 0;
538 }
539
Jean-Paul Calderone86ad7112010-05-11 16:08:45 -0400540 /* PyModule_AddObject steals a reference.
541 */
542 Py_INCREF((PyObject *)&crypto_X509Name_Type);
Jean-Paul Calderone2cd7a922009-06-27 11:02:46 -0400543 if (PyModule_AddObject(module, "X509Name", (PyObject *)&crypto_X509Name_Type) != 0) {
544 return 0;
545 }
546
Jean-Paul Calderoneaed23582011-03-12 22:45:02 -0500547 /* PyModule_AddObject steals a reference.
548 */
Jean-Paul Calderoned07d57d2011-03-12 22:35:24 -0500549 Py_INCREF((PyObject *)&crypto_X509Name_Type);
Jean-Paul Calderone2cd7a922009-06-27 11:02:46 -0400550 if (PyModule_AddObject(module, "X509NameType", (PyObject *)&crypto_X509Name_Type) != 0) {
551 return 0;
552 }
553
Jean-Paul Calderone897bc252008-02-18 20:50:23 -0500554 return 1;
555}