Add tests for the xxhash based hashers

This commit is contained in:
Kovid Goyal
2023-07-15 13:24:07 +05:30
parent 37d9a572ee
commit c84874ca8d
3 changed files with 35 additions and 2 deletions

View File

@@ -290,6 +290,13 @@ digest(Hasher *self, PyObject *args UNUSED) {
return ans;
}
static PyObject*
digest64(Hasher *self, PyObject *args UNUSED) {
if (self->h.digest64 == NULL) { PyErr_SetString(PyExc_TypeError, "Does not support 64-bit digests"); return NULL; }
unsigned long long a = self->h.digest64(self->h.state);
return PyLong_FromUnsignedLongLong(a);
}
static PyObject*
hexdigest(Hasher *self, PyObject *args UNUSED) {
uint8_t digest[64]; char hexdigest[128];
@@ -314,6 +321,7 @@ Hasher_name(Hasher* self, void* closure UNUSED) { return PyUnicode_FromString(se
static PyMethodDef Hasher_methods[] = {
METHODB(update, METH_O),
METHODB(digest, METH_NOARGS),
METHODB(digest64, METH_NOARGS),
METHODB(hexdigest, METH_NOARGS),
METHODB(reset, METH_NOARGS),
{NULL} /* Sentinel */