Skip to content

Commit 577c992

Browse files
committed
Added getter for block_size and digest_size
1 parent b12be0b commit 577c992

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

main.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,33 @@ PyMethodDef whirlpool_methods[] = {
156156
};
157157

158158

159+
static PyObject *
160+
whirlpool_get_block_size(PyObject *self, void *closure)
161+
{
162+
return PyInt_FromLong(WBLOCKBYTES);
163+
}
164+
165+
static PyObject *
166+
whirlpool_get_digest_size(PyObject *self, void *closure)
167+
{
168+
return PyInt_FromLong(DIGESTBYTES);
169+
}
170+
159171
static PyObject *
160172
whirlpool_get_name(PyObject *self, void *closure)
161173
{
162174
return PyString_FromStringAndSize("WHIRLPOOL", 9);
163175
}
164176

165-
166177
static PyGetSetDef whirlpool_getseters[] = {
178+
{"digest_size",
179+
(getter)whirlpool_get_digest_size, NULL,
180+
NULL,
181+
NULL},
182+
{"block_size",
183+
(getter)whirlpool_get_block_size, NULL,
184+
NULL,
185+
NULL},
167186
{"name",
168187
(getter)whirlpool_get_name, NULL,
169188
NULL,

tests.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,20 @@ def test_update_copy(self):
7777
self.assertEqual(b2a_hex(wp3.digest()), results['tqbfjotle'])
7878
self.assertEqual(wp3.hexdigest(), results['tqbfjotle'])
7979

80+
def test_digest_size(self):
81+
wp = whirlpool.new()
82+
self.assertEqual(wp.digest_size, 64)
83+
with self.assertRaisesRegexp(AttributeError,
84+
'digest_size.*not writable'):
85+
wp.digest_size = 32
86+
87+
def test_block_size(self):
88+
wp = whirlpool.new()
89+
self.assertEqual(wp.block_size, 64)
90+
with self.assertRaisesRegexp(AttributeError,
91+
'block_size.*not writable'):
92+
wp.block_size = 32
93+
8094

8195
if __name__ == '__main__':
8296
unittest.main()

0 commit comments

Comments
 (0)