Skip to content
Closed
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
Prev Previous commit
Next Next commit
open for different alphabets - encode tables private again
  • Loading branch information
cljk committed Jul 23, 2019
commit 8b29c523306cd69a924c4002cc9d7ffa735410cd
4 changes: 2 additions & 2 deletions src/main/java/org/apache/commons/codec/binary/Base64.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public class Base64 extends BaseNCodec {
* Thanks to "commons" project in ws.apache.org for this code.
* http://svn.apache.org/repos/asf/webservices/commons/trunk/modules/util/
*/
public static final byte[] STANDARD_ENCODE_TABLE = {
private static final byte[] STANDARD_ENCODE_TABLE = {
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
Expand All @@ -92,7 +92,7 @@ public class Base64 extends BaseNCodec {
* changed to - and _ to make the encoded Base64 results more URL-SAFE.
* This table is only used when the Base64's mode is set to URL-SAFE.
*/
public static final byte[] URL_SAFE_ENCODE_TABLE = {
private static final byte[] URL_SAFE_ENCODE_TABLE = {
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
Expand Down
15 changes: 10 additions & 5 deletions src/test/java/org/apache/commons/codec/binary/Base64Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,16 @@ public void testBase64() {

@Test
public void testCustomEncodingAlphabet() {
// create a duplicate of STANDARD_ENCODE_TABLE and replace two chars with
// created a duplicate of STANDARD_ENCODE_TABLE and replaced two chars with
// custom values not already present in table
byte[] encodeTable = Arrays.copyOf(Base64.STANDARD_ENCODE_TABLE, 64);
encodeTable[0] = '.';
encodeTable[1] = '-';
// A => . B => -
byte[] encodeTable = {
'.', '-', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'
};

// two instances: one with default table and one with adjusted encoding table
Base64 b64 = new Base64();
Expand All @@ -137,7 +142,7 @@ public void testCustomEncodingAlphabet() {
String encodedContentCustom = StringUtils.newStringUtf8(encodedBytesCustom);

Assert.assertTrue("testing precondition not met - ecodedContent should contain parts of modified table",
encodedContent.contains("A") || encodedContent.contains("B"));
encodedContent.contains("A") && encodedContent.contains("B"));

Assert.assertEquals("custom encoding mismatch to expected - " + encodedContentCustom,
encodedContent
Expand Down