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

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, 3 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
larry 2014/01/10 12:36:53 The name of the type is SHA1Type.
389 self: SHA1object
390 obj: object
391 /
392
393 Update this hash object's state with the provided string.
394 [clinic start generated code]*/
395
396 PyDoc_STRVAR(_sha1_SHA1_update__doc__,
397 "update(obj)\n"
398 "Update this hash object\'s state with the provided string.");
399
400 #define _SHA1_SHA1_UPDATE_METHODDEF \
401 {"update", (PyCFunction)_sha1_SHA1_update, METH_O, _sha1_SHA1_update__doc__} ,
378 402
379 static PyObject * 403 static PyObject *
380 SHA1_update(SHA1object *self, PyObject *args) 404 _sha1_SHA1_update(SHA1object *self, PyObject *obj)
405 /*[clinic end generated code: checksum=e4215b9d33337c4a4f1f05705ab5ddcf3c65c599] */
381 { 406 {
382 PyObject *obj;
383 Py_buffer buf; 407 Py_buffer buf;
384
385 if (!PyArg_ParseTuple(args, "O:update", &obj))
386 return NULL;
387 408
388 GET_BUFFER_VIEW_OR_ERROUT(obj, &buf); 409 GET_BUFFER_VIEW_OR_ERROUT(obj, &buf);
389 410
390 sha1_process(&self->hash_state, buf.buf, buf.len); 411 sha1_process(&self->hash_state, buf.buf, buf.len);
391 412
392 PyBuffer_Release(&buf); 413 PyBuffer_Release(&buf);
393 Py_INCREF(Py_None); 414 Py_INCREF(Py_None);
394 return Py_None; 415 return Py_None;
395 } 416 }
396 417
397 static PyMethodDef SHA1_methods[] = { 418 static PyMethodDef SHA1_methods[] = {
398 {"copy", (PyCFunction)SHA1_copy, METH_NOARGS, SHA1_copy__doc__}, 419 {"copy", (PyCFunction)SHA1_copy, METH_NOARGS, SHA1_copy__doc__},
399 {"digest", (PyCFunction)SHA1_digest, METH_NOARGS, SHA1_digest__doc__} , 420 {"digest", (PyCFunction)SHA1_digest, METH_NOARGS, SHA1_digest__doc__} ,
400 {"hexdigest", (PyCFunction)SHA1_hexdigest, METH_NOARGS, SHA1_hexdigest__doc __}, 421 {"hexdigest", (PyCFunction)SHA1_hexdigest, METH_NOARGS, SHA1_hexdigest__doc __},
401 {"update", (PyCFunction)SHA1_update, METH_VARARGS, SHA1_update__doc__} , 422 _SHA1_SHA1_UPDATE_METHODDEF
402 {NULL, NULL} /* sentinel */ 423 {NULL, NULL} /* sentinel */
403 }; 424 };
404 425
405 static PyObject * 426 static PyObject *
406 SHA1_get_block_size(PyObject *self, void *closure) 427 SHA1_get_block_size(PyObject *self, void *closure)
407 { 428 {
408 return PyLong_FromLong(SHA1_BLOCKSIZE); 429 return PyLong_FromLong(SHA1_BLOCKSIZE);
409 } 430 }
410 431
411 static PyObject * 432 static PyObject *
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 0, /*tp_iter*/ 488 0, /*tp_iter*/
468 0, /*tp_iternext*/ 489 0, /*tp_iternext*/
469 SHA1_methods, /* tp_methods */ 490 SHA1_methods, /* tp_methods */
470 NULL, /* tp_members */ 491 NULL, /* tp_members */
471 SHA1_getseters, /* tp_getset */ 492 SHA1_getseters, /* tp_getset */
472 }; 493 };
473 494
474 495
475 /* The single module-level function: new() */ 496 /* The single module-level function: new() */
476 497
477 PyDoc_STRVAR(SHA1_new__doc__, 498 /*[clinic input]
499 _sha1.SHA1.sha1
500
501 string: object = None
larry 2014/01/10 12:36:53 Use a default value of NULL here.
502
503 Return a new SHA1 hash object; optionally initialized with a string.
504 [clinic start generated code]*/
505
506 PyDoc_STRVAR(_sha1_SHA1_sha1__doc__,
507 "sha1(string=None)\n"
478 "Return a new SHA1 hash object; optionally initialized with a string."); 508 "Return a new SHA1 hash object; optionally initialized with a string.");
479 509
510 #define _SHA1_SHA1_SHA1_METHODDEF \
511 {"sha1", (PyCFunction)_sha1_SHA1_sha1, METH_VARARGS|METH_KEYWORDS, _sha1_SHA 1_sha1__doc__},
512
480 static PyObject * 513 static PyObject *
481 SHA1_new(PyObject *self, PyObject *args, PyObject *kwdict) 514 _sha1_SHA1_sha1_impl(PyObject *self, PyObject *string);
515
516 static PyObject *
517 _sha1_SHA1_sha1(PyObject *self, PyObject *args, PyObject *kwargs)
482 { 518 {
483 static char *kwlist[] = {"string", NULL}; 519 PyObject *return_value = NULL;
520 static char *_keywords[] = {"string", NULL};
521 PyObject *string = Py_None;
522
523 if (!PyArg_ParseTupleAndKeywords(args, kwargs,
524 "|O:sha1", _keywords,
525 &string))
526 goto exit;
527 return_value = _sha1_SHA1_sha1_impl(self, string);
528
529 exit:
530 return return_value;
531 }
532
533 static PyObject *
534 _sha1_SHA1_sha1_impl(PyObject *self, PyObject *string)
535 /*[clinic end generated code: checksum=855cccc92a991cc651f3907f4b2293852856033c] */
536 {
484 SHA1object *new; 537 SHA1object *new;
485 PyObject *data_obj = NULL;
486 Py_buffer buf; 538 Py_buffer buf;
487 539
488 if (!PyArg_ParseTupleAndKeywords(args, kwdict, "|O:new", kwlist, 540 if (string != Py_None)
larry 2014/01/10 12:36:53 And once you use a default value of NULL, you shou
489 &data_obj)) { 541 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 542
496 if ((new = newSHA1object()) == NULL) { 543 if ((new = newSHA1object()) == NULL) {
497 if (data_obj) 544 if (string != Py_None)
498 PyBuffer_Release(&buf); 545 PyBuffer_Release(&buf);
499 return NULL; 546 return NULL;
500 } 547 }
501 548
502 sha1_init(&new->hash_state); 549 sha1_init(&new->hash_state);
503 550
504 if (PyErr_Occurred()) { 551 if (PyErr_Occurred()) {
505 Py_DECREF(new); 552 Py_DECREF(new);
506 if (data_obj) 553 if (string != Py_None)
507 PyBuffer_Release(&buf); 554 PyBuffer_Release(&buf);
508 return NULL; 555 return NULL;
509 } 556 }
510 if (data_obj) { 557 if (string != Py_None) {
511 sha1_process(&new->hash_state, buf.buf, buf.len); 558 sha1_process(&new->hash_state, buf.buf, buf.len);
512 PyBuffer_Release(&buf); 559 PyBuffer_Release(&buf);
513 } 560 }
514 561
515 return (PyObject *)new; 562 return (PyObject *)new;
516 } 563 }
517 564
518 565
519 /* List of functions exported by this module */ 566 /* List of functions exported by this module */
520 567
521 static struct PyMethodDef SHA1_functions[] = { 568 static struct PyMethodDef SHA1_functions[] = {
522 {"sha1",(PyCFunction)SHA1_new, METH_VARARGS|METH_KEYWORDS,SHA1_new__doc__}, 569 _SHA1_SHA1_SHA1_METHODDEF
523 {NULL, NULL} /* Sentinel */ 570 {NULL, NULL} /* Sentinel */
524 }; 571 };
525 572
526 573
527 /* Initialize this module. */ 574 /* Initialize this module. */
528 575
529 #define insint(n,v) { PyModule_AddIntConstant(m,n,v); } 576 #define insint(n,v) { PyModule_AddIntConstant(m,n,v); }
530 577
531 578
532 static struct PyModuleDef _sha1module = { 579 static struct PyModuleDef _sha1module = {
(...skipping 18 matching lines...) Expand all
551 return NULL; 598 return NULL;
552 599
553 m = PyModule_Create(&_sha1module); 600 m = PyModule_Create(&_sha1module);
554 if (m == NULL) 601 if (m == NULL)
555 return NULL; 602 return NULL;
556 603
557 Py_INCREF((PyObject *)&SHA1type); 604 Py_INCREF((PyObject *)&SHA1type);
558 PyModule_AddObject(m, "SHA1Type", (PyObject *)&SHA1type); 605 PyModule_AddObject(m, "SHA1Type", (PyObject *)&SHA1type);
559 return m; 606 return m;
560 } 607 }
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+