MCPcopy Create free account
hub / github.com/ashvardanian/StringZilla / hmac_sha256

Function hmac_sha256

python/stringzilla.c:1616–1718  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1614 " TypeError: If arguments are not string-like or incorrect number provided.";
1615
1616static PyObject *hmac_sha256(PyObject *self, PyObject *const *args, Py_ssize_t positional_args_count,
1617 PyObject *args_names_tuple) {
1618 sz_unused_(self);
1619
1620 // Parse arguments
1621 PyObject *key_obj = NULL;
1622 PyObject *message_obj = NULL;
1623
1624 // Get count of keyword arguments
1625 Py_ssize_t const args_names_count = args_names_tuple ? PyTuple_Size(args_names_tuple) : 0;
1626 Py_ssize_t const total_args = positional_args_count + args_names_count;
1627
1628 // Validate total argument count
1629 if (total_args != 2) {
1630 PyErr_SetString(PyExc_TypeError, "hmac_sha256() expects exactly 2 arguments");
1631 return NULL;
1632 }
1633
1634 // Handle positional arguments
1635 if (positional_args_count >= 1) key_obj = args[0];
1636 if (positional_args_count >= 2) message_obj = args[1];
1637
1638 // Handle keyword arguments
1639 if (args_names_count > 0) {
1640 for (Py_ssize_t i = 0; i < args_names_count; ++i) {
1641 PyObject *const key = PyTuple_GetItem(args_names_tuple, i);
1642 PyObject *const value = args[positional_args_count + i];
1643
1644 if (PyUnicode_CompareWithASCIIString(key, "key") == 0) {
1645 if (key_obj) {
1646 PyErr_SetString(PyExc_TypeError, "key specified twice");
1647 return NULL;
1648 }
1649 key_obj = value;
1650 }
1651 else if (PyUnicode_CompareWithASCIIString(key, "message") == 0) {
1652 if (message_obj) {
1653 PyErr_SetString(PyExc_TypeError, "message specified twice");
1654 return NULL;
1655 }
1656 message_obj = value;
1657 }
1658 else {
1659 PyErr_Format(PyExc_TypeError, "unexpected keyword argument: %S", key);
1660 return NULL;
1661 }
1662 }
1663 }
1664
1665 // Validate all required arguments are provided
1666 if (!key_obj || !message_obj) {
1667 PyErr_SetString(PyExc_TypeError, "hmac_sha256() missing required arguments");
1668 return NULL;
1669 }
1670
1671 sz_string_view_t key, message;
1672 if (!sz_py_export_string_like(key_obj, &key.start, &key.length)) {
1673 wrap_current_exception("Key must be string-like");

Callers

nothing calls this directly

Calls 5

sz_py_export_string_likeFunction · 0.85
wrap_current_exceptionFunction · 0.85
sz_sha256_state_initFunction · 0.50
sz_sha256_state_updateFunction · 0.50
sz_sha256_state_digestFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…