summaryrefslogtreecommitdiff
path: root/src/stream_template.c
diff options
context:
space:
mode:
authorakuchling <akuchling@rivest.dlitz.net>2002-05-16 20:28:43 -0700
committerakuchling <akuchling@rivest.dlitz.net>2002-05-16 20:28:43 -0700
commit24f4f15f76c82bb996e40e395ca6cf0d2d1ad957 (patch)
treefc88f36f40d34d9c09cee535784fd1def24f3ffe /src/stream_template.c
parent74a71a6534a8f58a72479002fda66a20425a30e7 (diff)
downloadpycrypto-24f4f15f76c82bb996e40e395ca6cf0d2d1ad957.tar.gz
[project @ akuchling-20020517032843-d46b1f26cebb9fb8]
[project @ 2002-05-16 20:28:43 by akuchling] Re-indent into Python C style; no other changes
Diffstat (limited to 'src/stream_template.c')
-rw-r--r--src/stream_template.c252
1 files changed, 126 insertions, 126 deletions
diff --git a/src/stream_template.c b/src/stream_template.c
index cea8257..580a0e9 100644
--- a/src/stream_template.c
+++ b/src/stream_template.c
@@ -23,7 +23,7 @@
#include "Python.h"
#include "modsupport.h"
- /* Endianness testing and definitions */
+/* Endianness testing and definitions */
#define TestEndianness(variable) {int i=1; variable=PCT_BIG_ENDIAN;\
if (*((char*)&i)==1) variable=PCT_LITTLE_ENDIAN;}
@@ -31,7 +31,7 @@
#define PCT_BIG_ENDIAN 0
- /*
+/*
*
* Python interface
*
@@ -39,8 +39,8 @@
typedef struct
{
- PyObject_HEAD
- stream_state st;
+ PyObject_HEAD
+ stream_state st;
} ALGobject;
staticforward PyTypeObject ALGtype;
@@ -50,19 +50,19 @@ staticforward PyTypeObject ALGtype;
static ALGobject *
newALGobject(void)
{
- ALGobject * new;
- new = PyObject_NEW(ALGobject, &ALGtype);
- return new;
+ ALGobject * new;
+ new = PyObject_NEW(ALGobject, &ALGtype);
+ return new;
}
static void
ALGdealloc(PyObject *self)
{ /* Overwrite the contents of the object, just in case... */
- int i;
+ int i;
- for (i = 0; i < sizeof(ALGobject); i++)
- *((char *) self + i) = '\0';
- PyMem_DEL(self);
+ for (i = 0; i < sizeof(ALGobject); i++)
+ *((char *) self + i) = '\0';
+ PyMem_DEL(self);
}
static char ALGnew__doc__[] =
@@ -73,37 +73,37 @@ static char *kwlist[] = {"key", NULL};
static ALGobject *
ALGnew(PyObject *self, PyObject *args, PyObject *kwdict)
{
- unsigned char *key;
- ALGobject * new;
- int keylen;
-
- new = newALGobject();
- if (!PyArg_ParseTupleAndKeywords(args, kwdict, "s#", kwlist,
- &key, &keylen))
- {
- Py_DECREF(new);
- return (NULL);
- }
-
- if (KEY_SIZE!=0 && keylen != KEY_SIZE)
- {
- PyErr_SetString(PyExc_ValueError, "ALG key must be "
- "KEY_SIZE bytes long");
- return (NULL);
- }
- if (KEY_SIZE== 0 && keylen == 0)
- {
- PyErr_SetString(PyExc_ValueError, "ALG key cannot be "
- "the null string (0 bytes long)");
- return (NULL);
- }
- stream_init(&(new->st), key, keylen);
- if (PyErr_Occurred())
- {
- Py_DECREF(new);
- return (NULL);
- }
- return new;
+ unsigned char *key;
+ ALGobject * new;
+ int keylen;
+
+ new = newALGobject();
+ if (!PyArg_ParseTupleAndKeywords(args, kwdict, "s#", kwlist,
+ &key, &keylen))
+ {
+ Py_DECREF(new);
+ return (NULL);
+ }
+
+ if (KEY_SIZE!=0 && keylen != KEY_SIZE)
+ {
+ PyErr_SetString(PyExc_ValueError, "ALG key must be "
+ "KEY_SIZE bytes long");
+ return (NULL);
+ }
+ if (KEY_SIZE== 0 && keylen == 0)
+ {
+ PyErr_SetString(PyExc_ValueError, "ALG key cannot be "
+ "the null string (0 bytes long)");
+ return (NULL);
+ }
+ stream_init(&(new->st), key, keylen);
+ if (PyErr_Occurred())
+ {
+ Py_DECREF(new);
+ return (NULL);
+ }
+ return new;
}
static char ALG_Encrypt__doc__[] =
@@ -112,28 +112,28 @@ static char ALG_Encrypt__doc__[] =
static PyObject *
ALG_Encrypt(ALGobject *self, PyObject *args)
{
- unsigned char *buffer, *str;
- int len;
- PyObject *result;
-
- if (!PyArg_Parse(args, "s#", &str, &len))
- return (NULL);
- if (len == 0) /* Handle empty string */
- {
- return PyString_FromStringAndSize(NULL, 0);
- }
- buffer = malloc(len);
- if (buffer == NULL)
- {
- PyErr_SetString(PyExc_MemoryError, "No memory available in "
- "ALG encrypt");
- return (NULL);
- }
- memcpy(buffer, str, len);
- stream_encrypt(&(self->st), buffer, len);
- result = PyString_FromStringAndSize(buffer, len);
- free(buffer);
- return (result);
+ unsigned char *buffer, *str;
+ int len;
+ PyObject *result;
+
+ if (!PyArg_Parse(args, "s#", &str, &len))
+ return (NULL);
+ if (len == 0) /* Handle empty string */
+ {
+ return PyString_FromStringAndSize(NULL, 0);
+ }
+ buffer = malloc(len);
+ if (buffer == NULL)
+ {
+ PyErr_SetString(PyExc_MemoryError, "No memory available in "
+ "ALG encrypt");
+ return (NULL);
+ }
+ memcpy(buffer, str, len);
+ stream_encrypt(&(self->st), buffer, len);
+ result = PyString_FromStringAndSize(buffer, len);
+ free(buffer);
+ return (result);
}
static char ALG_Decrypt__doc__[] =
@@ -142,51 +142,51 @@ static char ALG_Decrypt__doc__[] =
static PyObject *
ALG_Decrypt(ALGobject *self, PyObject *args)
{
- char *buffer, *str;
- int len;
- PyObject *result;
-
- if (!PyArg_Parse(args, "s#", &str, &len))
- return (NULL);
- if (len == 0) /* Handle empty string */
- {
- return PyString_FromStringAndSize(NULL, 0);
- }
- buffer = malloc(len);
- if (buffer == NULL)
- {
- PyErr_SetString(PyExc_MemoryError, "No memory available in "
- "ALG decrypt");
- return (NULL);
- }
- memcpy(buffer, str, len);
- stream_decrypt(&(self->st), buffer, len);
- result = PyString_FromStringAndSize(buffer, len);
- free(buffer);
- return (result);
+ char *buffer, *str;
+ int len;
+ PyObject *result;
+
+ if (!PyArg_Parse(args, "s#", &str, &len))
+ return (NULL);
+ if (len == 0) /* Handle empty string */
+ {
+ return PyString_FromStringAndSize(NULL, 0);
+ }
+ buffer = malloc(len);
+ if (buffer == NULL)
+ {
+ PyErr_SetString(PyExc_MemoryError, "No memory available in "
+ "ALG decrypt");
+ return (NULL);
+ }
+ memcpy(buffer, str, len);
+ stream_decrypt(&(self->st), buffer, len);
+ result = PyString_FromStringAndSize(buffer, len);
+ free(buffer);
+ return (result);
}
/* ALGobject methods */
static PyMethodDef ALGmethods[] =
{
- {"encrypt", (PyCFunction) ALG_Encrypt, 0, ALG_Encrypt__doc__},
- {"decrypt", (PyCFunction) ALG_Decrypt, 0, ALG_Decrypt__doc__},
- {NULL, NULL} /* sentinel */
+ {"encrypt", (PyCFunction) ALG_Encrypt, 0, ALG_Encrypt__doc__},
+ {"decrypt", (PyCFunction) ALG_Decrypt, 0, ALG_Decrypt__doc__},
+ {NULL, NULL} /* sentinel */
};
static PyObject *
ALGgetattr(PyObject *self, char *name)
{
- if (strcmp(name, "block_size") == 0)
- {
- return PyInt_FromLong(BLOCK_SIZE);
- }
- if (strcmp(name, "key_size") == 0)
- {
- return PyInt_FromLong(KEY_SIZE);
- }
- return Py_FindMethod(ALGmethods, self, name);
+ if (strcmp(name, "block_size") == 0)
+ {
+ return PyInt_FromLong(BLOCK_SIZE);
+ }
+ if (strcmp(name, "key_size") == 0)
+ {
+ return PyInt_FromLong(KEY_SIZE);
+ }
+ return Py_FindMethod(ALGmethods, self, name);
}
@@ -194,25 +194,25 @@ ALGgetattr(PyObject *self, char *name)
static struct PyMethodDef modulemethods[] =
{
- {"new", (PyCFunction) ALGnew, METH_VARARGS|METH_KEYWORDS, ALGnew__doc__},
- {NULL, NULL} /* sentinel */
+ {"new", (PyCFunction) ALGnew, METH_VARARGS|METH_KEYWORDS, ALGnew__doc__},
+ {NULL, NULL} /* sentinel */
};
static PyTypeObject ALGtype =
{
- PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
- "ALG", /*tp_name*/
- sizeof(ALGobject), /*tp_size*/
- 0, /*tp_itemsize*/
- /* methods */
- ALGdealloc, /*tp_dealloc*/
- 0, /*tp_print*/
- ALGgetattr, /*tp_getattr*/
- 0, /*tp_setattr*/
- 0, /*tp_compare*/
- 0, /*tp_repr*/
- 0, /*tp_as_number*/
+ PyObject_HEAD_INIT(NULL)
+ 0, /*ob_size*/
+ "ALG", /*tp_name*/
+ sizeof(ALGobject), /*tp_size*/
+ 0, /*tp_itemsize*/
+ /* methods */
+ ALGdealloc, /*tp_dealloc*/
+ 0, /*tp_print*/
+ ALGgetattr, /*tp_getattr*/
+ 0, /*tp_setattr*/
+ 0, /*tp_compare*/
+ 0, /*tp_repr*/
+ 0, /*tp_as_number*/
};
/* Initialization function for the module (*must* be called initxx) */
@@ -229,23 +229,23 @@ static PyTypeObject ALGtype =
void
_MODULE_NAME (void)
{
- PyObject *m, *d, *x;
+ PyObject *m, *d, *x;
- ALGtype.ob_type = &PyType_Type;
- /* Create the module and add the functions */
- m = Py_InitModule("Crypto.Cipher." _MODULE_STRING, modulemethods);
+ ALGtype.ob_type = &PyType_Type;
+ /* Create the module and add the functions */
+ m = Py_InitModule("Crypto.Cipher." _MODULE_STRING, modulemethods);
- /* Add some symbolic constants to the module */
- d = PyModule_GetDict(m);
- x = PyString_FromString(_MODULE_STRING ".error");
- PyDict_SetItemString(d, "error", x);
+ /* Add some symbolic constants to the module */
+ d = PyModule_GetDict(m);
+ x = PyString_FromString(_MODULE_STRING ".error");
+ PyDict_SetItemString(d, "error", x);
- insint("block_size", BLOCK_SIZE);
- insint("key_size", KEY_SIZE);
+ insint("block_size", BLOCK_SIZE);
+ insint("key_size", KEY_SIZE);
- /* Check for errors */
- if (PyErr_Occurred())
- Py_FatalError("can't initialize module " _MODULE_STRING);
+ /* Check for errors */
+ if (PyErr_Occurred())
+ Py_FatalError("can't initialize module " _MODULE_STRING);
}