Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[CODEC-343] Fix Base32 hex decode table builder
Configure setHexDecodeTable(boolean) with the matching encode table instead of passing a decode lookup table to setEncodeTable(byte...).

Add a regression test showing the configured codec encodes with the Base32-Hex alphabet and decodes its own output.

Reviewed-by: OpenAI Codex
Reviewed-by: Anthropic Claude Code
  • Loading branch information
OldTruckDriver committed Jun 17, 2026
commit 7dcaa2a994c374d71303bd32ae2b7693aad48008
1 change: 1 addition & 0 deletions src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ The <action> type attribute can be add,update,fix,remove.
<body>
<release version="1.22.1" date="YYYY-MM-DD" description="This is a feature and maintenance release. Java 8 or later is required.">
<!-- FIX -->
<action type="fix" issue="CODEC-343" dev="ggregory" due-to="Ruiqi Dong, Gary Gregory">Base32.Builder.setHexDecodeTable(boolean) sets the encode table to a decode lookup table.</action>
<action type="add" issue="CODEC-337" dev="pkarwasz" due-to="Ruiqi Dong, Gary Gregory">Digest ALL reuses System.in, so only the first algorithm sees the real input (#431).</action>
<!-- ADD -->
<!-- UPDATE -->
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/apache/commons/codec/binary/Base32.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public Builder setEncodeTable(final byte... encodeTable) {
}

/**
* Sets the decode table to use Base32 hexadecimal if {@code true}, otherwise use the Base32 alphabet.
* Sets the encode and decode tables to use Base32 hexadecimal if {@code true}, otherwise use the Base32 alphabet.
* <p>
* This overrides a value previously set with {@link #setEncodeTable(byte...)}.
* </p>
Expand All @@ -113,7 +113,7 @@ public Builder setEncodeTable(final byte... encodeTable) {
* @since 1.18.0
*/
public Builder setHexDecodeTable(final boolean useHex) {
return setEncodeTable(decodeTable(useHex));
return setEncodeTable(encodeTable(useHex));
}

/**
Expand Down
9 changes: 9 additions & 0 deletions src/test/java/org/apache/commons/codec/binary/Base32Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,15 @@ void testBase32HexImpossibleSamples() {
// @formatter:on
}

@Test
void testBuilderSetHexDecodeTableDecodesOwnOutput() {
final Base32 base32 = Base32.builder().setHexDecodeTable(true).setLineLength(0).get();
final byte[] data = { 0 };
final byte[] encoded = base32.encode(data);
assertEquals("00======", new String(encoded, StandardCharsets.US_ASCII));
assertArrayEquals(data, base32.decode(encoded));
}

@Test
void testBase32HexSamples() throws Exception {
final Base32 codec = new Base32(true);
Expand Down