src/share/classes/com/sun/org/apache/xml/internal/security/transforms/implementations/TransformBase64Decode.java
Print this page
*** 1,29 ****
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
! /*
! * Copyright 1999-2004 The Apache Software Foundation.
! *
! * Licensed under the Apache License, Version 2.0 (the "License");
! * you may not use this file except in compliance with the License.
! * You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
! * Unless required by applicable law or agreed to in writing, software
! * distributed under the License is distributed on an "AS IS" BASIS,
! * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
! * See the License for the specific language governing permissions and
! * limitations under the License.
! *
*/
package com.sun.org.apache.xml.internal.security.transforms.implementations;
-
-
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.OutputStream;
import javax.xml.XMLConstants;
--- 1,29 ----
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
! /**
! * Licensed to the Apache Software Foundation (ASF) under one
! * or more contributor license agreements. See the NOTICE file
! * distributed with this work for additional information
! * regarding copyright ownership. The ASF licenses this file
! * to you under the Apache License, Version 2.0 (the
! * "License"); you may not use this file except in compliance
! * with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
! * Unless required by applicable law or agreed to in writing,
! * software distributed under the License is distributed on an
! * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
! * KIND, either express or implied. See the License for the
! * specific language governing permissions and limitations
! * under the License.
*/
package com.sun.org.apache.xml.internal.security.transforms.implementations;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.OutputStream;
import javax.xml.XMLConstants;
*** 93,166 ****
* @inheritDoc
* @throws CanonicalizationException
* @throws IOException
* @throws TransformationException
*/
! protected XMLSignatureInput enginePerformTransform
! (XMLSignatureInput input, Transform _transformObject)
! throws IOException, CanonicalizationException,
! TransformationException {
! return enginePerformTransform(input, null, _transformObject);
}
! protected XMLSignatureInput enginePerformTransform(XMLSignatureInput input,
! OutputStream os, Transform _transformObject)
! throws IOException, CanonicalizationException,
! TransformationException {
try {
if (input.isElement()) {
! Node el=input.getSubNode();
! if (input.getSubNode().getNodeType()==Node.TEXT_NODE) {
! el=el.getParentNode();
! }
! StringBuffer sb=new StringBuffer();
! traverseElement((Element)el,sb);
! if (os==null) {
byte[] decodedBytes = Base64.decode(sb.toString());
return new XMLSignatureInput(decodedBytes);
}
! Base64.decode(sb.toString(),os);
! XMLSignatureInput output=new XMLSignatureInput((byte[])null);
output.setOutputStream(os);
return output;
-
}
- if (input.isOctetStream() || input.isNodeSet()) {
-
! if (os==null) {
byte[] base64Bytes = input.getBytes();
byte[] decodedBytes = Base64.decode(base64Bytes);
return new XMLSignatureInput(decodedBytes);
}
if (input.isByteArray() || input.isNodeSet()) {
! Base64.decode(input.getBytes(),os);
} else {
! Base64.decode(new BufferedInputStream(input.getOctetStreamReal())
! ,os);
}
! XMLSignatureInput output=new XMLSignatureInput((byte[])null);
output.setOutputStream(os);
return output;
-
-
}
try {
! // Exceptional case there is current not text case testing this
! // (before it was a a common case).
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
! dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING,
! Boolean.TRUE);
Document doc =
dbf.newDocumentBuilder().parse(input.getOctetStream());
Element rootNode = doc.getDocumentElement();
! StringBuffer sb = new StringBuffer();
! traverseElement(rootNode,sb);
byte[] decodedBytes = Base64.decode(sb.toString());
-
return new XMLSignatureInput(decodedBytes);
} catch (ParserConfigurationException e) {
throw new TransformationException("c14n.Canonicalizer.Exception",e);
} catch (SAXException e) {
throw new TransformationException("SAX exception", e);
--- 93,157 ----
* @inheritDoc
* @throws CanonicalizationException
* @throws IOException
* @throws TransformationException
*/
! protected XMLSignatureInput enginePerformTransform(
! XMLSignatureInput input, Transform transformObject
! ) throws IOException, CanonicalizationException, TransformationException {
! return enginePerformTransform(input, null, transformObject);
}
! protected XMLSignatureInput enginePerformTransform(
! XMLSignatureInput input, OutputStream os, Transform transformObject
! ) throws IOException, CanonicalizationException, TransformationException {
try {
if (input.isElement()) {
! Node el = input.getSubNode();
! if (input.getSubNode().getNodeType() == Node.TEXT_NODE) {
! el = el.getParentNode();
! }
! StringBuilder sb = new StringBuilder();
! traverseElement((Element)el, sb);
! if (os == null) {
byte[] decodedBytes = Base64.decode(sb.toString());
return new XMLSignatureInput(decodedBytes);
}
! Base64.decode(sb.toString(), os);
! XMLSignatureInput output = new XMLSignatureInput((byte[])null);
output.setOutputStream(os);
return output;
}
! if (input.isOctetStream() || input.isNodeSet()) {
! if (os == null) {
byte[] base64Bytes = input.getBytes();
byte[] decodedBytes = Base64.decode(base64Bytes);
return new XMLSignatureInput(decodedBytes);
}
if (input.isByteArray() || input.isNodeSet()) {
! Base64.decode(input.getBytes(), os);
} else {
! Base64.decode(new BufferedInputStream(input.getOctetStreamReal()), os);
}
! XMLSignatureInput output = new XMLSignatureInput((byte[])null);
output.setOutputStream(os);
return output;
}
try {
! //Exceptional case there is current not text case testing this(Before it was a
! //a common case).
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
! dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
Document doc =
dbf.newDocumentBuilder().parse(input.getOctetStream());
Element rootNode = doc.getDocumentElement();
! StringBuilder sb = new StringBuilder();
! traverseElement(rootNode, sb);
byte[] decodedBytes = Base64.decode(sb.toString());
return new XMLSignatureInput(decodedBytes);
} catch (ParserConfigurationException e) {
throw new TransformationException("c14n.Canonicalizer.Exception",e);
} catch (SAXException e) {
throw new TransformationException("SAX exception", e);
*** 168,186 ****
} catch (Base64DecodingException e) {
throw new TransformationException("Base64Decoding", e);
}
}
! void traverseElement(org.w3c.dom.Element node,StringBuffer sb) {
! Node sibling=node.getFirstChild();
! while (sibling!=null) {
switch (sibling.getNodeType()) {
case Node.ELEMENT_NODE:
! traverseElement((Element)sibling,sb);
break;
case Node.TEXT_NODE:
sb.append(((Text)sibling).getData());
}
! sibling=sibling.getNextSibling();
}
}
}
--- 159,177 ----
} catch (Base64DecodingException e) {
throw new TransformationException("Base64Decoding", e);
}
}
! void traverseElement(org.w3c.dom.Element node, StringBuilder sb) {
! Node sibling = node.getFirstChild();
! while (sibling != null) {
switch (sibling.getNodeType()) {
case Node.ELEMENT_NODE:
! traverseElement((Element)sibling, sb);
break;
case Node.TEXT_NODE:
sb.append(((Text)sibling).getData());
}
! sibling = sibling.getNextSibling();
}
}
}