-static PyObject *py_hex_to_sha(PyObject *self, PyObject *py_hexsha)
-{
- char *hexsha;
- char sha[20];
- int i;
-
- if (!PyString_CheckExact(py_hexsha)) {
- PyErr_SetString(PyExc_TypeError, "hex sha is not a string");
- return NULL;
- }
-
- if (PyString_Size(py_hexsha) != 40) {
- PyErr_SetString(PyExc_ValueError, "hex sha is not 40 bytes long");
- return NULL;
- }
-
- hexsha = PyString_AsString(py_hexsha);
-
- for (i = 0; i < 20; i++) {
- sha[i] = (hexbyte(hexsha[i*2]) << 4) + hexbyte(hexsha[i*2+1]);
- }
-
- return PyString_FromStringAndSize(sha, 20);
-}
-