Blame SOURCES/0001-Replace-bundled-base64-implementation.patch

409d12
From 7eb4cceb36eff9d863abe45bafa6d94c6e7e9270 Mon Sep 17 00:00:00 2001
409d12
From: Michal Srb <msrb@redhat.com>
409d12
Date: Wed, 24 Apr 2013 11:25:52 +0200
409d12
Subject: [PATCH 1/2] Replace bundled base64 implementation
409d12
409d12
---
409d12
 .../snakeyaml/constructor/SafeConstructor.java     |   2 +-
409d12
 .../external/biz/base64Coder/Base64Coder.java      | 305 ---------------------
409d12
 .../snakeyaml/representer/SafeRepresenter.java     |   2 +-
409d12
 .../source_code/base64Coder/Base64CoderTest.java   |  73 -----
409d12
 .../snakeyaml/issues/issue99/YamlBase64Test.java   |   2 +-
409d12
 5 files changed, 3 insertions(+), 381 deletions(-)
409d12
 delete mode 100644 src/main/java/org/yaml/snakeyaml/external/biz/base64Coder/Base64Coder.java
409d12
 delete mode 100644 src/test/java/biz/source_code/base64Coder/Base64CoderTest.java
409d12
409d12
diff --git a/src/main/java/org/yaml/snakeyaml/constructor/SafeConstructor.java b/src/main/java/org/yaml/snakeyaml/constructor/SafeConstructor.java
409d12
index b5572ea..190384e 100644
409d12
--- a/src/main/java/org/yaml/snakeyaml/constructor/SafeConstructor.java
409d12
+++ b/src/main/java/org/yaml/snakeyaml/constructor/SafeConstructor.java
409d12
@@ -15,6 +15,7 @@
409d12
  */
409d12
 package org.yaml.snakeyaml.constructor;
409d12
 
409d12
+import biz.source_code.base64Coder.Base64Coder;
409d12
 import java.math.BigInteger;
409d12
 import java.text.NumberFormat;
409d12
 import java.text.ParseException;
409d12
@@ -32,7 +33,6 @@ import java.util.regex.Matcher;
409d12
 import java.util.regex.Pattern;
409d12
 
409d12
 import org.yaml.snakeyaml.error.YAMLException;
409d12
-import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder;
409d12
 import org.yaml.snakeyaml.nodes.MappingNode;
409d12
 import org.yaml.snakeyaml.nodes.Node;
409d12
 import org.yaml.snakeyaml.nodes.NodeId;
409d12
diff --git a/src/main/java/org/yaml/snakeyaml/external/biz/base64Coder/Base64Coder.java b/src/main/java/org/yaml/snakeyaml/external/biz/base64Coder/Base64Coder.java
409d12
deleted file mode 100644
409d12
index 65923b6..0000000
409d12
--- a/src/main/java/org/yaml/snakeyaml/external/biz/base64Coder/Base64Coder.java
409d12
+++ /dev/null
409d12
@@ -1,305 +0,0 @@
409d12
-// Copyright 2003-2010 Christian d'Heureuse, Inventec Informatik AG, Zurich, Switzerland
409d12
-// www.source-code.biz, www.inventec.ch/chdh
409d12
-//
409d12
-// This module is multi-licensed and may be used under the terms
409d12
-// of any of the following licenses:
409d12
-//
409d12
-//  EPL, Eclipse Public License, V1.0 or later, http://www.eclipse.org/legal
409d12
-//  LGPL, GNU Lesser General Public License, V2.1 or later, http://www.gnu.org/licenses/lgpl.html
409d12
-//  GPL, GNU General Public License, V2 or later, http://www.gnu.org/licenses/gpl.html
409d12
-//  AL, Apache License, V2.0 or later, http://www.apache.org/licenses
409d12
-//  BSD, BSD License, http://www.opensource.org/licenses/bsd-license.php
409d12
-//
409d12
-// Please contact the author if you need another license.
409d12
-// This module is provided "as is", without warranties of any kind.
409d12
-
409d12
-package org.yaml.snakeyaml.external.biz.base64Coder;
409d12
-
409d12
-/**
409d12
- * A Base64 encoder/decoder.
409d12
- * 
409d12
- * 

409d12
- * This class is used to encode and decode data in Base64 format as described in
409d12
- * RFC 1521.
409d12
- * 
409d12
- * 

409d12
- * Project home page: 
409d12
- * href="http://www.source-code.biz/base64coder/java/">www.
409d12
- * source-code.biz/base64coder/java
409d12
- * Author: Christian d'Heureuse, Inventec Informatik AG, Zurich, Switzerland
409d12
- * Multi-licensed: EPL / LGPL / GPL / AL / BSD.
409d12
- */
409d12
-public class Base64Coder {
409d12
-
409d12
-    // The line separator string of the operating system.
409d12
-    private static final String systemLineSeparator = System.getProperty("line.separator");
409d12
-
409d12
-    // Mapping table from 6-bit nibbles to Base64 characters.
409d12
-    private static char[] map1 = new char[64];
409d12
-    static {
409d12
-        int i = 0;
409d12
-        for (char c = 'A'; c <= 'Z'; c++)
409d12
-            map1[i++] = c;
409d12
-        for (char c = 'a'; c <= 'z'; c++)
409d12
-            map1[i++] = c;
409d12
-        for (char c = '0'; c <= '9'; c++)
409d12
-            map1[i++] = c;
409d12
-        map1[i++] = '+';
409d12
-        map1[i++] = '/';
409d12
-    }
409d12
-
409d12
-    // Mapping table from Base64 characters to 6-bit nibbles.
409d12
-    private static byte[] map2 = new byte[128];
409d12
-    static {
409d12
-        for (int i = 0; i < map2.length; i++)
409d12
-            map2[i] = -1;
409d12
-        for (int i = 0; i < 64; i++)
409d12
-            map2[map1[i]] = (byte) i;
409d12
-    }
409d12
-
409d12
-    /**
409d12
-     * Encodes a string into Base64 format. No blanks or line breaks are
409d12
-     * inserted.
409d12
-     * 
409d12
-     * @param s
409d12
-     *            A String to be encoded.
409d12
-     * @return A String containing the Base64 encoded data.
409d12
-     */
409d12
-    public static String encodeString(String s) {
409d12
-        return new String(encode(s.getBytes()));
409d12
-    }
409d12
-
409d12
-    /**
409d12
-     * Encodes a byte array into Base 64 format and breaks the output into lines
409d12
-     * of 76 characters. This method is compatible with
409d12
-     * sun.misc.BASE64Encoder.encodeBuffer(byte[]).
409d12
-     * 
409d12
-     * @param in
409d12
-     *            An array containing the data bytes to be encoded.
409d12
-     * @return A String containing the Base64 encoded data, broken into lines.
409d12
-     */
409d12
-    public static String encodeLines(byte[] in) {
409d12
-        return encodeLines(in, 0, in.length, 76, systemLineSeparator);
409d12
-    }
409d12
-
409d12
-    /**
409d12
-     * Encodes a byte array into Base 64 format and breaks the output into
409d12
-     * lines.
409d12
-     * 
409d12
-     * @param in
409d12
-     *            An array containing the data bytes to be encoded.
409d12
-     * @param iOff
409d12
-     *            Offset of the first byte in in to be processed.
409d12
-     * @param iLen
409d12
-     *            Number of bytes to be processed in in, starting
409d12
-     *            at iOff.
409d12
-     * @param lineLen
409d12
-     *            Line length for the output data. Should be a multiple of 4.
409d12
-     * @param lineSeparator
409d12
-     *            The line separator to be used to separate the output lines.
409d12
-     * @return A String containing the Base64 encoded data, broken into lines.
409d12
-     */
409d12
-    public static String encodeLines(byte[] in, int iOff, int iLen, int lineLen,
409d12
-            String lineSeparator) {
409d12
-        int blockLen = (lineLen * 3) / 4;
409d12
-        if (blockLen <= 0)
409d12
-            throw new IllegalArgumentException();
409d12
-        int lines = (iLen + blockLen - 1) / blockLen;
409d12
-        int bufLen = ((iLen + 2) / 3) * 4 + lines * lineSeparator.length();
409d12
-        StringBuilder buf = new StringBuilder(bufLen);
409d12
-        int ip = 0;
409d12
-        while (ip < iLen) {
409d12
-            int l = Math.min(iLen - ip, blockLen);
409d12
-            buf.append(encode(in, iOff + ip, l));
409d12
-            buf.append(lineSeparator);
409d12
-            ip += l;
409d12
-        }
409d12
-        return buf.toString();
409d12
-    }
409d12
-
409d12
-    /**
409d12
-     * Encodes a byte array into Base64 format. No blanks or line breaks are
409d12
-     * inserted in the output.
409d12
-     * 
409d12
-     * @param in
409d12
-     *            An array containing the data bytes to be encoded.
409d12
-     * @return A character array containing the Base64 encoded data.
409d12
-     */
409d12
-    public static char[] encode(byte[] in) {
409d12
-        return encode(in, 0, in.length);
409d12
-    }
409d12
-
409d12
-    /**
409d12
-     * Encodes a byte array into Base64 format. No blanks or line breaks are
409d12
-     * inserted in the output.
409d12
-     * 
409d12
-     * @param in
409d12
-     *            An array containing the data bytes to be encoded.
409d12
-     * @param iLen
409d12
-     *            Number of bytes to process in in.
409d12
-     * @return A character array containing the Base64 encoded data.
409d12
-     */
409d12
-    public static char[] encode(byte[] in, int iLen) {
409d12
-        return encode(in, 0, iLen);
409d12
-    }
409d12
-
409d12
-    /**
409d12
-     * Encodes a byte array into Base64 format. No blanks or line breaks are
409d12
-     * inserted in the output.
409d12
-     * 
409d12
-     * @param in
409d12
-     *            An array containing the data bytes to be encoded.
409d12
-     * @param iOff
409d12
-     *            Offset of the first byte in in to be processed.
409d12
-     * @param iLen
409d12
-     *            Number of bytes to process in in, starting at
409d12
-     *            iOff.
409d12
-     * @return A character array containing the Base64 encoded data.
409d12
-     */
409d12
-    public static char[] encode(byte[] in, int iOff, int iLen) {
409d12
-        int oDataLen = (iLen * 4 + 2) / 3; // output length without padding
409d12
-        int oLen = ((iLen + 2) / 3) * 4; // output length including padding
409d12
-        char[] out = new char[oLen];
409d12
-        int ip = iOff;
409d12
-        int iEnd = iOff + iLen;
409d12
-        int op = 0;
409d12
-        while (ip < iEnd) {
409d12
-            int i0 = in[ip++] & 0xff;
409d12
-            int i1 = ip < iEnd ? in[ip++] & 0xff : 0;
409d12
-            int i2 = ip < iEnd ? in[ip++] & 0xff : 0;
409d12
-            int o0 = i0 >>> 2;
409d12
-            int o1 = ((i0 & 3) << 4) | (i1 >>> 4);
409d12
-            int o2 = ((i1 & 0xf) << 2) | (i2 >>> 6);
409d12
-            int o3 = i2 & 0x3F;
409d12
-            out[op++] = map1[o0];
409d12
-            out[op++] = map1[o1];
409d12
-            out[op] = op < oDataLen ? map1[o2] : '=';
409d12
-            op++;
409d12
-            out[op] = op < oDataLen ? map1[o3] : '=';
409d12
-            op++;
409d12
-        }
409d12
-        return out;
409d12
-    }
409d12
-
409d12
-    /**
409d12
-     * Decodes a string from Base64 format. No blanks or line breaks are allowed
409d12
-     * within the Base64 encoded input data.
409d12
-     * 
409d12
-     * @param s
409d12
-     *            A Base64 String to be decoded.
409d12
-     * @return A String containing the decoded data.
409d12
-     * @throws IllegalArgumentException
409d12
-     *             If the input is not valid Base64 encoded data.
409d12
-     */
409d12
-    public static String decodeString(String s) {
409d12
-        return new String(decode(s));
409d12
-    }
409d12
-
409d12
-    /**
409d12
-     * Decodes a byte array from Base64 format and ignores line separators, tabs
409d12
-     * and blanks. CR, LF, Tab and Space characters are ignored in the input
409d12
-     * data. This method is compatible with
409d12
-     * sun.misc.BASE64Decoder.decodeBuffer(String).
409d12
-     * 
409d12
-     * @param s
409d12
-     *            A Base64 String to be decoded.
409d12
-     * @return An array containing the decoded data bytes.
409d12
-     * @throws IllegalArgumentException
409d12
-     *             If the input is not valid Base64 encoded data.
409d12
-     */
409d12
-    public static byte[] decodeLines(String s) {
409d12
-        char[] buf = new char[s.length()];
409d12
-        int p = 0;
409d12
-        for (int ip = 0; ip < s.length(); ip++) {
409d12
-            char c = s.charAt(ip);
409d12
-            if (c != ' ' && c != '\r' && c != '\n' && c != '\t')
409d12
-                buf[p++] = c;
409d12
-        }
409d12
-        return decode(buf, 0, p);
409d12
-    }
409d12
-
409d12
-    /**
409d12
-     * Decodes a byte array from Base64 format. No blanks or line breaks are
409d12
-     * allowed within the Base64 encoded input data.
409d12
-     * 
409d12
-     * @param s
409d12
-     *            A Base64 String to be decoded.
409d12
-     * @return An array containing the decoded data bytes.
409d12
-     * @throws IllegalArgumentException
409d12
-     *             If the input is not valid Base64 encoded data.
409d12
-     */
409d12
-    public static byte[] decode(String s) {
409d12
-        return decode(s.toCharArray());
409d12
-    }
409d12
-
409d12
-    /**
409d12
-     * Decodes a byte array from Base64 format. No blanks or line breaks are
409d12
-     * allowed within the Base64 encoded input data.
409d12
-     * 
409d12
-     * @param in
409d12
-     *            A character array containing the Base64 encoded data.
409d12
-     * @return An array containing the decoded data bytes.
409d12
-     * @throws IllegalArgumentException
409d12
-     *             If the input is not valid Base64 encoded data.
409d12
-     */
409d12
-    public static byte[] decode(char[] in) {
409d12
-        return decode(in, 0, in.length);
409d12
-    }
409d12
-
409d12
-    /**
409d12
-     * Decodes a byte array from Base64 format. No blanks or line breaks are
409d12
-     * allowed within the Base64 encoded input data.
409d12
-     * 
409d12
-     * @param in
409d12
-     *            A character array containing the Base64 encoded data.
409d12
-     * @param iOff
409d12
-     *            Offset of the first character in in to be
409d12
-     *            processed.
409d12
-     * @param iLen
409d12
-     *            Number of characters to process in in, starting
409d12
-     *            at iOff.
409d12
-     * @return An array containing the decoded data bytes.
409d12
-     * @throws IllegalArgumentException
409d12
-     *             If the input is not valid Base64 encoded data.
409d12
-     */
409d12
-    public static byte[] decode(char[] in, int iOff, int iLen) {
409d12
-        if (iLen % 4 != 0)
409d12
-            throw new IllegalArgumentException(
409d12
-                    "Length of Base64 encoded input string is not a multiple of 4.");
409d12
-        while (iLen > 0 && in[iOff + iLen - 1] == '=')
409d12
-            iLen--;
409d12
-        int oLen = (iLen * 3) / 4;
409d12
-        byte[] out = new byte[oLen];
409d12
-        int ip = iOff;
409d12
-        int iEnd = iOff + iLen;
409d12
-        int op = 0;
409d12
-        while (ip < iEnd) {
409d12
-            int i0 = in[ip++];
409d12
-            int i1 = in[ip++];
409d12
-            int i2 = ip < iEnd ? in[ip++] : 'A';
409d12
-            int i3 = ip < iEnd ? in[ip++] : 'A';
409d12
-            if (i0 > 127 || i1 > 127 || i2 > 127 || i3 > 127)
409d12
-                throw new IllegalArgumentException("Illegal character in Base64 encoded data.");
409d12
-            int b0 = map2[i0];
409d12
-            int b1 = map2[i1];
409d12
-            int b2 = map2[i2];
409d12
-            int b3 = map2[i3];
409d12
-            if (b0 < 0 || b1 < 0 || b2 < 0 || b3 < 0)
409d12
-                throw new IllegalArgumentException("Illegal character in Base64 encoded data.");
409d12
-            int o0 = (b0 << 2) | (b1 >>> 4);
409d12
-            int o1 = ((b1 & 0xf) << 4) | (b2 >>> 2);
409d12
-            int o2 = ((b2 & 3) << 6) | b3;
409d12
-            out[op++] = (byte) o0;
409d12
-            if (op < oLen)
409d12
-                out[op++] = (byte) o1;
409d12
-            if (op < oLen)
409d12
-                out[op++] = (byte) o2;
409d12
-        }
409d12
-        return out;
409d12
-    }
409d12
-
409d12
-    // Dummy constructor.
409d12
-    private Base64Coder() {
409d12
-    }
409d12
-
409d12
-} // end class Base64Coder
409d12
diff --git a/src/main/java/org/yaml/snakeyaml/representer/SafeRepresenter.java b/src/main/java/org/yaml/snakeyaml/representer/SafeRepresenter.java
409d12
index 147e3af..b8dd4e0 100644
409d12
--- a/src/main/java/org/yaml/snakeyaml/representer/SafeRepresenter.java
409d12
+++ b/src/main/java/org/yaml/snakeyaml/representer/SafeRepresenter.java
409d12
@@ -15,6 +15,7 @@
409d12
  */
409d12
 package org.yaml.snakeyaml.representer;
409d12
 
409d12
+import biz.source_code.base64Coder.Base64Coder;
409d12
 import java.io.UnsupportedEncodingException;
409d12
 import java.math.BigInteger;
409d12
 import java.util.ArrayList;
409d12
@@ -32,7 +33,6 @@ import java.util.UUID;
409d12
 import java.util.regex.Pattern;
409d12
 
409d12
 import org.yaml.snakeyaml.error.YAMLException;
409d12
-import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder;
409d12
 import org.yaml.snakeyaml.nodes.Node;
409d12
 import org.yaml.snakeyaml.nodes.Tag;
409d12
 import org.yaml.snakeyaml.reader.StreamReader;
409d12
diff --git a/src/test/java/biz/source_code/base64Coder/Base64CoderTest.java b/src/test/java/biz/source_code/base64Coder/Base64CoderTest.java
409d12
deleted file mode 100644
409d12
index 60f6d84..0000000
409d12
--- a/src/test/java/biz/source_code/base64Coder/Base64CoderTest.java
409d12
+++ /dev/null
409d12
@@ -1,73 +0,0 @@
409d12
-/**
409d12
- * Copyright (c) 2008, http://www.snakeyaml.org
409d12
- *
409d12
- * Licensed under the Apache License, Version 2.0 (the "License");
409d12
- * you may not use this file except in compliance with the License.
409d12
- * You may obtain a copy of the License at
409d12
- *
409d12
- *     http://www.apache.org/licenses/LICENSE-2.0
409d12
- *
409d12
- * Unless required by applicable law or agreed to in writing, software
409d12
- * distributed under the License is distributed on an "AS IS" BASIS,
409d12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
409d12
- * See the License for the specific language governing permissions and
409d12
- * limitations under the License.
409d12
- */
409d12
-package biz.source_code.base64Coder;
409d12
-
409d12
-import java.io.UnsupportedEncodingException;
409d12
-
409d12
-import junit.framework.TestCase;
409d12
-
409d12
-import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder;
409d12
-
409d12
-public class Base64CoderTest extends TestCase {
409d12
-
409d12
-    public void testDecode() throws UnsupportedEncodingException {
409d12
-        check("Aladdin:open sesame", "QWxhZGRpbjpvcGVuIHNlc2FtZQ==");
409d12
-        check("a", "YQ==");
409d12
-        check("aa", "YWE=");
409d12
-        check("a=", "YT0=");
409d12
-        check("", "");
409d12
-    }
409d12
-
409d12
-    public void testFailure1() throws UnsupportedEncodingException {
409d12
-        try {
409d12
-            Base64Coder.decode("YQ=".toCharArray());
409d12
-            fail();
409d12
-        } catch (Exception e) {
409d12
-            assertEquals("Length of Base64 encoded input string is not a multiple of 4.",
409d12
-                    e.getMessage());
409d12
-        }
409d12
-    }
409d12
-
409d12
-    public void testFailure2() throws UnsupportedEncodingException {
409d12
-        checkInvalid("\tWE=");
409d12
-        checkInvalid("Y\tE=");
409d12
-        checkInvalid("YW\t=");
409d12
-        checkInvalid("YWE\t");
409d12
-        //
409d12
-        checkInvalid("©WE=");
409d12
-        checkInvalid("Y©E=");
409d12
-        checkInvalid("YW©=");
409d12
-        checkInvalid("YWE©");
409d12
-    }
409d12
-
409d12
-    private void checkInvalid(String encoded) {
409d12
-        try {
409d12
-            Base64Coder.decode(encoded.toCharArray());
409d12
-            fail("Illegal chanracter.");
409d12
-        } catch (Exception e) {
409d12
-            assertEquals("Illegal character in Base64 encoded data.", e.getMessage());
409d12
-        }
409d12
-    }
409d12
-
409d12
-    private void check(String text, String encoded) throws UnsupportedEncodingException {
409d12
-        char[] s1 = Base64Coder.encode(text.getBytes("UTF-8"));
409d12
-        String t1 = new String(s1);
409d12
-        assertEquals(encoded, t1);
409d12
-        byte[] s2 = Base64Coder.decode(encoded.toCharArray());
409d12
-        String t2 = new String(s2, "UTF-8");
409d12
-        assertEquals(text, t2);
409d12
-    }
409d12
-}
409d12
diff --git a/src/test/java/org/yaml/snakeyaml/issues/issue99/YamlBase64Test.java b/src/test/java/org/yaml/snakeyaml/issues/issue99/YamlBase64Test.java
409d12
index 32e7eef..3275c7e 100644
409d12
--- a/src/test/java/org/yaml/snakeyaml/issues/issue99/YamlBase64Test.java
409d12
+++ b/src/test/java/org/yaml/snakeyaml/issues/issue99/YamlBase64Test.java
409d12
@@ -15,6 +15,7 @@
409d12
  */
409d12
 package org.yaml.snakeyaml.issues.issue99;
409d12
 
409d12
+import biz.source_code.base64Coder.Base64Coder;
409d12
 import java.io.BufferedInputStream;
409d12
 import java.io.IOException;
409d12
 import java.io.InputStream;
409d12
@@ -27,7 +28,6 @@ import org.yaml.snakeyaml.Yaml;
409d12
 import org.yaml.snakeyaml.YamlDocument;
409d12
 import org.yaml.snakeyaml.constructor.AbstractConstruct;
409d12
 import org.yaml.snakeyaml.constructor.Constructor;
409d12
-import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder;
409d12
 import org.yaml.snakeyaml.nodes.Node;
409d12
 import org.yaml.snakeyaml.nodes.ScalarNode;
409d12
 import org.yaml.snakeyaml.nodes.Tag;
409d12
-- 
409d12
2.7.4
409d12