Fix key_macing_length() return value when nbytes is 0.
This commit is contained in:
parent
5b55528008
commit
c9680fd7c7
2 changed files with 20 additions and 1 deletions
|
@ -236,7 +236,7 @@ key_macing_length (const MifareDESFireKey key)
|
|||
size_t
|
||||
padded_data_length (const size_t nbytes, const size_t block_size)
|
||||
{
|
||||
if (nbytes % block_size)
|
||||
if ((!nbytes) || (nbytes % block_size))
|
||||
return ((nbytes / block_size) + 1) * block_size;
|
||||
else
|
||||
return nbytes;
|
||||
|
|
|
@ -71,3 +71,22 @@ test_mifare_desfire_des_send (void)
|
|||
|
||||
mifare_desfire_key_free (key);
|
||||
}
|
||||
|
||||
void
|
||||
test_mifare_desfire_padded_data_length (void)
|
||||
{
|
||||
size_t res;
|
||||
|
||||
res = padded_data_length (0, 8);
|
||||
cut_assert_equal_int (res, 8, cut_message ("Invalid size"));
|
||||
res = padded_data_length (1, 8);
|
||||
cut_assert_equal_int (res, 8, cut_message ("Invalid size"));
|
||||
res = padded_data_length (8, 8);
|
||||
cut_assert_equal_int (res, 8, cut_message ("Invalid size"));
|
||||
res = padded_data_length (9, 8);
|
||||
cut_assert_equal_int (res, 16, cut_message ("Invalid size"));
|
||||
res = padded_data_length (0, 16);
|
||||
cut_assert_equal_int (res, 16, cut_message ("Invalid size"));
|
||||
res = padded_data_length (33, 16);
|
||||
cut_assert_equal_int (res, 48, cut_message ("Invalid size"));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue