This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-codec.git


The following commit(s) were added to refs/heads/master by this push:
     new 9fb8ee2a Add Base32.Builder.setHexDecodeTable(boolean)
9fb8ee2a is described below

commit 9fb8ee2a07031b16c8cde31edaaea58bfd5d3739
Author: Gary D. Gregory <garydgreg...@gmail.com>
AuthorDate: Tue Jan 21 07:04:30 2025 -0500

    Add Base32.Builder.setHexDecodeTable(boolean)
    
    - Add Base32.Builder.setHexEncodeTable(boolean)
    - New public API means the next version will be 1.18.0
---
 pom.xml                                            |  6 +--
 src/changes/changes.xml                            |  4 +-
 .../org/apache/commons/codec/binary/Base32.java    | 45 +++++++++++++++++++---
 .../apache/commons/codec/binary/Base32Test.java    | 16 ++++++++
 4 files changed, 62 insertions(+), 9 deletions(-)

diff --git a/pom.xml b/pom.xml
index e58d9780..21557670 100644
--- a/pom.xml
+++ b/pom.xml
@@ -28,7 +28,7 @@ limitations under the License.
   </parent>
   <groupId>commons-codec</groupId>
   <artifactId>commons-codec</artifactId>
-  <version>1.17.3-SNAPSHOT</version>
+  <version>1.18.0-SNAPSHOT</version>
   <name>Apache Commons Codec</name>
   <inceptionYear>2002</inceptionYear>
   <description>
@@ -93,9 +93,9 @@ limitations under the License.
     
<checkstyle.header.file>${basedir}/src/conf/checkstyle-header.txt</checkstyle.header.file>
     
<checkstyle.config.file>${basedir}/src/conf/checkstyle.xml</checkstyle.config.file>
     <!-- Commons Release Plugin -->
-    <commons.release.version>1.17.2</commons.release.version>
+    <commons.release.version>1.18.0</commons.release.version>
     <commons.bc.version>1.17.1</commons.bc.version>
-    <commons.release.next>1.17.3</commons.release.next>
+    <commons.release.next>1.18.1</commons.release.next>
     <commons.rc.version>RC1</commons.rc.version>
     <commons.release.isDistModule>true</commons.release.isDistModule>
     
<commons.distSvnStagingUrl>scm:svn:https://dist.apache.org/repos/dist/dev/commons/${commons.componentid}</commons.distSvnStagingUrl>
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 993d84a8..f553b970 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -43,9 +43,11 @@ The <action> type attribute can be add,update,fix,remove.
     <author>Apache Commons Developers</author>
   </properties>
   <body>
-    <release version="1.17.3" date="YYYY-MM-DD" description="This is a feature 
and maintenance release. Java 8 or later is required.">
+    <release version="1.18.0" date="YYYY-MM-DD" description="This is a feature 
and maintenance release. Java 8 or later is required.">
       <!-- FIX -->
       <!-- ADD -->
+      <action type="add" dev="ggregory" due-to="Gary Gregory, Julian 
Reschke">Add Base32.Builder.setHexDecodeTable(boolean).</action>
+      <action type="add" dev="ggregory" due-to="Gary Gregory, Julian 
Reschke">Add Base32.Builder.setHexEncodeTable(boolean).</action>
       <!-- UPDATE -->
       <action type="update" dev="ggregory" due-to="Gary Gregory">Bump 
org.apache.commons:commons-parent from 78 to 79.</action>
     </release>
diff --git a/src/main/java/org/apache/commons/codec/binary/Base32.java 
b/src/main/java/org/apache/commons/codec/binary/Base32.java
index 9f88c2a3..81951aca 100644
--- a/src/main/java/org/apache/commons/codec/binary/Base32.java
+++ b/src/main/java/org/apache/commons/codec/binary/Base32.java
@@ -75,6 +75,33 @@ public class Base32 extends BaseNCodec {
             return new Base32(getLineLength(), getLineSeparator(), 
getEncodeTable(), getPadding(), getDecodingPolicy());
         }
 
+        /**
+         * Sets the decode table to use Base32 hexadecimal if {@code true}, 
otherwise use the Base32 alphabet.
+         * <p>
+         * This overrides a value previously set with {@link 
#setEncodeTable(byte...)}.
+         * </p>
+         *
+         * @param useHex use Base32 hexadecimal if {@code true}, otherwise use 
the Base32 alphabet.
+         * @return this instance.
+         * @since 1.18.0
+         */
+        public Builder setHexDecodeTable(final boolean useHex) {
+            return setEncodeTable(decodeTable(useHex));
+        }
+
+        /**
+         * Sets the encode table to use Base32 hexadecimal if {@code true}, 
otherwise use the Base32 alphabet.
+         * <p>
+         * This overrides a value previously set with {@link 
#setEncodeTable(byte...)}.
+         * </p>
+         *
+         * @param useHex use Base32 hexadecimal if {@code true}, otherwise use 
the Base32 alphabet.
+         * @return this instance.
+         * @since 1.18.0
+         */
+        public Builder setHexEncodeTable(final boolean useHex) {
+            return setEncodeTable(encodeTable(useHex));
+        }
     }
 
     /**
@@ -162,6 +189,10 @@ public class Base32 extends BaseNCodec {
     /** Mask used to extract 1 bits, used when decoding final trailing 
character. */
     private static final long MASK_1BITS = 0x01L;
 
+    // The static final fields above are used for the original static byte[] 
methods on Base32.
+    // The private member fields below are used with the new streaming 
approach, which requires
+    // some state be preserved between calls of encode() and decode().
+
     /**
      * Creates a new Builder.
      *
@@ -172,9 +203,13 @@ public class Base32 extends BaseNCodec {
         return new Builder();
     }
 
-    // The static final fields above are used for the original static byte[] 
methods on Base32.
-    // The private member fields below are used with the new streaming 
approach, which requires
-    // some state be preserved between calls of encode() and decode().
+    private static byte[] decodeTable(final boolean useHex) {
+        return useHex ? HEX_DECODE_TABLE : DECODE_TABLE;
+    }
+
+    private static byte[] encodeTable(final boolean useHex) {
+        return useHex ? HEX_ENCODE_TABLE : ENCODE_TABLE;
+    }
 
     /**
      * Decode table to use.
@@ -326,14 +361,14 @@ public class Base32 extends BaseNCodec {
      * @param lineLength     Each line of encoded data will be at most of the 
given length (rounded down to the nearest multiple of 8). If lineLength &lt;= 0,
      *                       then the output will not be divided into lines 
(chunks). Ignored when decoding.
      * @param lineSeparator  Each line of encoded data will end with this 
sequence of bytes.
-     * @param useHex         if {@code true}, then use Base32 Hex alphabet, 
otherwise use Base32 alphabet
+     * @param useHex         use Base32 hexadecimal if {@code true}, otherwise 
use the Base32 alphabet.
      * @param padding        padding byte.
      * @param decodingPolicy The decoding policy.
      * @throws IllegalArgumentException Thrown when the {@code lineSeparator} 
contains Base32 characters. Or the lineLength &gt; 0 and lineSeparator is null.
      * @since 1.15
      */
     public Base32(final int lineLength, final byte[] lineSeparator, final 
boolean useHex, final byte padding, final CodecPolicy decodingPolicy) {
-        this(lineLength, lineSeparator, useHex ? HEX_ENCODE_TABLE : 
ENCODE_TABLE, padding, decodingPolicy);
+        this(lineLength, lineSeparator, encodeTable(useHex), padding, 
decodingPolicy);
     }
 
     /**
diff --git a/src/test/java/org/apache/commons/codec/binary/Base32Test.java 
b/src/test/java/org/apache/commons/codec/binary/Base32Test.java
index 419b5738..16d6a0b6 100644
--- a/src/test/java/org/apache/commons/codec/binary/Base32Test.java
+++ b/src/test/java/org/apache/commons/codec/binary/Base32Test.java
@@ -292,6 +292,22 @@ public class Base32Test {
     @Test
     public void testBase32HexImpossibleSamples() {
         testImpossibleCases(new Base32(0, null, true, BaseNCodec.PAD_DEFAULT, 
CodecPolicy.STRICT), BASE32HEX_IMPOSSIBLE_CASES);
+        // @formatter:off
+        testImpossibleCases(Base32.builder()
+                .setHexEncodeTable(true)
+                .setDecodingPolicy(CodecPolicy.STRICT)
+                .get(), BASE32HEX_IMPOSSIBLE_CASES);
+        // @formatter:on
+        // overrides, last set wins
+        // @formatter:off
+        testImpossibleCases(Base32.builder()
+                .setHexDecodeTable(false)
+                .setHexDecodeTable(true)
+                .setHexEncodeTable(false)
+                .setHexEncodeTable(true)
+                .setDecodingPolicy(CodecPolicy.STRICT)
+                .get(), BASE32HEX_IMPOSSIBLE_CASES);
+        // @formatter:on
     }
 
     @Test

Reply via email to