Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(20)

Side by Side Diff: Modules/sha1module.c

Issue 20173: Derby #4: Convert 53 sites to Argument Clinic across 5 files
Patch Set: Created 6 years, 2 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* SHA1 module */ 1 /* SHA1 module */
2 2
3 /* This module provides an interface to the SHA1 algorithm */ 3 /* This module provides an interface to the SHA1 algorithm */
4 4
5 /* See below for information about the original code this module was 5 /* See below for information about the original code this module was
6 based upon. Additional work performed by: 6 based upon. Additional work performed by:
7 7
8 Andrew Kuchling (amk@amk.ca) 8 Andrew Kuchling (amk@amk.ca)
9 Greg Stein (gstein@lyra.org) 9 Greg Stein (gstein@lyra.org)
10 Trevor Perrin (trevp@trevp.net) 10 Trevor Perrin (trevp@trevp.net)
(...skipping 15 matching lines...) Expand all
26 typedef unsigned int SHA1_INT32; /* 32-bit integer */ 26 typedef unsigned int SHA1_INT32; /* 32-bit integer */
27 typedef PY_LONG_LONG SHA1_INT64; /* 64-bit integer */ 27 typedef PY_LONG_LONG SHA1_INT64; /* 64-bit integer */
28 #else 28 #else
29 /* not defined. compilation will die. */ 29 /* not defined. compilation will die. */
30 #endif 30 #endif
31 31
32 /* The SHA1 block size and message digest sizes, in bytes */ 32 /* The SHA1 block size and message digest sizes, in bytes */
33 33
34 #define SHA1_BLOCKSIZE 64 34 #define SHA1_BLOCKSIZE 64
35 #define SHA1_DIGESTSIZE 20 35 #define SHA1_DIGESTSIZE 20
36
37 /*[clinic input]
38 module _sha1
39 class _sha1.SHA1
40 [clinic start generated code]*/
41 /*[clinic end generated code: checksum=da39a3ee5e6b4b0d3255bfef95601890afd80709] */
42 /*[python input]
43 class SHA1object_converter(self_converter):
44 type = "SHA1object *"
45 [python start generated code]*/
46 /*[python end generated code: checksum=da39a3ee5e6b4b0d3255bfef95601890afd80709] */
36 47
37 /* The structure for storing SHA1 info */ 48 /* The structure for storing SHA1 info */
38 49
39 struct sha1_state { 50 struct sha1_state {
40 SHA1_INT64 length; 51 SHA1_INT64 length;
41 SHA1_INT32 state[5], curlen; 52 SHA1_INT32 state[5], curlen;
42 unsigned char buf[SHA1_BLOCKSIZE]; 53 unsigned char buf[SHA1_BLOCKSIZE];
43 }; 54 };
44 55
45 typedef struct { 56 typedef struct {
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 hex_digest[j++] = Py_hexdigits[c]; 377 hex_digest[j++] = Py_hexdigits[c];
367 c = (digest[i] & 0xf); 378 c = (digest[i] & 0xf);
368 hex_digest[j++] = Py_hexdigits[c]; 379 hex_digest[j++] = Py_hexdigits[c];
369 } 380 }
370 #ifdef Py_DEBUG 381 #ifdef Py_DEBUG
371 assert(_PyUnicode_CheckConsistency(retval, 1)); 382 assert(_PyUnicode_CheckConsistency(retval, 1));
372 #endif 383 #endif
373 return retval; 384 return retval;
374 } 385 }
375 386
376 PyDoc_STRVAR(SHA1_update__doc__, 387 /*[clinic input]
377 "Update this hash object's state with the provided string."); 388 _sha1.SHA1.update
389
390 self: SHA1object
391 args: object
392 /
393
394 Update this hash object's state with the provided string.
395 [clinic start generated code]*/
396
397 PyDoc_STRVAR(_sha1_SHA1_update__doc__,
398 "update(args)\n"
399 "Update this hash object\'s state with the provided string.");
400
401 #define _SHA1_SHA1_UPDATE_METHODDEF \
402 {"update", (PyCFunction)_sha1_SHA1_update, METH_O, _sha1_SHA1_update__doc__} ,
378 403
379 static PyObject * 404 static PyObject *
380 SHA1_update(SHA1object *self, PyObject *args) 405 _sha1_SHA1_update(SHA1object *self, PyObject *args)
406 /*[clinic end generated code: checksum=a39d7531d589e7124e2ba96359cb2be591758c2c] */
381 { 407 {
382 PyObject *obj; 408 PyObject *obj;
383 Py_buffer buf; 409 Py_buffer buf;
384 410
385 if (!PyArg_ParseTuple(args, "O:update", &obj)) 411 if (!PyArg_ParseTuple(args, "O:update", &obj))
386 return NULL; 412 return NULL;
387 413
388 GET_BUFFER_VIEW_OR_ERROUT(obj, &buf); 414 GET_BUFFER_VIEW_OR_ERROUT(obj, &buf);
389 415
390 sha1_process(&self->hash_state, buf.buf, buf.len); 416 sha1_process(&self->hash_state, buf.buf, buf.len);
391 417
392 PyBuffer_Release(&buf); 418 PyBuffer_Release(&buf);
393 Py_INCREF(Py_None); 419 Py_INCREF(Py_None);
394 return Py_None; 420 return Py_None;
395 } 421 }
396 422
397 static PyMethodDef SHA1_methods[] = { 423 static PyMethodDef SHA1_methods[] = {
398 {"copy", (PyCFunction)SHA1_copy, METH_NOARGS, SHA1_copy__doc__}, 424 {"copy", (PyCFunction)SHA1_copy, METH_NOARGS, SHA1_copy__doc__},
399 {"digest", (PyCFunction)SHA1_digest, METH_NOARGS, SHA1_digest__doc__} , 425 {"digest", (PyCFunction)SHA1_digest, METH_NOARGS, SHA1_digest__doc__} ,
426 _SHA1_SHA1_UPDATE_METHODDEF
400 {"hexdigest", (PyCFunction)SHA1_hexdigest, METH_NOARGS, SHA1_hexdigest__doc __}, 427 {"hexdigest", (PyCFunction)SHA1_hexdigest, METH_NOARGS, SHA1_hexdigest__doc __},
401 {"update", (PyCFunction)SHA1_update, METH_VARARGS, SHA1_update__doc__} ,
402 {NULL, NULL} /* sentinel */ 428 {NULL, NULL} /* sentinel */
403 }; 429 };
404 430
405 static PyObject * 431 static PyObject *
406 SHA1_get_block_size(PyObject *self, void *closure) 432 SHA1_get_block_size(PyObject *self, void *closure)
407 { 433 {
408 return PyLong_FromLong(SHA1_BLOCKSIZE); 434 return PyLong_FromLong(SHA1_BLOCKSIZE);
409 } 435 }
410 436
411 static PyObject * 437 static PyObject *
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 0, /*tp_iter*/ 493 0, /*tp_iter*/
468 0, /*tp_iternext*/ 494 0, /*tp_iternext*/
469 SHA1_methods, /* tp_methods */ 495 SHA1_methods, /* tp_methods */
470 NULL, /* tp_members */ 496 NULL, /* tp_members */
471 SHA1_getseters, /* tp_getset */ 497 SHA1_getseters, /* tp_getset */
472 }; 498 };
473 499
474 500
475 /* The single module-level function: new() */ 501 /* The single module-level function: new() */
476 502
477 PyDoc_STRVAR(SHA1_new__doc__, 503 /*[clinic input]
504 _sha1.SHA1.sha1
505
506 [
larry 2014/01/08 12:40:11 You shouldn't have the square brackets here. Just
larry 2014/01/08 12:51:07 Sorry for the incomplete sentence. I meant to say
507 string: object = NULL
508 ]
509
510 Return a new SHA1 hash object; optionally initialized with a string.
511 [clinic start generated code]*/
512
513 PyDoc_STRVAR(_sha1_SHA1_sha1__doc__,
514 "sha1(string=None)\n"
478 "Return a new SHA1 hash object; optionally initialized with a string."); 515 "Return a new SHA1 hash object; optionally initialized with a string.");
479 516
517 #define _SHA1_SHA1_SHA1_METHODDEF \
518 {"sha1", (PyCFunction)_sha1_SHA1_sha1, METH_VARARGS|METH_KEYWORDS, _sha1_SHA 1_sha1__doc__},
519
480 static PyObject * 520 static PyObject *
481 SHA1_new(PyObject *self, PyObject *args, PyObject *kwdict) 521 _sha1_SHA1_sha1_impl(PyObject *self, PyObject *string);
522
523 static PyObject *
524 _sha1_SHA1_sha1(PyObject *self, PyObject *args, PyObject *kwargs)
482 { 525 {
483 static char *kwlist[] = {"string", NULL}; 526 PyObject *return_value = NULL;
527 static char *_keywords[] = {"string", NULL};
528 PyObject *string = NULL;
529
530 if (!PyArg_ParseTupleAndKeywords(args, kwargs,
531 "|O:sha1", _keywords,
532 &string))
533 goto exit;
534 return_value = _sha1_SHA1_sha1_impl(self, string);
535
536 exit:
537 return return_value;
538 }
539
540 static PyObject *
541 _sha1_SHA1_sha1_impl(PyObject *self, PyObject *string)
542 /*[clinic end generated code: checksum=ee414d8be9a6b1d5e00052af67cd5cfcd7924078] */
543 {
484 SHA1object *new; 544 SHA1object *new;
485 PyObject *data_obj = NULL;
486 Py_buffer buf; 545 Py_buffer buf;
487 546
488 if (!PyArg_ParseTupleAndKeywords(args, kwdict, "|O:new", kwlist, 547 if (string)
489 &data_obj)) { 548 GET_BUFFER_VIEW_OR_ERROUT(string, &buf);
490 return NULL;
491 }
492
493 if (data_obj)
494 GET_BUFFER_VIEW_OR_ERROUT(data_obj, &buf);
495 549
496 if ((new = newSHA1object()) == NULL) { 550 if ((new = newSHA1object()) == NULL) {
497 if (data_obj) 551 if (string)
498 PyBuffer_Release(&buf); 552 PyBuffer_Release(&buf);
499 return NULL; 553 return NULL;
500 } 554 }
501 555
502 sha1_init(&new->hash_state); 556 sha1_init(&new->hash_state);
503 557
504 if (PyErr_Occurred()) { 558 if (PyErr_Occurred()) {
505 Py_DECREF(new); 559 Py_DECREF(new);
506 if (data_obj) 560 if (string)
507 PyBuffer_Release(&buf); 561 PyBuffer_Release(&buf);
508 return NULL; 562 return NULL;
509 } 563 }
510 if (data_obj) { 564 if (string) {
511 sha1_process(&new->hash_state, buf.buf, buf.len); 565 sha1_process(&new->hash_state, buf.buf, buf.len);
512 PyBuffer_Release(&buf); 566 PyBuffer_Release(&buf);
513 } 567 }
514 568
515 return (PyObject *)new; 569 return (PyObject *)new;
516 } 570 }
517 571
518 572
519 /* List of functions exported by this module */ 573 /* List of functions exported by this module */
520 574
521 static struct PyMethodDef SHA1_functions[] = { 575 static struct PyMethodDef SHA1_functions[] = {
522 {"sha1",(PyCFunction)SHA1_new, METH_VARARGS|METH_KEYWORDS,SHA1_new__doc__}, 576 _SHA1_SHA1_SHA1_METHODDEF
523 {NULL, NULL} /* Sentinel */ 577 {NULL, NULL} /* Sentinel */
524 }; 578 };
525 579
526 580
527 /* Initialize this module. */ 581 /* Initialize this module. */
528 582
529 #define insint(n,v) { PyModule_AddIntConstant(m,n,v); } 583 #define insint(n,v) { PyModule_AddIntConstant(m,n,v); }
530 584
531 585
532 static struct PyModuleDef _sha1module = { 586 static struct PyModuleDef _sha1module = {
(...skipping 18 matching lines...) Expand all
551 return NULL; 605 return NULL;
552 606
553 m = PyModule_Create(&_sha1module); 607 m = PyModule_Create(&_sha1module);
554 if (m == NULL) 608 if (m == NULL)
555 return NULL; 609 return NULL;
556 610
557 Py_INCREF((PyObject *)&SHA1type); 611 Py_INCREF((PyObject *)&SHA1type);
558 PyModule_AddObject(m, "SHA1Type", (PyObject *)&SHA1type); 612 PyModule_AddObject(m, "SHA1Type", (PyObject *)&SHA1type);
559 return m; 613 return m;
560 } 614 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+