You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2022/06/17 13:03:42 UTC

[tomcat] 02/06: Remove unused code - thanks to UCDetector

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

markt pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit fb096de761254980f779ff99057cd3b055e6459d
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Fri Jun 17 12:29:10 2022 +0100

    Remove unused code - thanks to UCDetector
---
 .../apache/tomcat/util/codec/binary/Base64.java    | 155 ---------------------
 .../tomcat/util/codec/binary/BaseNCodec.java       |  88 ------------
 2 files changed, 243 deletions(-)

diff --git a/java/org/apache/tomcat/util/codec/binary/Base64.java b/java/org/apache/tomcat/util/codec/binary/Base64.java
index 3cd4f1a558..5666e9ba3e 100644
--- a/java/org/apache/tomcat/util/codec/binary/Base64.java
+++ b/java/org/apache/tomcat/util/codec/binary/Base64.java
@@ -16,9 +16,6 @@
  */
 package org.apache.tomcat.util.codec.binary;
 
-import java.math.BigInteger;
-import java.util.Objects;
-
 /**
  * Provides Base64 encoding and decoding as defined by <a href="http://www.ietf.org/rfc/rfc2045.txt">RFC 2045</a>.
  *
@@ -138,20 +135,6 @@ public class Base64 extends BaseNCodec {
     // The private member fields below are used with the new streaming approach, which requires
     // some state be preserved between calls of encode() and decode().
 
-    /**
-     * Decodes Base64 data into octets.
-     * <p>
-     * <b>Note:</b> this method seamlessly handles data encoded in URL-safe or normal mode.
-     * </p>
-     *
-     * @param base64Data
-     *            Byte array containing Base64 data
-     * @return Array containing decoded data.
-     */
-    public static byte[] decodeBase64(final byte[] base64Data) {
-        return decodeBase64(base64Data, 0, base64Data.length);
-    }
-
     public  static byte[] decodeBase64(
             final byte[] base64Data, final int off, final int len) {
         return new Base64().decode(base64Data, off, len);
@@ -177,29 +160,6 @@ public class Base64 extends BaseNCodec {
     }
 
     // Implementation of integer encoding used for crypto
-    /**
-     * Decodes a byte64-encoded integer according to crypto standards such as W3C's XML-Signature.
-     *
-     * @param pArray
-     *            a byte array containing base64 character data
-     * @return A BigInteger
-     * @since 1.4
-     */
-    public static BigInteger decodeInteger(final byte[] pArray) {
-        return new BigInteger(1, decodeBase64(pArray));
-    }
-
-    /**
-     * Encodes binary data using the base64 algorithm but does not chunk the output.
-     *
-     * @param binaryData
-     *            binary data to encode
-     * @return byte[] containing Base64 characters in their UTF-8 representation.
-     */
-    public static byte[] encodeBase64(final byte[] binaryData) {
-        return encodeBase64(binaryData, false);
-    }
-
     /**
      * Encodes binary data using the base64 algorithm, optionally chunking the output into 76 character blocks.
      *
@@ -269,17 +229,6 @@ public class Base64 extends BaseNCodec {
         return b64.encode(binaryData);
     }
 
-    /**
-     * Encodes binary data using the base64 algorithm and chunks the encoded output into 76 character blocks
-     *
-     * @param binaryData
-     *            binary data to encode
-     * @return Base64 characters chunked in 76 character blocks
-     */
-    public static byte[] encodeBase64Chunked(final byte[] binaryData) {
-        return encodeBase64(binaryData, true);
-    }
-
     /**
      * Encodes binary data using the base64 algorithm but does not chunk the output.
      *
@@ -295,19 +244,6 @@ public class Base64 extends BaseNCodec {
         return StringUtils.newStringUsAscii(encodeBase64(binaryData, false));
     }
 
-    /**
-     * Encodes binary data using a URL-safe variation of the base64 algorithm but does not chunk the output. The
-     * url-safe variation emits - and _ instead of + and / characters.
-     * <b>Note: no padding is added.</b>
-     * @param binaryData
-     *            binary data to encode
-     * @return byte[] containing Base64 characters in their UTF-8 representation.
-     * @since 1.4
-     */
-    public static byte[] encodeBase64URLSafe(final byte[] binaryData) {
-        return encodeBase64(binaryData, false, true);
-    }
-
     /**
      * Encodes binary data using a URL-safe variation of the base64 algorithm but does not chunk the output. The
      * url-safe variation emits - and _ instead of + and / characters.
@@ -321,97 +257,6 @@ public class Base64 extends BaseNCodec {
         return StringUtils.newStringUsAscii(encodeBase64(binaryData, false, true));
     }
 
-    /**
-     * Encodes to a byte64-encoded integer according to crypto standards such as W3C's XML-Signature.
-     *
-     * @param bigInteger
-     *            a BigInteger
-     * @return A byte array containing base64 character data
-     * @throws NullPointerException
-     *             if null is passed in
-     * @since 1.4
-     */
-    public static byte[] encodeInteger(final BigInteger bigInteger) {
-        Objects.requireNonNull(bigInteger,sm.getString("base64.nullEncodeParameter"));
-        return encodeBase64(toIntegerBytes(bigInteger), false);
-    }
-
-    /**
-     * Returns whether or not the {@code octet} is in the base 64 alphabet.
-     *
-     * @param octet
-     *            The value to test
-     * @return {@code true} if the value is defined in the the base 64 alphabet, {@code false} otherwise.
-     * @since 1.4
-     */
-    public static boolean isBase64(final byte octet) {
-        return octet == PAD_DEFAULT || (octet >= 0 && octet < STANDARD_DECODE_TABLE.length && STANDARD_DECODE_TABLE[octet] != -1);
-    }
-
-    /**
-     * Tests a given byte array to see if it contains only valid characters within the Base64 alphabet. Currently the
-     * method treats whitespace as valid.
-     *
-     * @param arrayOctet
-     *            byte array to test
-     * @return {@code true} if all bytes are valid characters in the Base64 alphabet or if the byte array is empty;
-     *         {@code false}, otherwise
-     * @since 1.5
-     */
-    public static boolean isBase64(final byte[] arrayOctet) {
-        for (final byte element : arrayOctet) {
-            if (!isBase64(element) && !isWhiteSpace(element)) {
-                return false;
-            }
-        }
-        return true;
-    }
-
-    /**
-     * Tests a given String to see if it contains only valid characters within the Base64 alphabet. Currently the
-     * method treats whitespace as valid.
-     *
-     * @param base64
-     *            String to test
-     * @return {@code true} if all characters in the String are valid characters in the Base64 alphabet or if
-     *         the String is empty; {@code false}, otherwise
-     *  @since 1.5
-     */
-    public static boolean isBase64(final String base64) {
-        return isBase64(StringUtils.getBytesUtf8(base64));
-    }
-
-    /**
-     * Returns a byte-array representation of a {@code BigInteger} without sign bit.
-     *
-     * @param bigInt
-     *            {@code BigInteger} to be converted
-     * @return a byte array representation of the BigInteger parameter
-     */
-    static byte[] toIntegerBytes(final BigInteger bigInt) {
-        int bitlen = bigInt.bitLength();
-        // round bitlen
-        bitlen = ((bitlen + 7) >> 3) << 3;
-        final byte[] bigBytes = bigInt.toByteArray();
-
-        if (((bigInt.bitLength() % 8) != 0) && (((bigInt.bitLength() / 8) + 1) == (bitlen / 8))) {
-            return bigBytes;
-        }
-        // set up params for copying everything but sign bit
-        int startSrc = 0;
-        int len = bigBytes.length;
-
-        // if bigInt is exactly byte-aligned, just skip signbit in copy
-        if ((bigInt.bitLength() % 8) == 0) {
-            startSrc = 1;
-            len--;
-        }
-        final int startDst = bitlen / 8 - len; // to pad w/ nulls as per spec
-        final byte[] resizedBytes = new byte[bitlen / 8];
-        System.arraycopy(bigBytes, startSrc, resizedBytes, startDst, len);
-        return resizedBytes;
-    }
-
     /**
      * Validates whether decoding the final trailing character is possible in the context
      * of the set of possible base 64 values.
diff --git a/java/org/apache/tomcat/util/codec/binary/BaseNCodec.java b/java/org/apache/tomcat/util/codec/binary/BaseNCodec.java
index 6ca10acaae..6c1a7be4a3 100644
--- a/java/org/apache/tomcat/util/codec/binary/BaseNCodec.java
+++ b/java/org/apache/tomcat/util/codec/binary/BaseNCodec.java
@@ -114,18 +114,6 @@ public abstract class BaseNCodec {
      */
     public static final int MIME_CHUNK_SIZE = 76;
 
-    /**
-     * PEM chunk size per RFC 1421 section 4.3.2.4.
-     *
-     * <p>
-     * The {@value} character limit does not count the trailing CRLF, but counts all other characters, including any
-     * equal signs.
-     * </p>
-     *
-     * @see <a href="http://tools.ietf.org/html/rfc1421">RFC 1421 section 4.3.2.4</a>
-     */
-    public static final int PEM_CHUNK_SIZE = 64;
-
     private static final int DEFAULT_BUFFER_RESIZE_FACTOR = 2;
 
     /**
@@ -205,36 +193,6 @@ public abstract class BaseNCodec {
             MAX_BUFFER_SIZE;
     }
 
-    /**
-     * Gets a copy of the chunk separator per RFC 2045 section 2.1.
-     *
-     * @return the chunk separator
-     * @see <a href="http://www.ietf.org/rfc/rfc2045.txt">RFC 2045 section 2.1</a>
-     * @since 1.15
-     */
-    public static byte[] getChunkSeparator() {
-        return CHUNK_SEPARATOR.clone();
-    }
-
-    /**
-     * Checks if a byte value is whitespace or not.
-     * Whitespace is taken to mean: space, tab, CR, LF
-     * @param byteToCheck
-     *            the byte to check
-     * @return true if byte is whitespace, false otherwise
-     */
-    protected static boolean isWhiteSpace(final byte byteToCheck) {
-        switch (byteToCheck) {
-            case ' ' :
-            case '\n' :
-            case '\r' :
-            case '\t' :
-                return true;
-            default :
-                return false;
-        }
-    }
-
     /**
      * Increases our buffer by the {@link #DEFAULT_BUFFER_RESIZE_FACTOR}.
      * @param context the context to be used
@@ -428,24 +386,11 @@ public abstract class BaseNCodec {
      * @param pArray a byte array containing binary data
      * @return String containing only character data in the appropriate alphabet.
      * @since 1.5
-     * This is a duplicate of {@link #encodeToString(byte[])}; it was merged during refactoring.
     */
     public String encodeAsString(final byte[] pArray){
         return StringUtils.newStringUtf8(encode(pArray));
     }
 
-    /**
-     * Encodes a byte[] containing binary data, into a String containing characters in the Base-N alphabet.
-     * Uses UTF8 encoding.
-     *
-     * @param pArray
-     *            a byte array containing binary data
-     * @return A String containing only Base-N character data
-     */
-    public String encodeToString(final byte[] pArray) {
-        return StringUtils.newStringUtf8(encode(pArray));
-    }
-
     /**
      * Ensure that the buffer has room for {@code size} bytes
      *
@@ -515,39 +460,6 @@ public abstract class BaseNCodec {
      */
     protected abstract boolean isInAlphabet(byte value);
 
-    /**
-     * Tests a given byte array to see if it contains only valid characters within the alphabet.
-     * The method optionally treats whitespace and pad as valid.
-     *
-     * @param arrayOctet byte array to test
-     * @param allowWSPad if {@code true}, then whitespace and PAD are also allowed
-     *
-     * @return {@code true} if all bytes are valid characters in the alphabet or if the byte array is empty;
-     *         {@code false}, otherwise
-     */
-    public boolean isInAlphabet(final byte[] arrayOctet, final boolean allowWSPad) {
-        for (final byte octet : arrayOctet) {
-            if (!isInAlphabet(octet) &&
-                    (!allowWSPad || (octet != pad) && !isWhiteSpace(octet))) {
-                return false;
-            }
-        }
-        return true;
-    }
-
-    /**
-     * Tests a given String to see if it contains only valid characters within the alphabet.
-     * The method treats whitespace and PAD as valid.
-     *
-     * @param basen String to test
-     * @return {@code true} if all characters in the String are valid characters in the alphabet or if
-     *         the String is empty; {@code false}, otherwise
-     * @see #isInAlphabet(byte[], boolean)
-     */
-    public boolean isInAlphabet(final String basen) {
-        return isInAlphabet(StringUtils.getBytesUtf8(basen), true);
-    }
-
     /**
      * Extracts buffered data into the provided byte[] array, starting at position bPos, up to a maximum of bAvail
      * bytes. Returns how many bytes were actually extracted.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org