use of org.apache.xml.security.c14n.implementations.Canonicalizer20010315ExclWithComments in project santuario-java by apache.
the class Canonicalizer20010315ExclusiveTest method test222excl.
/**
* Method test222excl
*
* @throws CanonicalizationException
* @throws FileNotFoundException
* @throws IOException
* @throws InvalidCanonicalizerException
* @throws ParserConfigurationException
* @throws SAXException
* @throws TransformerException
* @throws XMLSecurityException
* @throws XMLSignatureException
*/
@org.junit.Test
public void test222excl() throws IOException, FileNotFoundException, SAXException, ParserConfigurationException, CanonicalizationException, InvalidCanonicalizerException, TransformerException, XMLSignatureException, XMLSecurityException {
Document doc = this.db.parse(getAbsolutePath("src/test/resources/org/apache/xml/security/c14n/inExcl/example2_2_2.xml"));
Node root = doc.getElementsByTagNameNS("http://example.net", "elem2").item(0);
Canonicalizer20010315Excl c = new Canonicalizer20010315ExclWithComments();
byte[] reference = JavaUtils.getBytesFromFile(getAbsolutePath("src/test/resources/org/apache/xml/security/c14n/inExcl/example2_2_c14nized_exclusive.xml"));
byte[] result = c.engineCanonicalizeSubTree(root);
boolean equals = java.security.MessageDigest.isEqual(reference, result);
assertTrue(equals);
}
use of org.apache.xml.security.c14n.implementations.Canonicalizer20010315ExclWithComments in project santuario-java by apache.
the class Canonicalizer20010315ExclusiveTest method test24Aexcl.
/**
* Method test24Aexcl - a testcase for SANTUARIO-263
* "Canonicalizer can't handle dynamical created DOM correctly"
* https://issues.apache.org/jira/browse/SANTUARIO-263
*/
@org.junit.Test
public void test24Aexcl() throws Exception {
Document doc = XMLUtils.createDocumentBuilder(false).newDocument();
Element local = doc.createElementNS("foo:bar", "dsig:local");
Element test = doc.createElementNS("http://example.net", "etsi:test");
Element elem2 = doc.createElementNS("http://example.net", "etsi:elem2");
Element stuff = doc.createElementNS("foo:bar", "dsig:stuff");
elem2.appendChild(stuff);
test.appendChild(elem2);
local.appendChild(test);
doc.appendChild(local);
Node root = doc.getElementsByTagNameNS("http://example.net", "elem2").item(0);
Canonicalizer20010315Excl c = new Canonicalizer20010315ExclWithComments();
byte[] reference = JavaUtils.getBytesFromFile(getAbsolutePath("src/test/resources/org/apache/xml/security/c14n/inExcl/example2_4_c14nized.xml"));
byte[] result = c.engineCanonicalizeSubTree(root);
boolean equals = java.security.MessageDigest.isEqual(reference, result);
assertTrue(equals);
}
use of org.apache.xml.security.c14n.implementations.Canonicalizer20010315ExclWithComments in project santuario-java by apache.
the class Canonicalizer20010315ExclusiveTest method test24excl.
/**
* Method test24excl - a testcase for SANTUARIO-263
* "Canonicalizer can't handle dynamical created DOM correctly"
* https://issues.apache.org/jira/browse/SANTUARIO-263
*/
@org.junit.Test
public void test24excl() throws Exception {
Document doc = this.db.parse(getAbsolutePath("src/test/resources/org/apache/xml/security/c14n/inExcl/example2_4.xml"));
Node root = doc.getElementsByTagNameNS("http://example.net", "elem2").item(0);
Canonicalizer20010315Excl c = new Canonicalizer20010315ExclWithComments();
byte[] reference = JavaUtils.getBytesFromFile(getAbsolutePath("src/test/resources/org/apache/xml/security/c14n/inExcl/example2_4_c14nized.xml"));
byte[] result = c.engineCanonicalizeSubTree(root);
boolean equals = java.security.MessageDigest.isEqual(reference, result);
assertTrue(equals);
}
use of org.apache.xml.security.c14n.implementations.Canonicalizer20010315ExclWithComments in project santuario-java by apache.
the class TransformC14NExclusiveWithComments method enginePerformTransform.
protected XMLSignatureInput enginePerformTransform(XMLSignatureInput input, OutputStream os, Transform transformObject) throws CanonicalizationException {
try {
String inclusiveNamespaces = null;
if (transformObject.length(InclusiveNamespaces.ExclusiveCanonicalizationNamespace, InclusiveNamespaces._TAG_EC_INCLUSIVENAMESPACES) == 1) {
Element inclusiveElement = XMLUtils.selectNode(transformObject.getElement().getFirstChild(), InclusiveNamespaces.ExclusiveCanonicalizationNamespace, InclusiveNamespaces._TAG_EC_INCLUSIVENAMESPACES, 0);
inclusiveNamespaces = new InclusiveNamespaces(inclusiveElement, transformObject.getBaseURI()).getInclusiveNamespaces();
}
Canonicalizer20010315ExclWithComments c14n = new Canonicalizer20010315ExclWithComments();
c14n.setSecureValidation(secureValidation);
if (os != null) {
c14n.setWriter(os);
}
byte[] result = c14n.engineCanonicalize(input, inclusiveNamespaces);
XMLSignatureInput output = new XMLSignatureInput(result);
output.setSecureValidation(secureValidation);
return output;
} catch (XMLSecurityException ex) {
throw new CanonicalizationException(ex);
}
}
use of org.apache.xml.security.c14n.implementations.Canonicalizer20010315ExclWithComments in project santuario-java by apache.
the class Canonicalizer20010315ExclusiveTest method test223excl.
/**
* Method test223excl
*
* Provided by Gabriel McGoldrick - see e-mail of 21/11/03
*
* @throws CanonicalizationException
* @throws FileNotFoundException
* @throws IOException
* @throws InvalidCanonicalizerException
* @throws ParserConfigurationException
* @throws SAXException
* @throws TransformerException
* @throws XMLSecurityException
* @throws XMLSignatureException
* @throws XPathExpressionException
*/
@org.junit.Test
public void test223excl() throws IOException, FileNotFoundException, SAXException, ParserConfigurationException, CanonicalizationException, InvalidCanonicalizerException, TransformerException, XMLSignatureException, XMLSecurityException, XPathExpressionException {
Document doc = this.db.parse(getAbsolutePath("src/test/resources/org/apache/xml/security/c14n/inExcl/example2_2_3.xml"));
XPathFactory xpf = XPathFactory.newInstance();
XPath xpath = xpf.newXPath();
xpath.setNamespaceContext(new DSNamespaceContext());
String expression = "(//. | //@* | //namespace::*)[ancestor-or-self::p]";
NodeList nodes = (NodeList) xpath.evaluate(expression, doc, XPathConstants.NODESET);
Canonicalizer20010315Excl c = new Canonicalizer20010315ExclWithComments();
byte[] reference = JavaUtils.getBytesFromFile(getAbsolutePath("src/test/resources/org/apache/xml/security/c14n/inExcl/example2_2_3_c14nized_exclusive.xml"));
byte[] result = c.engineCanonicalizeXPathNodeSet(nodes);
assertEquals(new String(reference), new String(result));
}
Aggregations