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 2004/09/20 23:36:28 UTC
cvs commit: xml-security/src/org/apache/xml/security/transforms/implementations TransformC14NWithComments.java TransformEnvelopedSignature.java TransformBase64Decode.java TransformC14N.java
raul 2004/09/20 14:36:28
Modified: src/org/apache/xml/security/transforms/implementations
TransformC14NWithComments.java
TransformEnvelopedSignature.java
TransformBase64Decode.java TransformC14N.java
Log:
Code clean-up & minor speed-ups.
Revision Changes Path
1.9 +4 -1 xml-security/src/org/apache/xml/security/transforms/implementations/TransformC14NWithComments.java
Index: TransformC14NWithComments.java
===================================================================
RCS file: /home/cvs/xml-security/src/org/apache/xml/security/transforms/implementations/TransformC14NWithComments.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- TransformC14NWithComments.java 18 Sep 2004 16:45:53 -0000 1.8
+++ TransformC14NWithComments.java 20 Sep 2004 21:36:28 -0000 1.9
@@ -19,6 +19,7 @@
import java.io.IOException;
+import java.util.Set;
import javax.xml.parsers.ParserConfigurationException;
@@ -28,6 +29,7 @@
import org.apache.xml.security.signature.XMLSignatureInput;
import org.apache.xml.security.transforms.TransformSpi;
import org.apache.xml.security.transforms.Transforms;
+import org.apache.xml.security.utils.XMLUtils;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;
@@ -87,7 +89,8 @@
Node excl=input.getExcludeNode();
result=c14n.engineCanonicalizeSubTree(input.getSubNode(),excl);
} else {
- result = c14n.engineCanonicalizeXPathNodeSet(input.getNodeSet());
+ Set set=input.getNodeSet(true);
+ result = c14n.engineCanonicalizeXPathNodeSet(set);
}
}
return new XMLSignatureInput(result);
1.12 +0 -7 xml-security/src/org/apache/xml/security/transforms/implementations/TransformEnvelopedSignature.java
Index: TransformEnvelopedSignature.java
===================================================================
RCS file: /home/cvs/xml-security/src/org/apache/xml/security/transforms/implementations/TransformEnvelopedSignature.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- TransformEnvelopedSignature.java 3 Aug 2004 18:01:20 -0000 1.11
+++ TransformEnvelopedSignature.java 20 Sep 2004 21:36:28 -0000 1.12
@@ -118,13 +118,6 @@
throw new TransformationException("generic.EmptyMessage", exArgs);
}
- Document transformDoc = transformElement.getOwnerDocument();
- Document inputDoc = XMLUtils.getOwnerDocument((Node) inputSet.iterator().next());
-
- if (transformDoc != inputDoc) {
- throw new TransformationException("xpath.funcHere.documentsDiffer");
- }
-
Set resultSet=XMLUtils.excludeNodeFromSet(signatureElement, inputSet);
1.16 +26 -60 xml-security/src/org/apache/xml/security/transforms/implementations/TransformBase64Decode.java
Index: TransformBase64Decode.java
===================================================================
RCS file: /home/cvs/xml-security/src/org/apache/xml/security/transforms/implementations/TransformBase64Decode.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- TransformBase64Decode.java 3 Aug 2004 18:01:20 -0000 1.15
+++ TransformBase64Decode.java 20 Sep 2004 21:36:28 -0000 1.16
@@ -19,10 +19,7 @@
-import java.io.ByteArrayInputStream;
import java.io.IOException;
-import java.util.Iterator;
-import java.util.Set;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
@@ -98,6 +95,7 @@
* Method enginePerformTransform
*
* @param input
+ * @return
* @inheritDoc
* @throws CanonicalizationException
* @throws IOException
@@ -109,54 +107,43 @@
TransformationException, InvalidCanonicalizerException {
try {
- if (input.isOctetStream() || isTextNodeSet(input.getNodeSet())) {
- try {
- byte[] base64Bytes = input.getBytes();
- byte[] decodedBytes = Base64.decode(base64Bytes);
-
- return new XMLSignatureInput(
- new ByteArrayInputStream(decodedBytes));
- } catch (Base64DecodingException ex) {
- throw new TransformationException("empty", ex);
+ 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);
+ byte[] decodedBytes = Base64.decode(sb.toString());
+ return new XMLSignatureInput(decodedBytes);
+ }
+ if (input.isOctetStream() ) {
+ byte[] base64Bytes = input.getBytes();
+ byte[] decodedBytes = Base64.decode(base64Bytes);
+ return new XMLSignatureInput(decodedBytes);
}
- try {
+
+ try {
+ //Exceptional case there is current not text case testing this(Before it was a
+ //a common case).
Document doc =
DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(
input.getOctetStream());
- //DocumentTraversal dt = ((DocumentTraversal) doc);
+
Element rootNode = doc.getDocumentElement();
StringBuffer sb = new StringBuffer();
traverseElement(rootNode,sb);
- // we accept all nodes
- /*
- NodeFilter nodefilter = new AlwaysAcceptNodeFilter();
- TreeWalker treewalker = dt.createTreeWalker(rootNode,
- NodeFilter.SHOW_ALL,
- nodefilter, true);
- StringBuffer sb = new StringBuffer();
-
- process(treewalker, sb);
- */
byte[] decodedBytes = Base64.decode(sb.toString());
- return new XMLSignatureInput(
- new ByteArrayInputStream(decodedBytes));
+ return new XMLSignatureInput(decodedBytes);
} catch (ParserConfigurationException e) {
- throw new TransformationException("c14n.Canonicalizer.Exception",
- e);
+ throw new TransformationException("c14n.Canonicalizer.Exception",e);
} catch (SAXException e) {
throw new TransformationException("SAX exception", e);
- } catch (Base64DecodingException ex) {
- throw new TransformationException("empty", ex);
- }
-
- } catch (ParserConfigurationException e) {
- throw new TransformationException("c14n.Canonicalizer.Exception",
- e);
- } catch (SAXException e) {
- throw new TransformationException("SAX exception", e);
- }
+ }
+ } catch (Base64DecodingException e) {
+ throw new TransformationException("Base64Decoding", e);
+ }
}
void traverseElement(org.w3c.dom.Element node,StringBuffer sb) {
@@ -171,26 +158,5 @@
}
sibling=sibling.getNextSibling();
}
- }
-
- /**
- * Method to take a set of nodes and check whether any are "non-text"
- * @param s to search
- * @return true if the set only contains text nodes.
- */
- private boolean isTextNodeSet(Set s) {
-
- boolean isText = true;
-
- Iterator it = s.iterator();
- while (it.hasNext() && isText) {
-
- Node n = (Node) it.next();
- if (n.getNodeType() != Node.TEXT_NODE)
- isText = false;
- }
-
- return isText;
- }
-
+ }
}
1.10 +4 -1 xml-security/src/org/apache/xml/security/transforms/implementations/TransformC14N.java
Index: TransformC14N.java
===================================================================
RCS file: /home/cvs/xml-security/src/org/apache/xml/security/transforms/implementations/TransformC14N.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- TransformC14N.java 18 Sep 2004 16:45:53 -0000 1.9
+++ TransformC14N.java 20 Sep 2004 21:36:28 -0000 1.10
@@ -19,6 +19,7 @@
import java.io.IOException;
+import java.util.Set;
import javax.xml.parsers.ParserConfigurationException;
@@ -28,6 +29,7 @@
import org.apache.xml.security.signature.XMLSignatureInput;
import org.apache.xml.security.transforms.TransformSpi;
import org.apache.xml.security.transforms.Transforms;
+import org.apache.xml.security.utils.XMLUtils;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;
@@ -86,7 +88,8 @@
Node excl=input.getExcludeNode();
result=c14n.engineCanonicalizeSubTree(input.getSubNode(),excl);
} else {
- result = c14n.engineCanonicalizeXPathNodeSet(input.getNodeSet());
+ Set set=input.getNodeSet(true);
+ result = c14n.engineCanonicalizeXPathNodeSet(set);
}
}
return new XMLSignatureInput(result);