You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by ra...@apache.org on 2006/08/15 16:27:28 UTC

svn commit: r431604 - in /xml/security/trunk: CHANGELOG.txt src/org/apache/xml/security/transforms/implementations/TransformBase64Decode.java src/org/apache/xml/security/utils/Base64.java

Author: raul
Date: Tue Aug 15 07:27:28 2006
New Revision: 431604

URL: http://svn.apache.org/viewvc?rev=431604&view=rev
Log:
Optimization in Base64 to do simple transformation from String to  byte[]    

Modified:
    xml/security/trunk/CHANGELOG.txt
    xml/security/trunk/src/org/apache/xml/security/transforms/implementations/TransformBase64Decode.java
    xml/security/trunk/src/org/apache/xml/security/utils/Base64.java

Modified: xml/security/trunk/CHANGELOG.txt
URL: http://svn.apache.org/viewvc/xml/security/trunk/CHANGELOG.txt?rev=431604&r1=431603&r2=431604&view=diff
==============================================================================
--- xml/security/trunk/CHANGELOG.txt (original)
+++ xml/security/trunk/CHANGELOG.txt Tue Aug 15 07:27:28 2006
@@ -37,10 +37,11 @@
 	Added ECDSA signature thanks Markus Lindner 
 	Optimization in RetrievelMethod handling don't reparse the bytes into a DOM tree if not needed thanks David Garcia.
 	Fixed bug 40215: Base64 is not working in EBCDIC platform. Thanks to
-	acastro.dit@aeat.es for fix.
+	     acastro.dit@aeat.es for fix.
 	Big optimizations in XPath2 transformation.
 	Fixed bug 40245 in XPATH2 transformation(only in development version)
-	Fixed bug no resolver for X509Data with just a X509Certificate.	    
+	Fixed bug no resolver for X509Data with just a X509Certificate.	
+	Optimization in Base64 to do simple transformation from String to  byte[]    
 		
 New in v1.3
 	Init-Don't fail if a transformation don't have all of its dependecies.

Modified: xml/security/trunk/src/org/apache/xml/security/transforms/implementations/TransformBase64Decode.java
URL: http://svn.apache.org/viewvc/xml/security/trunk/src/org/apache/xml/security/transforms/implementations/TransformBase64Decode.java?rev=431604&r1=431603&r2=431604&view=diff
==============================================================================
--- xml/security/trunk/src/org/apache/xml/security/transforms/implementations/TransformBase64Decode.java (original)
+++ xml/security/trunk/src/org/apache/xml/security/transforms/implementations/TransformBase64Decode.java Tue Aug 15 07:27:28 2006
@@ -113,7 +113,7 @@
          	byte[] decodedBytes = Base64.decode(sb.toString());            
          	return new XMLSignatureInput(decodedBytes);
          } 
-         	Base64.decode(sb.toString().getBytes(),os);
+         	Base64.decode(sb.toString(),os);
             XMLSignatureInput output=new XMLSignatureInput((byte[])null);
             output.setOutputStream(os);
             return output;

Modified: xml/security/trunk/src/org/apache/xml/security/utils/Base64.java
URL: http://svn.apache.org/viewvc/xml/security/trunk/src/org/apache/xml/security/utils/Base64.java?rev=431604&r1=431603&r2=431604&view=diff
==============================================================================
--- xml/security/trunk/src/org/apache/xml/security/utils/Base64.java (original)
+++ xml/security/trunk/src/org/apache/xml/security/utils/Base64.java Tue Aug 15 07:27:28 2006
@@ -20,18 +20,13 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
-import java.io.StringReader;
 import java.math.BigInteger;
 
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-
 import org.apache.xml.security.exceptions.Base64DecodingException;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 import org.w3c.dom.Text;
-import org.xml.sax.InputSource;
 
 
 /**
@@ -263,7 +258,7 @@
     *
     */
    public final static byte[] decode(byte[] base64) throws Base64DecodingException  {   	   
-         return decodeInternal(base64);
+         return decodeInternal(base64, -1);
    }
 
 
@@ -485,20 +480,29 @@
      */
     public final static byte[] decode(String encoded) throws Base64DecodingException {
 
-	if (encoded == null)
-	    return null;
-
-	try {
-            return decodeInternal(encoded.getBytes("US-ASCII"));
-	} catch (java.io.UnsupportedEncodingException e) {
-	    throw new Base64DecodingException
-		("US-ASCII encoding not available on platform: " + e);
+    	if (encoded == null)
+    		return null;
+    	byte []bytes=new byte[encoded.length()];
+    	int len=getBytesInternal(encoded, bytes);
+    	return decodeInternal(bytes, len);
 	}
-    }
 
-   protected final static byte[] decodeInternal(byte[] base64Data) throws Base64DecodingException {
+    protected static final int getBytesInternal(String s,byte[] result) {
+    	int length=s.length();
+    	
+    	int newSize=0;
+    	for (int i = 0; i < length; i++) {
+            byte dataS=(byte)s.charAt(i);
+            if (!isWhiteSpace(dataS))
+                result[newSize++] = dataS;
+        }
+    	return newSize;
+    	
+    }
+   protected final static byte[] decodeInternal(byte[] base64Data, int len) throws Base64DecodingException {
        // remove white spaces
-       int len = removeWhiteSpace(base64Data);
+	   if (len==-1)
+          len = removeWhiteSpace(base64Data);
        
        if (len%FOURBYTE != 0) {
            throw new Base64DecodingException("decoding.divisible.four");
@@ -577,7 +581,20 @@
        }            
        return decodedData;
    }
-   
+   /**
+    * Decodes Base64 data into  outputstream
+    *
+    * @param base64Data String containing Base64 data
+    * @param os the outputstream
+    * @throws IOException
+    * @throws Base64DecodingException
+    */
+   public final static void decode(String base64Data,
+        OutputStream os) throws Base64DecodingException, IOException {
+	   byte[] bytes=new byte[base64Data.length()];
+	   int len=getBytesInternal(base64Data, bytes);
+	   decode(bytes,os,len);
+   }
    /**
     * Decodes Base64 data into  outputstream
     *
@@ -588,8 +605,14 @@
     */
    public final static void decode(byte[] base64Data,
         OutputStream os) throws Base64DecodingException, IOException {	    
-    // remove white spaces
-    int len = removeWhiteSpace(base64Data);
+	    decode(base64Data,os,-1);
+   }
+   protected final static void decode(byte[] base64Data,
+		        OutputStream os,int len) throws Base64DecodingException, IOException {	    
+		   
+	// remove white spaces
+    if (len==-1)
+       len = removeWhiteSpace(base64Data);
     
     if (len%FOURBYTE != 0) {
         throw new Base64DecodingException("decoding.divisible.four");