Skip to content

Commit c7c3bf0

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

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
@@ -429,6 +429,43 @@ has_uint32_t_buffer_length(const Py_buffer *buffer)
429429

430430
// --- HMAC object ------------------------------------------------------------
431431

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

463500
static PyGetSetDef HMACObject_getsets[] = {
501+
_HMAC_HMAC_NAME_GETSETDEF
502+
_HMAC_HMAC_BLOCK_SIZE_GETSETDEF
503+
_HMAC_HMAC_DIGEST_SIZE_GETSETDEF
464504
{NULL, NULL, NULL, NULL, NULL} /* sentinel */
465505
};
466506

0 commit comments

Comments
 (0)