mirror of
https://github.com/python/cpython.git
synced 2025-08-03 00:23:06 +00:00
ANSI-fied sources, converted to four-space indentation.
Converted to PyArg_ParseTuple() with method names to get better error messages.
This commit is contained in:
parent
edabdc1e9e
commit
2c4a3dceaf
1 changed files with 147 additions and 178 deletions
|
@ -66,9 +66,7 @@ typedef struct {
|
|||
/* When run on a little-endian CPU we need to perform byte reversal on an
|
||||
array of longwords. */
|
||||
|
||||
static void longReverse(buffer, byteCount, Endianness)
|
||||
SHA_INT32 *buffer;
|
||||
int byteCount, Endianness;
|
||||
static void longReverse(SHA_INT32 *buffer, int byteCount, int Endianness)
|
||||
{
|
||||
SHA_INT32 value;
|
||||
|
||||
|
@ -76,8 +74,7 @@ static void longReverse(buffer, byteCount, Endianness)
|
|||
return;
|
||||
|
||||
byteCount /= sizeof(*buffer);
|
||||
while( byteCount-- )
|
||||
{
|
||||
while (byteCount--) {
|
||||
value = *buffer;
|
||||
value = ( ( value & 0xFF00FF00L ) >> 8 ) | \
|
||||
( ( value & 0x00FF00FFL ) << 8 );
|
||||
|
@ -85,8 +82,7 @@ static void longReverse(buffer, byteCount, Endianness)
|
|||
}
|
||||
}
|
||||
|
||||
static void SHAcopy(src, dest)
|
||||
SHAobject *src, *dest;
|
||||
static void SHAcopy(SHAobject *src, SHAobject *dest)
|
||||
{
|
||||
dest->Endianness = src->Endianness;
|
||||
dest->local = src->local;
|
||||
|
@ -173,8 +169,7 @@ static void SHAcopy(src, dest)
|
|||
/* do SHA transformation */
|
||||
|
||||
static void
|
||||
sha_transform(sha_info)
|
||||
SHAobject *sha_info;
|
||||
sha_transform(SHAobject *sha_info)
|
||||
{
|
||||
int i;
|
||||
SHA_INT32 T, A, B, C, D, E, W[80], *WP;
|
||||
|
@ -235,8 +230,7 @@ sha_transform(sha_info)
|
|||
/* initialize the SHA digest */
|
||||
|
||||
static void
|
||||
sha_init(sha_info)
|
||||
SHAobject *sha_info;
|
||||
sha_init(SHAobject *sha_info)
|
||||
{
|
||||
TestEndianness(sha_info->Endianness)
|
||||
|
||||
|
@ -253,10 +247,7 @@ sha_init(sha_info)
|
|||
/* update the SHA digest */
|
||||
|
||||
static void
|
||||
sha_update(sha_info, buffer, count)
|
||||
SHAobject *sha_info;
|
||||
SHA_BYTE *buffer;
|
||||
int count;
|
||||
sha_update(SHAobject *sha_info, SHA_BYTE *buffer, int count)
|
||||
{
|
||||
int i;
|
||||
SHA_INT32 clo;
|
||||
|
@ -272,14 +263,14 @@ sha_update(sha_info, buffer, count)
|
|||
if (i > count) {
|
||||
i = count;
|
||||
}
|
||||
memcpy(((SHA_BYTE *) sha_info->data) + sha_info->local,
|
||||
buffer, i);
|
||||
memcpy(((SHA_BYTE *) sha_info->data) + sha_info->local, buffer, i);
|
||||
count -= i;
|
||||
buffer += i;
|
||||
sha_info->local += i;
|
||||
if (sha_info->local == SHA_BLOCKSIZE) {
|
||||
sha_transform(sha_info);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -296,9 +287,7 @@ sha_update(sha_info, buffer, count)
|
|||
/* finish computing the SHA digest */
|
||||
|
||||
static void
|
||||
sha_final(digest, sha_info)
|
||||
unsigned char digest[20];
|
||||
SHAobject *sha_info;
|
||||
sha_final(unsigned char digest[20], SHAobject *sha_info)
|
||||
{
|
||||
int count;
|
||||
SHA_INT32 lo_bit_count, hi_bit_count;
|
||||
|
@ -307,15 +296,13 @@ sha_final(digest, sha_info)
|
|||
hi_bit_count = sha_info->count_hi;
|
||||
count = (int) ((lo_bit_count >> 3) & 0x3f);
|
||||
((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,
|
||||
SHA_BLOCKSIZE - count);
|
||||
sha_transform(sha_info);
|
||||
memset((SHA_BYTE *) sha_info->data, 0, SHA_BLOCKSIZE - 8);
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
memset(((SHA_BYTE *) sha_info->data) + count, 0,
|
||||
SHA_BLOCKSIZE - 8 - count);
|
||||
}
|
||||
|
@ -371,8 +358,7 @@ newSHAobject()
|
|||
/* Internal methods for a hashing object */
|
||||
|
||||
static void
|
||||
SHA_dealloc(ptr)
|
||||
PyObject *ptr;
|
||||
SHA_dealloc(PyObject *ptr)
|
||||
{
|
||||
PyObject_Del(ptr);
|
||||
}
|
||||
|
@ -384,16 +370,13 @@ static char SHA_copy__doc__[] =
|
|||
"Return a copy of the hashing object.";
|
||||
|
||||
static PyObject *
|
||||
SHA_copy(self, args)
|
||||
SHAobject *self;
|
||||
PyObject *args;
|
||||
SHA_copy(SHAobject *self, PyObject *args)
|
||||
{
|
||||
SHAobject *newobj;
|
||||
|
||||
if (!PyArg_NoArgs(args)) {
|
||||
if (!PyArg_ParseTuple(args, ":copy")) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ( (newobj = newSHAobject())==NULL)
|
||||
return NULL;
|
||||
|
||||
|
@ -405,14 +388,12 @@ static char SHA_digest__doc__[] =
|
|||
"Return the digest value as a string of binary data.";
|
||||
|
||||
static PyObject *
|
||||
SHA_digest(self, args)
|
||||
SHAobject *self;
|
||||
PyObject *args;
|
||||
SHA_digest(SHAobject *self, PyObject *args)
|
||||
{
|
||||
unsigned char digest[SHA_DIGESTSIZE];
|
||||
SHAobject temp;
|
||||
|
||||
if (!PyArg_NoArgs(args))
|
||||
if (!PyArg_ParseTuple(args, ":digest"))
|
||||
return NULL;
|
||||
|
||||
SHAcopy(self, &temp);
|
||||
|
@ -424,9 +405,7 @@ static char SHA_hexdigest__doc__[] =
|
|||
"Return the digest value as a string of hexadecimal digits.";
|
||||
|
||||
static PyObject *
|
||||
SHA_hexdigest(self, args)
|
||||
SHAobject *self;
|
||||
PyObject *args;
|
||||
SHA_hexdigest(SHAobject *self, PyObject *args)
|
||||
{
|
||||
unsigned char digest[SHA_DIGESTSIZE];
|
||||
SHAobject temp;
|
||||
|
@ -434,7 +413,7 @@ SHA_hexdigest(self, args)
|
|||
char *hex_digest;
|
||||
int i, j;
|
||||
|
||||
if (!PyArg_NoArgs(args))
|
||||
if (!PyArg_ParseTuple(args, ":hexdigest"))
|
||||
return NULL;
|
||||
|
||||
/* Get the raw (binary) digest value */
|
||||
|
@ -446,15 +425,13 @@ SHA_hexdigest(self, args)
|
|||
hex_digest = PyString_AsString(retval);
|
||||
|
||||
/* Make hex version of the digest */
|
||||
for(i=j=0; i<sizeof(digest); i++)
|
||||
{
|
||||
for(i=j=0; i<sizeof(digest); i++) {
|
||||
char c;
|
||||
c = digest[i] / 16; c = (c>9) ? c+'a'-10 : c + '0';
|
||||
hex_digest[j++] = c;
|
||||
c = digest[i] % 16; c = (c>9) ? c+'a'-10 : c + '0';
|
||||
hex_digest[j++] = c;
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
@ -462,14 +439,12 @@ static char SHA_update__doc__[] =
|
|||
"Update this hashing object's state with the provided string.";
|
||||
|
||||
static PyObject *
|
||||
SHA_update(self, args)
|
||||
SHAobject *self;
|
||||
PyObject *args;
|
||||
SHA_update(SHAobject *self, PyObject *args)
|
||||
{
|
||||
unsigned char *cp;
|
||||
int len;
|
||||
|
||||
if (!PyArg_Parse(args, "s#", &cp, &len))
|
||||
if (!PyArg_ParseTuple(args, "s#:update", &cp, &len))
|
||||
return NULL;
|
||||
|
||||
sha_update(self, cp, len);
|
||||
|
@ -479,17 +454,15 @@ SHA_update(self, args)
|
|||
}
|
||||
|
||||
static PyMethodDef SHA_methods[] = {
|
||||
{"copy", (PyCFunction)SHA_copy, 0, SHA_copy__doc__},
|
||||
{"digest", (PyCFunction)SHA_digest, 0, SHA_digest__doc__},
|
||||
{"hexdigest", (PyCFunction)SHA_hexdigest, 0, SHA_hexdigest__doc__},
|
||||
{"update", (PyCFunction)SHA_update, 0, SHA_update__doc__},
|
||||
{"copy", (PyCFunction)SHA_copy, METH_VARARGS, SHA_copy__doc__},
|
||||
{"digest", (PyCFunction)SHA_digest, METH_VARARGS, SHA_digest__doc__},
|
||||
{"hexdigest", (PyCFunction)SHA_hexdigest, METH_VARARGS, SHA_hexdigest__doc__},
|
||||
{"update", (PyCFunction)SHA_update, METH_VARARGS, SHA_update__doc__},
|
||||
{NULL, NULL} /* sentinel */
|
||||
};
|
||||
|
||||
static PyObject *
|
||||
SHA_getattr(self, name)
|
||||
PyObject *self;
|
||||
char *name;
|
||||
SHA_getattr(PyObject *self, char *name)
|
||||
{
|
||||
if (strcmp(name, "blocksize")==0)
|
||||
return PyInt_FromLong(1);
|
||||
|
@ -520,10 +493,7 @@ static char SHA_new__doc__[] =
|
|||
" automatically hashed.";
|
||||
|
||||
static PyObject *
|
||||
SHA_new(self, args, kwdict)
|
||||
PyObject *self;
|
||||
PyObject *args;
|
||||
PyObject *kwdict;
|
||||
SHA_new(PyObject *self, PyObject *args, PyObject *kwdict)
|
||||
{
|
||||
static char *kwlist[] = {"string", NULL};
|
||||
SHAobject *new;
|
||||
|
@ -586,4 +556,3 @@ initsha()
|
|||
if (PyErr_Occurred())
|
||||
Py_FatalError("can't initialize module SHA");
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue