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

200f6e
From a524758e35ce71a1839bb8594e9c3af93f335f1d Mon Sep 17 00:00:00 2001
200f6e
From: Michal Srb <msrb@redhat.com>
200f6e
Date: Wed, 24 Apr 2013 11:25:52 +0200
200f6e
Subject: [PATCH] Replace bundled base64 implementation
200f6e
200f6e
---
200f6e
 pom.xml                                            |   5 +
200f6e
 .../snakeyaml/constructor/SafeConstructor.java     |   3 +-
200f6e
 .../external/biz/base64Coder/Base64Coder.java      | 305 ---------------------
200f6e
 .../snakeyaml/representer/SafeRepresenter.java     |   3 +-
200f6e
 .../source_code/base64Coder/Base64CoderTest.java   |   2 +-
200f6e
 .../snakeyaml/issues/issue99/YamlBase64Test.java   |   3 +-
200f6e
 6 files changed, 12 insertions(+), 309 deletions(-)
200f6e
 delete mode 100644 src/main/java/org/yaml/snakeyaml/external/biz/base64Coder/Base64Coder.java
200f6e
200f6e
diff --git a/pom.xml b/pom.xml
200f6e
index 013e07e..629a49c 100644
200f6e
--- a/pom.xml
200f6e
+++ b/pom.xml
200f6e
@@ -78,6 +78,11 @@
200f6e
             <version>1.6</version>
200f6e
             <scope>test</scope>
200f6e
         </dependency>
200f6e
+        <dependency>
200f6e
+            <groupId>biz.source_code</groupId>
200f6e
+            <artifactId>base64coder</artifactId>
200f6e
+            <version>2010-12-19</version>
200f6e
+        </dependency>
200f6e
     </dependencies>
200f6e
     <distributionManagement>
200f6e
         <repository>
200f6e
diff --git a/src/main/java/org/yaml/snakeyaml/constructor/SafeConstructor.java b/src/main/java/org/yaml/snakeyaml/constructor/SafeConstructor.java
200f6e
index e8f4214..651a497 100644
200f6e
--- a/src/main/java/org/yaml/snakeyaml/constructor/SafeConstructor.java
200f6e
+++ b/src/main/java/org/yaml/snakeyaml/constructor/SafeConstructor.java
200f6e
@@ -29,8 +29,9 @@ import java.util.TimeZone;
200f6e
 import java.util.regex.Matcher;
200f6e
 import java.util.regex.Pattern;
200f6e
 
200f6e
+import biz.source_code.base64Coder.Base64Coder;
200f6e
+
200f6e
 import org.yaml.snakeyaml.error.YAMLException;
200f6e
-import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder;
200f6e
 import org.yaml.snakeyaml.nodes.MappingNode;
200f6e
 import org.yaml.snakeyaml.nodes.Node;
200f6e
 import org.yaml.snakeyaml.nodes.NodeId;
200f6e
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
200f6e
deleted file mode 100644
200f6e
index 65923b6..0000000
200f6e
--- a/src/main/java/org/yaml/snakeyaml/external/biz/base64Coder/Base64Coder.java
200f6e
+++ /dev/null
200f6e
@@ -1,305 +0,0 @@
200f6e
-// Copyright 2003-2010 Christian d'Heureuse, Inventec Informatik AG, Zurich, Switzerland
200f6e
-// www.source-code.biz, www.inventec.ch/chdh
200f6e
-//
200f6e
-// This module is multi-licensed and may be used under the terms
200f6e
-// of any of the following licenses:
200f6e
-//
200f6e
-//  EPL, Eclipse Public License, V1.0 or later, http://www.eclipse.org/legal
200f6e
-//  LGPL, GNU Lesser General Public License, V2.1 or later, http://www.gnu.org/licenses/lgpl.html
200f6e
-//  GPL, GNU General Public License, V2 or later, http://www.gnu.org/licenses/gpl.html
200f6e
-//  AL, Apache License, V2.0 or later, http://www.apache.org/licenses
200f6e
-//  BSD, BSD License, http://www.opensource.org/licenses/bsd-license.php
200f6e
-//
200f6e
-// Please contact the author if you need another license.
200f6e
-// This module is provided "as is", without warranties of any kind.
200f6e
-
200f6e
-package org.yaml.snakeyaml.external.biz.base64Coder;
200f6e
-
200f6e
-/**
200f6e
- * A Base64 encoder/decoder.
200f6e
- * 
200f6e
- * 

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

200f6e
- * Project home page: 
200f6e
- * href="http://www.source-code.biz/base64coder/java/">www.
200f6e
- * source-code.biz/base64coder/java
200f6e
- * Author: Christian d'Heureuse, Inventec Informatik AG, Zurich, Switzerland
200f6e
- * Multi-licensed: EPL / LGPL / GPL / AL / BSD.
200f6e
- */
200f6e
-public class Base64Coder {
200f6e
-
200f6e
-    // The line separator string of the operating system.
200f6e
-    private static final String systemLineSeparator = System.getProperty("line.separator");
200f6e
-
200f6e
-    // Mapping table from 6-bit nibbles to Base64 characters.
200f6e
-    private static char[] map1 = new char[64];
200f6e
-    static {
200f6e
-        int i = 0;
200f6e
-        for (char c = 'A'; c <= 'Z'; c++)
200f6e
-            map1[i++] = c;
200f6e
-        for (char c = 'a'; c <= 'z'; c++)
200f6e
-            map1[i++] = c;
200f6e
-        for (char c = '0'; c <= '9'; c++)
200f6e
-            map1[i++] = c;
200f6e
-        map1[i++] = '+';
200f6e
-        map1[i++] = '/';
200f6e
-    }
200f6e
-
200f6e
-    // Mapping table from Base64 characters to 6-bit nibbles.
200f6e
-    private static byte[] map2 = new byte[128];
200f6e
-    static {
200f6e
-        for (int i = 0; i < map2.length; i++)
200f6e
-            map2[i] = -1;
200f6e
-        for (int i = 0; i < 64; i++)
200f6e
-            map2[map1[i]] = (byte) i;
200f6e
-    }
200f6e
-
200f6e
-    /**
200f6e
-     * Encodes a string into Base64 format. No blanks or line breaks are
200f6e
-     * inserted.
200f6e
-     * 
200f6e
-     * @param s
200f6e
-     *            A String to be encoded.
200f6e
-     * @return A String containing the Base64 encoded data.
200f6e
-     */
200f6e
-    public static String encodeString(String s) {
200f6e
-        return new String(encode(s.getBytes()));
200f6e
-    }
200f6e
-
200f6e
-    /**
200f6e
-     * Encodes a byte array into Base 64 format and breaks the output into lines
200f6e
-     * of 76 characters. This method is compatible with
200f6e
-     * sun.misc.BASE64Encoder.encodeBuffer(byte[]).
200f6e
-     * 
200f6e
-     * @param in
200f6e
-     *            An array containing the data bytes to be encoded.
200f6e
-     * @return A String containing the Base64 encoded data, broken into lines.
200f6e
-     */
200f6e
-    public static String encodeLines(byte[] in) {
200f6e
-        return encodeLines(in, 0, in.length, 76, systemLineSeparator);
200f6e
-    }
200f6e
-
200f6e
-    /**
200f6e
-     * Encodes a byte array into Base 64 format and breaks the output into
200f6e
-     * lines.
200f6e
-     * 
200f6e
-     * @param in
200f6e
-     *            An array containing the data bytes to be encoded.
200f6e
-     * @param iOff
200f6e
-     *            Offset of the first byte in in to be processed.
200f6e
-     * @param iLen
200f6e
-     *            Number of bytes to be processed in in, starting
200f6e
-     *            at iOff.
200f6e
-     * @param lineLen
200f6e
-     *            Line length for the output data. Should be a multiple of 4.
200f6e
-     * @param lineSeparator
200f6e
-     *            The line separator to be used to separate the output lines.
200f6e
-     * @return A String containing the Base64 encoded data, broken into lines.
200f6e
-     */
200f6e
-    public static String encodeLines(byte[] in, int iOff, int iLen, int lineLen,
200f6e
-            String lineSeparator) {
200f6e
-        int blockLen = (lineLen * 3) / 4;
200f6e
-        if (blockLen <= 0)
200f6e
-            throw new IllegalArgumentException();
200f6e
-        int lines = (iLen + blockLen - 1) / blockLen;
200f6e
-        int bufLen = ((iLen + 2) / 3) * 4 + lines * lineSeparator.length();
200f6e
-        StringBuilder buf = new StringBuilder(bufLen);
200f6e
-        int ip = 0;
200f6e
-        while (ip < iLen) {
200f6e
-            int l = Math.min(iLen - ip, blockLen);
200f6e
-            buf.append(encode(in, iOff + ip, l));
200f6e
-            buf.append(lineSeparator);
200f6e
-            ip += l;
200f6e
-        }
200f6e
-        return buf.toString();
200f6e
-    }
200f6e
-
200f6e
-    /**
200f6e
-     * Encodes a byte array into Base64 format. No blanks or line breaks are
200f6e
-     * inserted in the output.
200f6e
-     * 
200f6e
-     * @param in
200f6e
-     *            An array containing the data bytes to be encoded.
200f6e
-     * @return A character array containing the Base64 encoded data.
200f6e
-     */
200f6e
-    public static char[] encode(byte[] in) {
200f6e
-        return encode(in, 0, in.length);
200f6e
-    }
200f6e
-
200f6e
-    /**
200f6e
-     * Encodes a byte array into Base64 format. No blanks or line breaks are
200f6e
-     * inserted in the output.
200f6e
-     * 
200f6e
-     * @param in
200f6e
-     *            An array containing the data bytes to be encoded.
200f6e
-     * @param iLen
200f6e
-     *            Number of bytes to process in in.
200f6e
-     * @return A character array containing the Base64 encoded data.
200f6e
-     */
200f6e
-    public static char[] encode(byte[] in, int iLen) {
200f6e
-        return encode(in, 0, iLen);
200f6e
-    }
200f6e
-
200f6e
-    /**
200f6e
-     * Encodes a byte array into Base64 format. No blanks or line breaks are
200f6e
-     * inserted in the output.
200f6e
-     * 
200f6e
-     * @param in
200f6e
-     *            An array containing the data bytes to be encoded.
200f6e
-     * @param iOff
200f6e
-     *            Offset of the first byte in in to be processed.
200f6e
-     * @param iLen
200f6e
-     *            Number of bytes to process in in, starting at
200f6e
-     *            iOff.
200f6e
-     * @return A character array containing the Base64 encoded data.
200f6e
-     */
200f6e
-    public static char[] encode(byte[] in, int iOff, int iLen) {
200f6e
-        int oDataLen = (iLen * 4 + 2) / 3; // output length without padding
200f6e
-        int oLen = ((iLen + 2) / 3) * 4; // output length including padding
200f6e
-        char[] out = new char[oLen];
200f6e
-        int ip = iOff;
200f6e
-        int iEnd = iOff + iLen;
200f6e
-        int op = 0;
200f6e
-        while (ip < iEnd) {
200f6e
-            int i0 = in[ip++] & 0xff;
200f6e
-            int i1 = ip < iEnd ? in[ip++] & 0xff : 0;
200f6e
-            int i2 = ip < iEnd ? in[ip++] & 0xff : 0;
200f6e
-            int o0 = i0 >>> 2;
200f6e
-            int o1 = ((i0 & 3) << 4) | (i1 >>> 4);
200f6e
-            int o2 = ((i1 & 0xf) << 2) | (i2 >>> 6);
200f6e
-            int o3 = i2 & 0x3F;
200f6e
-            out[op++] = map1[o0];
200f6e
-            out[op++] = map1[o1];
200f6e
-            out[op] = op < oDataLen ? map1[o2] : '=';
200f6e
-            op++;
200f6e
-            out[op] = op < oDataLen ? map1[o3] : '=';
200f6e
-            op++;
200f6e
-        }
200f6e
-        return out;
200f6e
-    }
200f6e
-
200f6e
-    /**
200f6e
-     * Decodes a string from Base64 format. No blanks or line breaks are allowed
200f6e
-     * within the Base64 encoded input data.
200f6e
-     * 
200f6e
-     * @param s
200f6e
-     *            A Base64 String to be decoded.
200f6e
-     * @return A String containing the decoded data.
200f6e
-     * @throws IllegalArgumentException
200f6e
-     *             If the input is not valid Base64 encoded data.
200f6e
-     */
200f6e
-    public static String decodeString(String s) {
200f6e
-        return new String(decode(s));
200f6e
-    }
200f6e
-
200f6e
-    /**
200f6e
-     * Decodes a byte array from Base64 format and ignores line separators, tabs
200f6e
-     * and blanks. CR, LF, Tab and Space characters are ignored in the input
200f6e
-     * data. This method is compatible with
200f6e
-     * sun.misc.BASE64Decoder.decodeBuffer(String).
200f6e
-     * 
200f6e
-     * @param s
200f6e
-     *            A Base64 String to be decoded.
200f6e
-     * @return An array containing the decoded data bytes.
200f6e
-     * @throws IllegalArgumentException
200f6e
-     *             If the input is not valid Base64 encoded data.
200f6e
-     */
200f6e
-    public static byte[] decodeLines(String s) {
200f6e
-        char[] buf = new char[s.length()];
200f6e
-        int p = 0;
200f6e
-        for (int ip = 0; ip < s.length(); ip++) {
200f6e
-            char c = s.charAt(ip);
200f6e
-            if (c != ' ' && c != '\r' && c != '\n' && c != '\t')
200f6e
-                buf[p++] = c;
200f6e
-        }
200f6e
-        return decode(buf, 0, p);
200f6e
-    }
200f6e
-
200f6e
-    /**
200f6e
-     * Decodes a byte array from Base64 format. No blanks or line breaks are
200f6e
-     * allowed within the Base64 encoded input data.
200f6e
-     * 
200f6e
-     * @param s
200f6e
-     *            A Base64 String to be decoded.
200f6e
-     * @return An array containing the decoded data bytes.
200f6e
-     * @throws IllegalArgumentException
200f6e
-     *             If the input is not valid Base64 encoded data.
200f6e
-     */
200f6e
-    public static byte[] decode(String s) {
200f6e
-        return decode(s.toCharArray());
200f6e
-    }
200f6e
-
200f6e
-    /**
200f6e
-     * Decodes a byte array from Base64 format. No blanks or line breaks are
200f6e
-     * allowed within the Base64 encoded input data.
200f6e
-     * 
200f6e
-     * @param in
200f6e
-     *            A character array containing the Base64 encoded data.
200f6e
-     * @return An array containing the decoded data bytes.
200f6e
-     * @throws IllegalArgumentException
200f6e
-     *             If the input is not valid Base64 encoded data.
200f6e
-     */
200f6e
-    public static byte[] decode(char[] in) {
200f6e
-        return decode(in, 0, in.length);
200f6e
-    }
200f6e
-
200f6e
-    /**
200f6e
-     * Decodes a byte array from Base64 format. No blanks or line breaks are
200f6e
-     * allowed within the Base64 encoded input data.
200f6e
-     * 
200f6e
-     * @param in
200f6e
-     *            A character array containing the Base64 encoded data.
200f6e
-     * @param iOff
200f6e
-     *            Offset of the first character in in to be
200f6e
-     *            processed.
200f6e
-     * @param iLen
200f6e
-     *            Number of characters to process in in, starting
200f6e
-     *            at iOff.
200f6e
-     * @return An array containing the decoded data bytes.
200f6e
-     * @throws IllegalArgumentException
200f6e
-     *             If the input is not valid Base64 encoded data.
200f6e
-     */
200f6e
-    public static byte[] decode(char[] in, int iOff, int iLen) {
200f6e
-        if (iLen % 4 != 0)
200f6e
-            throw new IllegalArgumentException(
200f6e
-                    "Length of Base64 encoded input string is not a multiple of 4.");
200f6e
-        while (iLen > 0 && in[iOff + iLen - 1] == '=')
200f6e
-            iLen--;
200f6e
-        int oLen = (iLen * 3) / 4;
200f6e
-        byte[] out = new byte[oLen];
200f6e
-        int ip = iOff;
200f6e
-        int iEnd = iOff + iLen;
200f6e
-        int op = 0;
200f6e
-        while (ip < iEnd) {
200f6e
-            int i0 = in[ip++];
200f6e
-            int i1 = in[ip++];
200f6e
-            int i2 = ip < iEnd ? in[ip++] : 'A';
200f6e
-            int i3 = ip < iEnd ? in[ip++] : 'A';
200f6e
-            if (i0 > 127 || i1 > 127 || i2 > 127 || i3 > 127)
200f6e
-                throw new IllegalArgumentException("Illegal character in Base64 encoded data.");
200f6e
-            int b0 = map2[i0];
200f6e
-            int b1 = map2[i1];
200f6e
-            int b2 = map2[i2];
200f6e
-            int b3 = map2[i3];
200f6e
-            if (b0 < 0 || b1 < 0 || b2 < 0 || b3 < 0)
200f6e
-                throw new IllegalArgumentException("Illegal character in Base64 encoded data.");
200f6e
-            int o0 = (b0 << 2) | (b1 >>> 4);
200f6e
-            int o1 = ((b1 & 0xf) << 4) | (b2 >>> 2);
200f6e
-            int o2 = ((b2 & 3) << 6) | b3;
200f6e
-            out[op++] = (byte) o0;
200f6e
-            if (op < oLen)
200f6e
-                out[op++] = (byte) o1;
200f6e
-            if (op < oLen)
200f6e
-                out[op++] = (byte) o2;
200f6e
-        }
200f6e
-        return out;
200f6e
-    }
200f6e
-
200f6e
-    // Dummy constructor.
200f6e
-    private Base64Coder() {
200f6e
-    }
200f6e
-
200f6e
-} // end class Base64Coder
200f6e
diff --git a/src/main/java/org/yaml/snakeyaml/representer/SafeRepresenter.java b/src/main/java/org/yaml/snakeyaml/representer/SafeRepresenter.java
200f6e
index b4b618f..93b5dcd 100644
200f6e
--- a/src/main/java/org/yaml/snakeyaml/representer/SafeRepresenter.java
200f6e
+++ b/src/main/java/org/yaml/snakeyaml/representer/SafeRepresenter.java
200f6e
@@ -30,8 +30,9 @@ import java.util.Set;
200f6e
 import java.util.TimeZone;
200f6e
 import java.util.regex.Pattern;
200f6e
 
200f6e
+import biz.source_code.base64Coder.Base64Coder;
200f6e
+
200f6e
 import org.yaml.snakeyaml.error.YAMLException;
200f6e
-import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder;
200f6e
 import org.yaml.snakeyaml.nodes.Node;
200f6e
 import org.yaml.snakeyaml.nodes.Tag;
200f6e
 import org.yaml.snakeyaml.reader.StreamReader;
200f6e
diff --git a/src/test/java/biz/source_code/base64Coder/Base64CoderTest.java b/src/test/java/biz/source_code/base64Coder/Base64CoderTest.java
200f6e
index 397fb7c..002f4c7 100644
200f6e
--- a/src/test/java/biz/source_code/base64Coder/Base64CoderTest.java
200f6e
+++ b/src/test/java/biz/source_code/base64Coder/Base64CoderTest.java
200f6e
@@ -19,7 +19,7 @@ import java.io.UnsupportedEncodingException;
200f6e
 
200f6e
 import junit.framework.TestCase;
200f6e
 
200f6e
-import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder;
200f6e
+import biz.source_code.base64Coder.Base64Coder;
200f6e
 
200f6e
 public class Base64CoderTest extends TestCase {
200f6e
 
200f6e
diff --git a/src/test/java/org/yaml/snakeyaml/issues/issue99/YamlBase64Test.java b/src/test/java/org/yaml/snakeyaml/issues/issue99/YamlBase64Test.java
200f6e
index f04ffe8..9a105b9 100644
200f6e
--- a/src/test/java/org/yaml/snakeyaml/issues/issue99/YamlBase64Test.java
200f6e
+++ b/src/test/java/org/yaml/snakeyaml/issues/issue99/YamlBase64Test.java
200f6e
@@ -22,12 +22,13 @@ import java.util.Map;
200f6e
 
200f6e
 import junit.framework.TestCase;
200f6e
 
200f6e
+import biz.source_code.base64Coder.Base64Coder;
200f6e
+
200f6e
 import org.yaml.snakeyaml.Util;
200f6e
 import org.yaml.snakeyaml.Yaml;
200f6e
 import org.yaml.snakeyaml.YamlDocument;
200f6e
 import org.yaml.snakeyaml.constructor.AbstractConstruct;
200f6e
 import org.yaml.snakeyaml.constructor.Constructor;
200f6e
-import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder;
200f6e
 import org.yaml.snakeyaml.nodes.Node;
200f6e
 import org.yaml.snakeyaml.nodes.ScalarNode;
200f6e
 import org.yaml.snakeyaml.nodes.Tag;
200f6e
-- 
200f6e
1.8.1.4
200f6e