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

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, 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 /* 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
larry 2014/01/10 03:18:32 "args" is a confusing name for this parameter. Pl
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))
larry 2014/01/10 03:18:32 You need to remove lines 411 and 412. Argument Cl
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__} ,
400 {"hexdigest", (PyCFunction)SHA1_hexdigest, METH_NOARGS, SHA1_hexdigest__doc __}, 426 {"hexdigest", (PyCFunction)SHA1_hexdigest, METH_NOARGS, SHA1_hexdigest__doc __},
401 {"update", (PyCFunction)SHA1_update, METH_VARARGS, SHA1_update__doc__} , 427 _SHA1_SHA1_UPDATE_METHODDEF
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 string: object = None
larry 2014/01/10 03:18:32 It's undocumented right now (I'll fix that), but:
507
508 Return a new SHA1 hash object; optionally initialized with a string.
509 [clinic start generated code]*/
510
511 PyDoc_STRVAR(_sha1_SHA1_sha1__doc__,
512 "sha1(string=None)\n"
478 "Return a new SHA1 hash object; optionally initialized with a string."); 513 "Return a new SHA1 hash object; optionally initialized with a string.");
479 514
515 #define _SHA1_SHA1_SHA1_METHODDEF \
516 {"sha1", (PyCFunction)_sha1_SHA1_sha1, METH_VARARGS|METH_KEYWORDS, _sha1_SHA 1_sha1__doc__},
517
480 static PyObject * 518 static PyObject *
481 SHA1_new(PyObject *self, PyObject *args, PyObject *kwdict) 519 _sha1_SHA1_sha1_impl(PyObject *self, PyObject *string);
520
521 static PyObject *
522 _sha1_SHA1_sha1(PyObject *self, PyObject *args, PyObject *kwargs)
482 { 523 {
483 static char *kwlist[] = {"string", NULL}; 524 PyObject *return_value = NULL;
525 static char *_keywords[] = {"string", NULL};
526 PyObject *string = Py_None;
527
528 if (!PyArg_ParseTupleAndKeywords(args, kwargs,
529 "|O:sha1", _keywords,
530 &string))
531 goto exit;
532 return_value = _sha1_SHA1_sha1_impl(self, string);
533
534 exit:
535 return return_value;
536 }
537
538 static PyObject *
539 _sha1_SHA1_sha1_impl(PyObject *self, PyObject *string)
540 /*[clinic end generated code: checksum=855cccc92a991cc651f3907f4b2293852856033c] */
541 {
484 SHA1object *new; 542 SHA1object *new;
485 PyObject *data_obj = NULL;
486 Py_buffer buf; 543 Py_buffer buf;
487 544
488 if (!PyArg_ParseTupleAndKeywords(args, kwdict, "|O:new", kwlist, 545 if (string != Py_None)
489 &data_obj)) { 546 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 547
496 if ((new = newSHA1object()) == NULL) { 548 if ((new = newSHA1object()) == NULL) {
497 if (data_obj) 549 if (string != Py_None)
498 PyBuffer_Release(&buf); 550 PyBuffer_Release(&buf);
499 return NULL; 551 return NULL;
500 } 552 }
501 553
502 sha1_init(&new->hash_state); 554 sha1_init(&new->hash_state);
503 555
504 if (PyErr_Occurred()) { 556 if (PyErr_Occurred()) {
505 Py_DECREF(new); 557 Py_DECREF(new);
506 if (data_obj) 558 if (string != Py_None)
507 PyBuffer_Release(&buf); 559 PyBuffer_Release(&buf);
508 return NULL; 560 return NULL;
509 } 561 }
510 if (data_obj) { 562 if (string != Py_None) {
511 sha1_process(&new->hash_state, buf.buf, buf.len); 563 sha1_process(&new->hash_state, buf.buf, buf.len);
512 PyBuffer_Release(&buf); 564 PyBuffer_Release(&buf);
513 } 565 }
514 566
515 return (PyObject *)new; 567 return (PyObject *)new;
516 } 568 }
517 569
518 570
519 /* List of functions exported by this module */ 571 /* List of functions exported by this module */
520 572
521 static struct PyMethodDef SHA1_functions[] = { 573 static struct PyMethodDef SHA1_functions[] = {
522 {"sha1",(PyCFunction)SHA1_new, METH_VARARGS|METH_KEYWORDS,SHA1_new__doc__}, 574 _SHA1_SHA1_SHA1_METHODDEF
523 {NULL, NULL} /* Sentinel */ 575 {NULL, NULL} /* Sentinel */
524 }; 576 };
525 577
526 578
527 /* Initialize this module. */ 579 /* Initialize this module. */
528 580
529 #define insint(n,v) { PyModule_AddIntConstant(m,n,v); } 581 #define insint(n,v) { PyModule_AddIntConstant(m,n,v); }
530 582
531 583
532 static struct PyModuleDef _sha1module = { 584 static struct PyModuleDef _sha1module = {
(...skipping 18 matching lines...) Expand all
551 return NULL; 603 return NULL;
552 604
553 m = PyModule_Create(&_sha1module); 605 m = PyModule_Create(&_sha1module);
554 if (m == NULL) 606 if (m == NULL)
555 return NULL; 607 return NULL;
556 608
557 Py_INCREF((PyObject *)&SHA1type); 609 Py_INCREF((PyObject *)&SHA1type);
558 PyModule_AddObject(m, "SHA1Type", (PyObject *)&SHA1type); 610 PyModule_AddObject(m, "SHA1Type", (PyObject *)&SHA1type);
559 return m; 611 return m;
560 } 612 }
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+