Skip to content

[CODEC-341] Fix Base16 custom alphabet decode table#434

Open
OldTruckDriver wants to merge 1 commit into
apache:masterfrom
OldTruckDriver:fix/CODEC-341_base16_custom_alphabet_decode
Open

[CODEC-341] Fix Base16 custom alphabet decode table#434
OldTruckDriver wants to merge 1 commit into
apache:masterfrom
OldTruckDriver:fix/CODEC-341_base16_custom_alphabet_decode

Conversation

@OldTruckDriver

Copy link
Copy Markdown

JIRA: https://issues.apache.org/jira/browse/CODEC-341

Problem

Base16.Builder#setEncodeTable(...) honors a custom alphabet for encoding, but only ever pairs it with the built-in upper/lower decode table. A Base16 built with any other alphabet, therefore, cannot decode its own output.

Fix

Derive the decode table from the configured encode table (toDecodeTable), so a custom alphabet round-trips. Encode tables that are not 16 unique bytes are rejected with IllegalArgumentException.

Notes (behavior changes)

  • setEncodeTable(...) now throws IllegalArgumentException for tables that are not 16 unique bytes (previously accepted, producing undecodable output).
  • Builder#setLowerCase(true) now also sets the matching decode table; before, builder().setLowerCase(true) could not decode its own lower-case a–f output.

Tests

Added to Base16Test: custom-alphabet round-trip, rejection of duplicate and wrong-length tables, and a builder().setLowerCase(true) round-trip that fails without this change.

Verification

mvn passes locally (tests, Checkstyle, PMD, Javadoc).

Derive Base16 decode tables from custom encode tables so a configured codec can decode its own output. Reject encode tables that do not contain exactly 16 unique byte values.

Reviewed-by: OpenAI Codex
Reviewed-by: Anthropic Claude Code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant