garydgregory commented on code in PR #266:
URL: https://github.com/apache/commons-codec/pull/266#discussion_r1562675703


##########
src/main/java/org/apache/commons/codec/binary/Base64.java:
##########
@@ -583,13 +598,54 @@ public Base64(final int lineLength, final byte[] 
lineSeparator, final boolean ur
      *             Thrown when the {@code lineSeparator} contains Base64 
characters.
      * @since 1.15
      */
-    public Base64(final int lineLength, final byte[] lineSeparator, final 
boolean urlSafe,
+    public Base64(final int lineLength, final byte[] lineSeparator, boolean 
urlSafe,
+                  final CodecPolicy decodingPolicy){
+        this(lineLength, lineSeparator,urlSafe ? URL_SAFE_ENCODE_TABLE : 
STANDARD_ENCODE_TABLE, decodingPolicy);
+    }
+
+    /**
+     * Creates a Base64 codec used for decoding (all modes) and encoding in 
URL-unsafe mode.
+     * <p>
+     * When encoding the line length and line separator are given in the 
constructor, and the encoding table is
+     * STANDARD_ENCODE_TABLE.
+     * </p>
+     * <p>
+     * Line lengths that aren't multiples of 4 will still essentially end up 
being multiples of 4 in the encoded data.
+     * </p>
+     * <p>
+     * When decoding all variants are supported.
+     * </p>
+     *
+     * @param lineLength
+     *            Each line of encoded data will be at most of the given 
length (rounded down to the nearest multiple of
+     *            4). 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 encodeTable
+     *            The manual encodeTable - a byte array of 64 chars.
+     * @param decodingPolicy The decoding policy.
+     * @throws IllegalArgumentException
+     *             Thrown when the {@code lineSeparator} contains Base64 
characters.
+     * @since 1.15
+     */
+    public Base64(final int lineLength, final byte[] lineSeparator, final 
byte[] encodeTable,
                   final CodecPolicy decodingPolicy) {
         super(BYTES_PER_UNENCODED_BLOCK, BYTES_PER_ENCODED_BLOCK,
                 lineLength,
                 lineSeparator == null ? 0 : lineSeparator.length,
                 PAD_DEFAULT,
                 decodingPolicy);
+        this.encodeTable = encodeTable;
+
+        if (encodeTable == STANDARD_ENCODE_TABLE || encodeTable == 
URL_SAFE_ENCODE_TABLE) {
+            decodeTable = DEFAULT_DECODE_TABLE;
+        } else {
+            if (encodeTable.length != 64) {

Review Comment:
   Use a constant for `64` instead of a magic number.



##########
src/main/java/org/apache/commons/codec/binary/Base64.java:
##########
@@ -802,6 +857,23 @@ protected boolean isInAlphabet(final byte octet) {
         return octet >= 0 && octet < decodeTable.length && decodeTable[octet] 
!= -1;
     }
 
+    /**
+     * calculates a decode table for a given encode table
+     *
+     * @param encodeTable that is used to determine decode lookup table
+     * @return decodeTable
+     */
+    private byte[] calculateDecodeTable(byte[] encodeTable) {
+        byte[] decodeTable = new byte[256];

Review Comment:
   Refactor magic number to a constant.



##########
src/main/java/org/apache/commons/codec/binary/Base64.java:
##########
@@ -802,6 +857,23 @@ protected boolean isInAlphabet(final byte octet) {
         return octet >= 0 && octet < decodeTable.length && decodeTable[octet] 
!= -1;
     }
 
+    /**
+     * calculates a decode table for a given encode table

Review Comment:
   Sentences start with a capital letter and end with a period.



##########
src/main/java/org/apache/commons/codec/binary/Base64.java:
##########
@@ -106,7 +107,7 @@ public class Base64 extends BaseNCodec {
      * https://svn.apache.org/repos/asf/webservices/commons/trunk/modules/util/
      * </p>
      */
-    private static final byte[] DECODE_TABLE = {
+    private static final byte[] DEFAULT_DECODE_TABLE = {

Review Comment:
   This does not need to be renamed.



##########
src/main/java/org/apache/commons/codec/binary/Base64.java:
##########
@@ -415,14 +416,17 @@ static byte[] toIntegerBytes(final BigInteger bigInt) {
     }
 
     /**
-     * Encode table to use: either STANDARD or URL_SAFE. Note: the 
DECODE_TABLE above remains static because it is able
+     * Encode table to use: either STANDARD or URL_SAFE or custom.
+     * Note: the DECODE_TABLE above remains static because it is able
      * to decode both STANDARD and URL_SAFE streams, but the encodeTable must 
be a member variable so we can switch
      * between the two modes.
      */
     private final byte[] encodeTable;
 
-    /** Only one decode table currently; keep for consistency with Base32 
code. */
-    private final byte[] decodeTable = DECODE_TABLE;
+    /**
+     * Decode table to use

Review Comment:
   Sentences end in a period`.`



##########
src/main/java/org/apache/commons/codec/binary/Base64.java:
##########
@@ -581,13 +596,54 @@ public Base64(final int lineLength, final byte[] 
lineSeparator, final boolean ur
      *             Thrown when the {@code lineSeparator} contains Base64 
characters.
      * @since 1.15
      */
-    public Base64(final int lineLength, final byte[] lineSeparator, final 
boolean urlSafe,
+    public Base64(final int lineLength, final byte[] lineSeparator, boolean 
urlSafe,
+                  final CodecPolicy decodingPolicy) {
+        this(lineLength, lineSeparator, urlSafe ? URL_SAFE_ENCODE_TABLE : 
STANDARD_ENCODE_TABLE, decodingPolicy);
+    }
+
+    /**
+     * Creates a Base64 codec used for decoding (all modes) and encoding in 
URL-unsafe mode.
+     * <p>
+     * When encoding the line length and line separator are given in the 
constructor, and the encoding table is
+     * STANDARD_ENCODE_TABLE.
+     * </p>
+     * <p>
+     * Line lengths that aren't multiples of 4 will still essentially end up 
being multiples of 4 in the encoded data.
+     * </p>
+     * <p>
+     * When decoding all variants are supported.
+     * </p>
+     *
+     * @param lineLength
+     *            Each line of encoded data will be at most of the given 
length (rounded down to the nearest multiple of
+     *            4). 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 encodeTable
+     *            The manual encodeTable - a byte array of 64 chars.
+     * @param decodingPolicy The decoding policy.
+     * @throws IllegalArgumentException
+     *             Thrown when the {@code lineSeparator} contains Base64 
characters.
+     * @since 1.15

Review Comment:
   Next version will be 1.17.0.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to