You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by GitBox <gi...@apache.org> on 2021/02/05 19:57:48 UTC

[GitHub] [commons-codec] boris-github commented on a change in pull request #35: [CODEC-280] Added strict decoding property to BaseNCodec.

boris-github commented on a change in pull request #35:
URL: https://github.com/apache/commons-codec/pull/35#discussion_r571215936



##########
File path: src/main/java/org/apache/commons/codec/binary/BaseNCodec.java
##########
@@ -223,6 +230,47 @@ protected BaseNCodec(final int unencodedBlockSize, final int encodedBlockSize,
         this.pad = pad;
     }
 
+    /**
+     * Sets the decoding behaviour when the input bytes contain leftover trailing bits that
+     * cannot be created by a valid encoding. These can be bits that are unused from the final
+     * character or entire characters. The default mode is lenient decoding. Set this to
+     * {@code true} to enable strict decoding.
+     * <ul>
+     * <li>Lenient: Any trailing bits are composed into 8-bit bytes where possible.
+     *     The remainder are discarded.
+     * <li>Strict: The decoding will raise an {@link IllegalArgumentException} if trailing bits
+     *     are not part of a valid encoding. Any unused bits from the final character must
+     *     be zero. Impossible counts of entire final characters are not allowed.
+     * </ul>
+     *
+     * <p>When strict decoding is enabled it is expected that the decoded bytes will be re-encoded
+     * to a byte array that matches the original, i.e. no changes occur on the final
+     * character. This requires that the input bytes use the same padding and alphabet
+     * as the encoder.
+     *
+     * @param strictDecoding Set to true to enable strict decoding; otherwise use lenient decoding.
+     * @see #encode(byte[])
+     * @since 1.15
+     */
+    public void setStrictDecoding(boolean strictDecoding) {

Review comment:
       @aherbert looking at the [BaseNCodec](https://commons.apache.org/proper/commons-codec/archives/1.15/apidocs/org/apache/commons/codec/binary/BaseNCodec.html) Javadoc I can't find the **setStrictDecoding()** method, however **isStrictDecoding()** is available. Can you please double check?
   
   And following [your example](https://issues.apache.org/jira/browse/CODEC-280) for `codec.setStrictDecoding(true)` I'm getting a compilation error when using [commons-codec 1.15](https://search.maven.org/artifact/commons-codec/commons-codec/1.15/jar):
   ```
   symbol:   method setStrictDecoding(boolean)
   location: variable codec of type org.apache.commons.codec.binary.Base32
   ```




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org