Designing a good API is hard. Even the little choices can be difficult. Let’s take a function to decrypt AES blocks for example, this function will consume a buffer 16 bytes at a time. Here’s what such function would look like:
void decrypt(const void* input, size_t nbytes);
(There’s no output parameter, we’re just looking at the input here)
input
is a pointer to the buffer we’re working with, nbytes
is how many
bytes to read from the buffer.
The function consumes blocks of 16 bytes, so what happens when nbytes
is not a
multiple of 16? Should we silently ignore the few extra bytes? Should we have an
assert(nbytes % 16 == 0)
? Maybe we could specify how many blocks to consume?
But then the API’s user would have to remember to divide the buffer size by 16.
I don’t know what the good answer is there.