Skip to content

Commit 0770202

Browse files
committed
implement HMAC simple getters
- `HMAC.name` - `HMAC.block_size` - `HMAC.digest_size`
1 parent 6b77844 commit 0770202

File tree

2 files changed

+98
-1
lines changed

2 files changed

+98
-1
lines changed

Modules/clinic/hmacmodule.c.h

Lines changed: 58 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/hmacmodule.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,43 @@ has_uint32_t_buffer_length(const Py_buffer *buffer)
426426

427427
// --- HMAC object ------------------------------------------------------------
428428

429+
/*[clinic input]
430+
@getter
431+
_hmac.HMAC.name
432+
[clinic start generated code]*/
433+
434+
static PyObject *
435+
_hmac_HMAC_name_get_impl(HMACObject *self)
436+
/*[clinic end generated code: output=ae693f09778d96d9 input=41c2c5dd1cf47fbc]*/
437+
{
438+
assert(self->name != NULL);
439+
return PyUnicode_FromFormat("hmac-%U", self->name);
440+
}
441+
442+
/*[clinic input]
443+
@getter
444+
_hmac.HMAC.block_size
445+
[clinic start generated code]*/
446+
447+
static PyObject *
448+
_hmac_HMAC_block_size_get_impl(HMACObject *self)
449+
/*[clinic end generated code: output=52cb11dee4e80cae input=9dda6b8d43e995b4]*/
450+
{
451+
return PyLong_FromUInt32(self->block_size);
452+
}
453+
454+
/*[clinic input]
455+
@getter
456+
_hmac.HMAC.digest_size
457+
[clinic start generated code]*/
458+
459+
static PyObject *
460+
_hmac_HMAC_digest_size_get_impl(HMACObject *self)
461+
/*[clinic end generated code: output=22eeca1010ac6255 input=5622bb2840025b5a]*/
462+
{
463+
return PyLong_FromUInt32(self->digest_size);
464+
}
465+
429466
static int
430467
HMACObject_clear(PyObject *op)
431468
{
@@ -458,6 +495,9 @@ static PyMethodDef HMACObject_methods[] = {
458495
};
459496

460497
static PyGetSetDef HMACObject_getsets[] = {
498+
_HMAC_HMAC_NAME_GETSETDEF
499+
_HMAC_HMAC_BLOCK_SIZE_GETSETDEF
500+
_HMAC_HMAC_DIGEST_SIZE_GETSETDEF
461501
{NULL, NULL, NULL, NULL, NULL} /* sentinel */
462502
};
463503

0 commit comments

Comments
 (0)