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

Side by Side Diff: Modules/md5module.c

Issue 20173: Derby #4: Convert 53 sites to Argument Clinic across 5 files
Patch Set: Created 6 years, 1 month 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 /* MD5 module */ 1 /* MD5 module */
2 2
3 /* This module provides an interface to the MD5 algorithm */ 3 /* This module provides an interface to the MD5 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 MD5_INT32; /* 32-bit integer */ 26 typedef unsigned int MD5_INT32; /* 32-bit integer */
27 typedef PY_LONG_LONG MD5_INT64; /* 64-bit integer */ 27 typedef PY_LONG_LONG MD5_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 MD5 block size and message digest sizes, in bytes */ 32 /* The MD5 block size and message digest sizes, in bytes */
33 33
34 #define MD5_BLOCKSIZE 64 34 #define MD5_BLOCKSIZE 64
35 #define MD5_DIGESTSIZE 16 35 #define MD5_DIGESTSIZE 16
36
37 /*[clinic input]
38 module _md5
39 class _md5.MD5
larry 2014/01/10 13:05:03 The correct name of this type is "MD5Type".
40 [clinic start generated code]*/
41 /*[clinic end generated code: checksum=da39a3ee5e6b4b0d3255bfef95601890afd80709] */
42 /*[python input]
43 class MD5object_converter(self_converter):
44 type = "MD5object *"
45 [python start generated code]*/
46 /*[python end generated code: checksum=da39a3ee5e6b4b0d3255bfef95601890afd80709] */
36 47
37 /* The structure for storing MD5 info */ 48 /* The structure for storing MD5 info */
38 49
39 struct md5_state { 50 struct md5_state {
40 MD5_INT64 length; 51 MD5_INT64 length;
41 MD5_INT32 state[4], curlen; 52 MD5_INT32 state[4], curlen;
42 unsigned char buf[MD5_BLOCKSIZE]; 53 unsigned char buf[MD5_BLOCKSIZE];
43 }; 54 };
44 55
45 typedef struct { 56 typedef struct {
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 hex_digest[j++] = Py_hexdigits[c]; 405 hex_digest[j++] = Py_hexdigits[c];
395 c = (digest[i] & 0xf); 406 c = (digest[i] & 0xf);
396 hex_digest[j++] = Py_hexdigits[c]; 407 hex_digest[j++] = Py_hexdigits[c];
397 } 408 }
398 #ifdef Py_DEBUG 409 #ifdef Py_DEBUG
399 assert(_PyUnicode_CheckConsistency(retval, 1)); 410 assert(_PyUnicode_CheckConsistency(retval, 1));
400 #endif 411 #endif
401 return retval; 412 return retval;
402 } 413 }
403 414
404 PyDoc_STRVAR(MD5_update__doc__, 415 /*[clinic input]
405 "Update this hash object's state with the provided string."); 416 _md5.MD5.update
417 self: MD5object
418 obj: object
419 /
420
421 Update this hash object's state with the provided string.
422 [clinic start generated code]*/
423
424 PyDoc_STRVAR(_md5_MD5_update__doc__,
425 "update(obj)\n"
426 "Update this hash object\'s state with the provided string.");
427
428 #define _MD5_MD5_UPDATE_METHODDEF \
429 {"update", (PyCFunction)_md5_MD5_update, METH_O, _md5_MD5_update__doc__},
406 430
407 static PyObject * 431 static PyObject *
408 MD5_update(MD5object *self, PyObject *args) 432 _md5_MD5_update(MD5object *self, PyObject *obj)
433 /*[clinic end generated code: checksum=2795c34ad0dccb2e2647c09b51c7bf7389613887] */
409 { 434 {
410 PyObject *obj;
411 Py_buffer buf; 435 Py_buffer buf;
412
413 if (!PyArg_ParseTuple(args, "O:update", &obj))
414 return NULL;
415 436
416 GET_BUFFER_VIEW_OR_ERROUT(obj, &buf); 437 GET_BUFFER_VIEW_OR_ERROUT(obj, &buf);
417 438
418 md5_process(&self->hash_state, buf.buf, buf.len); 439 md5_process(&self->hash_state, buf.buf, buf.len);
419 440
420 PyBuffer_Release(&buf); 441 PyBuffer_Release(&buf);
421 Py_INCREF(Py_None); 442 Py_INCREF(Py_None);
422 return Py_None; 443 return Py_None;
423 } 444 }
424 445
425 static PyMethodDef MD5_methods[] = { 446 static PyMethodDef MD5_methods[] = {
426 {"copy", (PyCFunction)MD5_copy, METH_NOARGS, MD5_copy__doc__}, 447 {"copy", (PyCFunction)MD5_copy, METH_NOARGS, MD5_copy__doc__},
427 {"digest", (PyCFunction)MD5_digest, METH_NOARGS, MD5_digest__doc__}, 448 {"digest", (PyCFunction)MD5_digest, METH_NOARGS, MD5_digest__doc__},
428 {"hexdigest", (PyCFunction)MD5_hexdigest, METH_NOARGS, MD5_hexdigest__doc__ }, 449 {"hexdigest", (PyCFunction)MD5_hexdigest, METH_NOARGS, MD5_hexdigest__doc__ },
429 {"update", (PyCFunction)MD5_update, METH_VARARGS, MD5_update__doc__}, 450 _MD5_MD5_UPDATE_METHODDEF
430 {NULL, NULL} /* sentinel */ 451 {NULL, NULL} /* sentinel */
431 }; 452 };
432 453
433 static PyObject * 454 static PyObject *
434 MD5_get_block_size(PyObject *self, void *closure) 455 MD5_get_block_size(PyObject *self, void *closure)
435 { 456 {
436 return PyLong_FromLong(MD5_BLOCKSIZE); 457 return PyLong_FromLong(MD5_BLOCKSIZE);
437 } 458 }
438 459
439 static PyObject * 460 static PyObject *
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 0, /*tp_iter*/ 516 0, /*tp_iter*/
496 0, /*tp_iternext*/ 517 0, /*tp_iternext*/
497 MD5_methods, /* tp_methods */ 518 MD5_methods, /* tp_methods */
498 NULL, /* tp_members */ 519 NULL, /* tp_members */
499 MD5_getseters, /* tp_getset */ 520 MD5_getseters, /* tp_getset */
500 }; 521 };
501 522
502 523
503 /* The single module-level function: new() */ 524 /* The single module-level function: new() */
504 525
505 PyDoc_STRVAR(MD5_new__doc__, 526 /*[clinic input]
527 _md5.MD5.md5
larry 2014/01/10 13:05:03 This should just be "_md5.md5". It's a function i
528
529 string: object = None
larry 2014/01/10 13:05:03 Change this to use a default of NULL.
530
531 Return a new MD5 hash object; optionally initialized with a string.
532 [clinic start generated code]*/
533
534 PyDoc_STRVAR(_md5_MD5_md5__doc__,
535 "md5(string=None)\n"
506 "Return a new MD5 hash object; optionally initialized with a string."); 536 "Return a new MD5 hash object; optionally initialized with a string.");
507 537
538 #define _MD5_MD5_MD5_METHODDEF \
539 {"md5", (PyCFunction)_md5_MD5_md5, METH_VARARGS|METH_KEYWORDS, _md5_MD5_md5_ _doc__},
540
508 static PyObject * 541 static PyObject *
509 MD5_new(PyObject *self, PyObject *args, PyObject *kwdict) 542 _md5_MD5_md5_impl(PyObject *self, PyObject *string);
543
544 static PyObject *
545 _md5_MD5_md5(PyObject *self, PyObject *args, PyObject *kwargs)
510 { 546 {
511 static char *kwlist[] = {"string", NULL}; 547 PyObject *return_value = NULL;
548 static char *_keywords[] = {"string", NULL};
549 PyObject *string = Py_None;
550
551 if (!PyArg_ParseTupleAndKeywords(args, kwargs,
552 "|O:md5", _keywords,
553 &string))
554 goto exit;
555 return_value = _md5_MD5_md5_impl(self, string);
556
557 exit:
558 return return_value;
559 }
560
561 static PyObject *
562 _md5_MD5_md5_impl(PyObject *self, PyObject *string)
563 /*[clinic end generated code: checksum=a4f98a1e8045ba48089b971b72bfe5a2d0b16c50] */
564 {
512 MD5object *new; 565 MD5object *new;
513 PyObject *data_obj = NULL;
514 Py_buffer buf; 566 Py_buffer buf;
515 567
516 if (!PyArg_ParseTupleAndKeywords(args, kwdict, "|O:new", kwlist, 568 if (string != Py_None)
larry 2014/01/10 13:05:03 Once you change string to have a default of NULL,
517 &data_obj)) { 569 GET_BUFFER_VIEW_OR_ERROUT(string, &buf);
518 return NULL;
519 }
520
521 if (data_obj)
522 GET_BUFFER_VIEW_OR_ERROUT(data_obj, &buf);
523 570
524 if ((new = newMD5object()) == NULL) { 571 if ((new = newMD5object()) == NULL) {
525 if (data_obj) 572 if (string != Py_None)
526 PyBuffer_Release(&buf); 573 PyBuffer_Release(&buf);
527 return NULL; 574 return NULL;
528 } 575 }
529 576
530 md5_init(&new->hash_state); 577 md5_init(&new->hash_state);
531 578
532 if (PyErr_Occurred()) { 579 if (PyErr_Occurred()) {
533 Py_DECREF(new); 580 Py_DECREF(new);
534 if (data_obj) 581 if (string != Py_None)
535 PyBuffer_Release(&buf); 582 PyBuffer_Release(&buf);
536 return NULL; 583 return NULL;
537 } 584 }
538 if (data_obj) { 585 if (string != Py_None) {
539 md5_process(&new->hash_state, buf.buf, buf.len); 586 md5_process(&new->hash_state, buf.buf, buf.len);
540 PyBuffer_Release(&buf); 587 PyBuffer_Release(&buf);
541 } 588 }
542 589
543 return (PyObject *)new; 590 return (PyObject *)new;
544 } 591 }
545 592
546 593
547 /* List of functions exported by this module */ 594 /* List of functions exported by this module */
548 595
549 static struct PyMethodDef MD5_functions[] = { 596 static struct PyMethodDef MD5_functions[] = {
550 {"md5", (PyCFunction)MD5_new, METH_VARARGS|METH_KEYWORDS, MD5_new__doc__}, 597 _MD5_MD5_MD5_METHODDEF
551 {NULL, NULL} /* Sentinel */ 598 {NULL, NULL} /* Sentinel */
552 }; 599 };
553 600
554 601
555 /* Initialize this module. */ 602 /* Initialize this module. */
556 603
557 #define insint(n,v) { PyModule_AddIntConstant(m,n,v); } 604 #define insint(n,v) { PyModule_AddIntConstant(m,n,v); }
558 605
559 606
560 static struct PyModuleDef _md5module = { 607 static struct PyModuleDef _md5module = {
(...skipping 18 matching lines...) Expand all
579 return NULL; 626 return NULL;
580 627
581 m = PyModule_Create(&_md5module); 628 m = PyModule_Create(&_md5module);
582 if (m == NULL) 629 if (m == NULL)
583 return NULL; 630 return NULL;
584 631
585 Py_INCREF((PyObject *)&MD5type); 632 Py_INCREF((PyObject *)&MD5type);
586 PyModule_AddObject(m, "MD5Type", (PyObject *)&MD5type); 633 PyModule_AddObject(m, "MD5Type", (PyObject *)&MD5type);
587 return m; 634 return m;
588 } 635 }
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+