sphinxc0re / rust-base24

A simple base24 implementation in Rust
MIT License
0 stars 0 forks source link

Taking `&[u32]` instead of `&[u8]` #3

Open kstrafe opened 4 years ago

kstrafe commented 4 years ago

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 use byteorder or some custom code to reinterpret the slice as u32.

This will make encoding infallible.

sphinxc0re commented 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 u32s. It's encoding u8s

kstrafe commented 4 years ago

Then it sounds like we really want &[[u8; 4]] to be explicit. This should be zero-copy convertible from &[u8].