base32 encoding API doesn't work for a source length that is not a multiple of 5 or 8
Assuming base32_encode()
here (but same issue goes for the decode function), it has a hard requirement of:
Limitation: Requires that srclen*8 is a multiple of 5.
Now, this has some drawbacks because srclen
is the length in bytes of what we want to encode. So assuming I want to encode 32 bytes, well I can't because 32 * 8 == 256
which is shy of 4 bits to be a multiple of 8 (260).
But how fun, since I can only pass bytes to that function, how can I tell it to use a srclen of 260 bits (32.5 bytes)? It seems to me we need a function call that takes bits instead of bytes? Or give a positive float as srclen
(sounds crazy)?
Or make base32_encode()
more smart by using floor((srclen * 8) / 5)
as the destination bytes length which will result in the right amount of bit (260 in this case). So that means, the caller must be smart and set the appropriate number of bytes + the extra bits. So to encode 32 bytes + 4 bit, the caller would have to pass a srclen of 33 and expect that 260 bit will be written and not 264.
(Setting parent ID to the proposal 224 key handling since it's a blocker to generate correctly the onion address).