#include <Python.h>
#define crypto_MODULE
#include "crypto.h"
static char *CVSid = "@(#) $Id: pkcs7.c,v 1.2 2004/09/23 14:25:28 murata Exp $";
static char crypto_PKCS7_type_is_signed_doc[] = "\n\
Check if this NID_pkcs7_signed object\n\
\n\
Arguments: self - The PKCS7 object\n\
args - An empty argument tuple\n\
Returns: True if the PKCS7 is of type signed\n\
";
static PyObject *
crypto_PKCS7_type_is_signed(crypto_PKCS7Obj *self, PyObject *args)
{
if (!PyArg_ParseTuple(args, ":type_is_signed"))
return NULL;
if (PKCS7_type_is_signed(self->pkcs7))
return PyInt_FromLong(1L);
else
return PyInt_FromLong(0L);
}
static char crypto_PKCS7_type_is_enveloped_doc[] = "\n\
Check if this NID_pkcs7_enveloped object\n\
\n\
Arguments: self - The PKCS7 object\n\
args - An empty argument tuple\n\
Returns: True if the PKCS7 is of type enveloped\n\
";
static PyObject *
crypto_PKCS7_type_is_enveloped(crypto_PKCS7Obj *self, PyObject *args)
{
if (!PyArg_ParseTuple(args, ":type_is_enveloped"))
return NULL;
if (PKCS7_type_is_enveloped(self->pkcs7))
return PyInt_FromLong(1L);
else
return PyInt_FromLong(0L);
}
static char crypto_PKCS7_type_is_signedAndEnveloped_doc[] = "\n\
Check if this NID_pkcs7_signedAndEnveloped object\n\
\n\
Arguments: self - The PKCS7 object\n\
args - An empty argument tuple\n\
Returns: True if the PKCS7 is of type signedAndEnveloped\n\
";
static PyObject *
crypto_PKCS7_type_is_signedAndEnveloped(crypto_PKCS7Obj *self, PyObject *args)
{
if (!PyArg_ParseTuple(args, ":type_is_signedAndEnveloped"))
return NULL;
if (PKCS7_type_is_signedAndEnveloped(self->pkcs7))
return PyInt_FromLong(1L);
else
return PyInt_FromLong(0L);
}
static char crypto_PKCS7_type_is_data_doc[] = "\n\
Check if this NID_pkcs7_data object\n\
\n\
Arguments: self - The PKCS7 object\n\
args - An empty argument tuple\n\
Returns: True if the PKCS7 is of type data\n\
";
static PyObject *
crypto_PKCS7_type_is_data(crypto_PKCS7Obj *self, PyObject *args)
{
if (!PyArg_ParseTuple(args, ":type_is_data"))
return NULL;
if (PKCS7_type_is_data(self->pkcs7))
return PyInt_FromLong(1L);
else
return PyInt_FromLong(0L);
}
static char crypto_PKCS7_get_type_name_doc[] = "\n\
Returns the type name of the PKCS7 structure\n\
\n\
Arguments: self - The PKCS7 object\n\
args - An empty argument tuple\n\
Returns: A string with the typename\n\
";
static PyObject *
crypto_PKCS7_get_type_name(crypto_PKCS7Obj *self, PyObject *args)
{
if (!PyArg_ParseTuple(args, ":get_type_name"))
return NULL;
return PyString_FromString(OBJ_nid2sn(OBJ_obj2nid(self->pkcs7->type)));
}
#define ADD_METHOD(name) \
{ #name, (PyCFunction)crypto_PKCS7_##name, METH_VARARGS, crypto_PKCS7_##name##_doc }
static PyMethodDef crypto_PKCS7_methods[] =
{
ADD_METHOD(type_is_signed),
ADD_METHOD(type_is_enveloped),
ADD_METHOD(type_is_signedAndEnveloped),
ADD_METHOD(type_is_data),
ADD_METHOD(get_type_name),
{ NULL, NULL }
};
#undef ADD_METHOD
crypto_PKCS7Obj *
crypto_PKCS7_New(PKCS7 *pkcs7, int dealloc)
{
crypto_PKCS7Obj *self;
self = PyObject_New(crypto_PKCS7Obj, &crypto_PKCS7_Type);
if (self == NULL)
return NULL;
self->pkcs7 = pkcs7;
self->dealloc = dealloc;
return self;
}
static void
crypto_PKCS7_dealloc(crypto_PKCS7Obj *self)
{
if (self->dealloc)
PKCS7_free(self->pkcs7);
PyObject_Del(self);
}
static PyObject *
crypto_PKCS7_getattr(crypto_PKCS7Obj *self, char *name)
{
return Py_FindMethod(crypto_PKCS7_methods, (PyObject *)self, name);
}
PyTypeObject crypto_PKCS7_Type = {
PyObject_HEAD_INIT(NULL)
0,
"PKCS7",
sizeof(crypto_PKCS7Obj),
0,
(destructor)crypto_PKCS7_dealloc,
NULL,
(getattrfunc)crypto_PKCS7_getattr,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL
};
int
init_crypto_pkcs7(PyObject *dict)
{
crypto_PKCS7_Type.ob_type = &PyType_Type;
Py_INCREF(&crypto_PKCS7_Type);
PyDict_SetItemString(dict, "PKCS7Type", (PyObject *)&crypto_PKCS7_Type);
return 1;
}