Commit 11f8539a authored by Fred Drake's avatar Fred Drake

ANSI-fied sources, converted to four-space indentation.

Converted to PyArg_ParseTuple() with method names to get better error
messages.
parent aa0e56bb
...@@ -66,9 +66,7 @@ typedef struct { ...@@ -66,9 +66,7 @@ typedef struct {
/* When run on a little-endian CPU we need to perform byte reversal on an /* When run on a little-endian CPU we need to perform byte reversal on an
array of longwords. */ array of longwords. */
static void longReverse(buffer, byteCount, Endianness) static void longReverse(SHA_INT32 *buffer, int byteCount, int Endianness)
SHA_INT32 *buffer;
int byteCount, Endianness;
{ {
SHA_INT32 value; SHA_INT32 value;
...@@ -76,8 +74,7 @@ static void longReverse(buffer, byteCount, Endianness) ...@@ -76,8 +74,7 @@ static void longReverse(buffer, byteCount, Endianness)
return; return;
byteCount /= sizeof(*buffer); byteCount /= sizeof(*buffer);
while( byteCount-- ) while (byteCount--) {
{
value = *buffer; value = *buffer;
value = ( ( value & 0xFF00FF00L ) >> 8 ) | \ value = ( ( value & 0xFF00FF00L ) >> 8 ) | \
( ( value & 0x00FF00FFL ) << 8 ); ( ( value & 0x00FF00FFL ) << 8 );
...@@ -85,8 +82,7 @@ static void longReverse(buffer, byteCount, Endianness) ...@@ -85,8 +82,7 @@ static void longReverse(buffer, byteCount, Endianness)
} }
} }
static void SHAcopy(src, dest) static void SHAcopy(SHAobject *src, SHAobject *dest)
SHAobject *src, *dest;
{ {
dest->Endianness = src->Endianness; dest->Endianness = src->Endianness;
dest->local = src->local; dest->local = src->local;
...@@ -173,8 +169,7 @@ static void SHAcopy(src, dest) ...@@ -173,8 +169,7 @@ static void SHAcopy(src, dest)
/* do SHA transformation */ /* do SHA transformation */
static void static void
sha_transform(sha_info) sha_transform(SHAobject *sha_info)
SHAobject *sha_info;
{ {
int i; int i;
SHA_INT32 T, A, B, C, D, E, W[80], *WP; SHA_INT32 T, A, B, C, D, E, W[80], *WP;
...@@ -235,8 +230,7 @@ sha_transform(sha_info) ...@@ -235,8 +230,7 @@ sha_transform(sha_info)
/* initialize the SHA digest */ /* initialize the SHA digest */
static void static void
sha_init(sha_info) sha_init(SHAobject *sha_info)
SHAobject *sha_info;
{ {
TestEndianness(sha_info->Endianness) TestEndianness(sha_info->Endianness)
...@@ -253,10 +247,7 @@ sha_init(sha_info) ...@@ -253,10 +247,7 @@ sha_init(sha_info)
/* update the SHA digest */ /* update the SHA digest */
static void static void
sha_update(sha_info, buffer, count) sha_update(SHAobject *sha_info, SHA_BYTE *buffer, int count)
SHAobject *sha_info;
SHA_BYTE *buffer;
int count;
{ {
int i; int i;
SHA_INT32 clo; SHA_INT32 clo;
...@@ -272,14 +263,14 @@ sha_update(sha_info, buffer, count) ...@@ -272,14 +263,14 @@ sha_update(sha_info, buffer, count)
if (i > count) { if (i > count) {
i = count; i = count;
} }
memcpy(((SHA_BYTE *) sha_info->data) + sha_info->local, memcpy(((SHA_BYTE *) sha_info->data) + sha_info->local, buffer, i);
buffer, i);
count -= i; count -= i;
buffer += i; buffer += i;
sha_info->local += i; sha_info->local += i;
if (sha_info->local == SHA_BLOCKSIZE) { if (sha_info->local == SHA_BLOCKSIZE) {
sha_transform(sha_info); sha_transform(sha_info);
} else { }
else {
return; return;
} }
} }
...@@ -296,9 +287,7 @@ sha_update(sha_info, buffer, count) ...@@ -296,9 +287,7 @@ sha_update(sha_info, buffer, count)
/* finish computing the SHA digest */ /* finish computing the SHA digest */
static void static void
sha_final(digest, sha_info) sha_final(unsigned char digest[20], SHAobject *sha_info)
unsigned char digest[20];
SHAobject *sha_info;
{ {
int count; int count;
SHA_INT32 lo_bit_count, hi_bit_count; SHA_INT32 lo_bit_count, hi_bit_count;
...@@ -307,15 +296,13 @@ sha_final(digest, sha_info) ...@@ -307,15 +296,13 @@ sha_final(digest, sha_info)
hi_bit_count = sha_info->count_hi; hi_bit_count = sha_info->count_hi;
count = (int) ((lo_bit_count >> 3) & 0x3f); count = (int) ((lo_bit_count >> 3) & 0x3f);
((SHA_BYTE *) sha_info->data)[count++] = 0x80; ((SHA_BYTE *) sha_info->data)[count++] = 0x80;
if (count > SHA_BLOCKSIZE - 8) if (count > SHA_BLOCKSIZE - 8) {
{
memset(((SHA_BYTE *) sha_info->data) + count, 0, memset(((SHA_BYTE *) sha_info->data) + count, 0,
SHA_BLOCKSIZE - count); SHA_BLOCKSIZE - count);
sha_transform(sha_info); sha_transform(sha_info);
memset((SHA_BYTE *) sha_info->data, 0, SHA_BLOCKSIZE - 8); memset((SHA_BYTE *) sha_info->data, 0, SHA_BLOCKSIZE - 8);
} }
else else {
{
memset(((SHA_BYTE *) sha_info->data) + count, 0, memset(((SHA_BYTE *) sha_info->data) + count, 0,
SHA_BLOCKSIZE - 8 - count); SHA_BLOCKSIZE - 8 - count);
} }
...@@ -371,8 +358,7 @@ newSHAobject() ...@@ -371,8 +358,7 @@ newSHAobject()
/* Internal methods for a hashing object */ /* Internal methods for a hashing object */
static void static void
SHA_dealloc(ptr) SHA_dealloc(PyObject *ptr)
PyObject *ptr;
{ {
PyObject_Del(ptr); PyObject_Del(ptr);
} }
...@@ -384,16 +370,13 @@ static char SHA_copy__doc__[] = ...@@ -384,16 +370,13 @@ static char SHA_copy__doc__[] =
"Return a copy of the hashing object."; "Return a copy of the hashing object.";
static PyObject * static PyObject *
SHA_copy(self, args) SHA_copy(SHAobject *self, PyObject *args)
SHAobject *self;
PyObject *args;
{ {
SHAobject *newobj; SHAobject *newobj;
if (!PyArg_NoArgs(args)) { if (!PyArg_ParseTuple(args, ":copy")) {
return NULL; return NULL;
} }
if ( (newobj = newSHAobject())==NULL) if ( (newobj = newSHAobject())==NULL)
return NULL; return NULL;
...@@ -405,14 +388,12 @@ static char SHA_digest__doc__[] = ...@@ -405,14 +388,12 @@ static char SHA_digest__doc__[] =
"Return the digest value as a string of binary data."; "Return the digest value as a string of binary data.";
static PyObject * static PyObject *
SHA_digest(self, args) SHA_digest(SHAobject *self, PyObject *args)
SHAobject *self;
PyObject *args;
{ {
unsigned char digest[SHA_DIGESTSIZE]; unsigned char digest[SHA_DIGESTSIZE];
SHAobject temp; SHAobject temp;
if (!PyArg_NoArgs(args)) if (!PyArg_ParseTuple(args, ":digest"))
return NULL; return NULL;
SHAcopy(self, &temp); SHAcopy(self, &temp);
...@@ -424,9 +405,7 @@ static char SHA_hexdigest__doc__[] = ...@@ -424,9 +405,7 @@ static char SHA_hexdigest__doc__[] =
"Return the digest value as a string of hexadecimal digits."; "Return the digest value as a string of hexadecimal digits.";
static PyObject * static PyObject *
SHA_hexdigest(self, args) SHA_hexdigest(SHAobject *self, PyObject *args)
SHAobject *self;
PyObject *args;
{ {
unsigned char digest[SHA_DIGESTSIZE]; unsigned char digest[SHA_DIGESTSIZE];
SHAobject temp; SHAobject temp;
...@@ -434,7 +413,7 @@ SHA_hexdigest(self, args) ...@@ -434,7 +413,7 @@ SHA_hexdigest(self, args)
char *hex_digest; char *hex_digest;
int i, j; int i, j;
if (!PyArg_NoArgs(args)) if (!PyArg_ParseTuple(args, ":hexdigest"))
return NULL; return NULL;
/* Get the raw (binary) digest value */ /* Get the raw (binary) digest value */
...@@ -446,15 +425,13 @@ SHA_hexdigest(self, args) ...@@ -446,15 +425,13 @@ SHA_hexdigest(self, args)
hex_digest = PyString_AsString(retval); hex_digest = PyString_AsString(retval);
/* Make hex version of the digest */ /* Make hex version of the digest */
for(i=j=0; i<sizeof(digest); i++) for(i=j=0; i<sizeof(digest); i++) {
{
char c; char c;
c = digest[i] / 16; c = (c>9) ? c+'a'-10 : c + '0'; c = digest[i] / 16; c = (c>9) ? c+'a'-10 : c + '0';
hex_digest[j++] = c; hex_digest[j++] = c;
c = digest[i] % 16; c = (c>9) ? c+'a'-10 : c + '0'; c = digest[i] % 16; c = (c>9) ? c+'a'-10 : c + '0';
hex_digest[j++] = c; hex_digest[j++] = c;
} }
return retval; return retval;
} }
...@@ -462,14 +439,12 @@ static char SHA_update__doc__[] = ...@@ -462,14 +439,12 @@ static char SHA_update__doc__[] =
"Update this hashing object's state with the provided string."; "Update this hashing object's state with the provided string.";
static PyObject * static PyObject *
SHA_update(self, args) SHA_update(SHAobject *self, PyObject *args)
SHAobject *self;
PyObject *args;
{ {
unsigned char *cp; unsigned char *cp;
int len; int len;
if (!PyArg_Parse(args, "s#", &cp, &len)) if (!PyArg_ParseTuple(args, "s#:update", &cp, &len))
return NULL; return NULL;
sha_update(self, cp, len); sha_update(self, cp, len);
...@@ -479,17 +454,15 @@ SHA_update(self, args) ...@@ -479,17 +454,15 @@ SHA_update(self, args)
} }
static PyMethodDef SHA_methods[] = { static PyMethodDef SHA_methods[] = {
{"copy", (PyCFunction)SHA_copy, 0, SHA_copy__doc__}, {"copy", (PyCFunction)SHA_copy, METH_VARARGS, SHA_copy__doc__},
{"digest", (PyCFunction)SHA_digest, 0, SHA_digest__doc__}, {"digest", (PyCFunction)SHA_digest, METH_VARARGS, SHA_digest__doc__},
{"hexdigest", (PyCFunction)SHA_hexdigest, 0, SHA_hexdigest__doc__}, {"hexdigest", (PyCFunction)SHA_hexdigest, METH_VARARGS, SHA_hexdigest__doc__},
{"update", (PyCFunction)SHA_update, 0, SHA_update__doc__}, {"update", (PyCFunction)SHA_update, METH_VARARGS, SHA_update__doc__},
{NULL, NULL} /* sentinel */ {NULL, NULL} /* sentinel */
}; };
static PyObject * static PyObject *
SHA_getattr(self, name) SHA_getattr(PyObject *self, char *name)
PyObject *self;
char *name;
{ {
if (strcmp(name, "blocksize")==0) if (strcmp(name, "blocksize")==0)
return PyInt_FromLong(1); return PyInt_FromLong(1);
...@@ -520,10 +493,7 @@ static char SHA_new__doc__[] = ...@@ -520,10 +493,7 @@ static char SHA_new__doc__[] =
" automatically hashed."; " automatically hashed.";
static PyObject * static PyObject *
SHA_new(self, args, kwdict) SHA_new(PyObject *self, PyObject *args, PyObject *kwdict)
PyObject *self;
PyObject *args;
PyObject *kwdict;
{ {
static char *kwlist[] = {"string", NULL}; static char *kwlist[] = {"string", NULL};
SHAobject *new; SHAobject *new;
...@@ -586,4 +556,3 @@ initsha() ...@@ -586,4 +556,3 @@ initsha()
if (PyErr_Occurred()) if (PyErr_Occurred())
Py_FatalError("can't initialize module SHA"); Py_FatalError("can't initialize module SHA");
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment