Open kstrafe opened 4 years ago
Thank you for your suggestion, this sounds like a really good idea. Unfortunately I believe this will mask the semantics of what is happening. The algorithm is encoding raw bytes into a string. That is what the reference implementation does and this is what every other implementation is doing. The 4byte alignment is just another constraint on the input value as is the 7char alignment on the input value of the decoding algorithm. It's just not encoding u32
s. It's encoding u8
s
Then it sounds like we really want &[[u8; 4]]
to be explicit. This should be zero-copy convertible from &[u8]
.
https://github.com/sphinxc0re/rust-base24/blob/d89c762cd1b07a92120a08af9770deb9a86a2fcf/src/lib.rs#L33
Since the protocol specifies no padding, it makes little sense to encode a
&[u8]
and letting the encoder fail on non-divisible-by-4 array lengths. If the user wants to encode a&[u8]
then the user could usebyteorder
or some custom code to reinterpret the slice asu32
.This will make encoding infallible.