05nelsonm / encoding

A Kotlin Multiplatform library for configurable, streamable, efficient and extensible Encoding/Decoding with support for base16/32/64.
Apache License 2.0
33 stars 5 forks source link

`Base16` and `Base32` should be case insensitive #64

Closed 05nelsonm closed 1 year ago

05nelsonm commented 1 year ago

Currently published code does not allow for decoding of lowercase in either the Base16, or all variants of the Base32 implementation.

With the refactor to EncoderDecoder and Feeds, a configuration option was added; acceptLowercase. This is incorrect as per RFC 4648. The decoding process should be case insensitive by default and accept both upper and lower case letters.

image

image

Regarding the refactor and pointing the old extension functions to use the new EncoderDecoder implementations, anyone currently using those will be doing something like encodedData.uppercase().decodeBase16ToArray(), so modifying it to also accept lowercase should not be an issue at all in terms of decoding failures.

If someone were to downgrade the dependency to an older version (1.1.5 or lower), while still using the old extension functions, while not calling encodedData.uppercase(), it would fail to decode. So, super rare edge case.

Binary compatibility is still be preserved, but the functionality will now include automatically accepting lowercase letters.

This issue serves as documentation to point to if any issues may arise from consumers that fall into the aforementioned category of downgrading dependency versions and encountering decoding failures.

05nelsonm commented 1 year ago

In terms of fixing the issue in the new, yet unreleased version. Will need to remove the config option acceptLowercase as that will be the default henceforth. What matters in terms of case sensitivity is the encoded output, which is already configurable.