Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

code cleanup #276

Merged
merged 14 commits into from
Nov 20, 2023
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
<dependency>
<groupId>org.apache.santuario</groupId>
<artifactId>xmlsec</artifactId>
<version>3.0.3</version>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/xades4j/utils/ResolverAnonymous.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.io.InputStream;
import org.apache.xml.security.signature.XMLSignatureInput;
import org.apache.xml.security.signature.XMLSignatureStreamInput;
import org.apache.xml.security.utils.resolver.ResourceResolverContext;
import org.apache.xml.security.utils.resolver.ResourceResolverException;
import org.apache.xml.security.utils.resolver.ResourceResolverSpi;
Expand All @@ -40,7 +41,7 @@ public ResolverAnonymous(InputStream data)
@Override
public XMLSignatureInput engineResolveURI(ResourceResolverContext context) throws ResourceResolverException
{
return new XMLSignatureInput(this.data);
return new XMLSignatureStreamInput(this.data);
}

@Override
Expand Down
13 changes: 5 additions & 8 deletions src/main/java/xades4j/utils/TimeStampDigestInputImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.xml.security.signature.Reference;
import org.apache.xml.security.signature.XMLSignatureException;
import org.apache.xml.security.signature.XMLSignatureInput;
import org.apache.xml.security.signature.XMLSignatureNodeInput;
import org.apache.xml.security.transforms.Transform;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
Expand Down Expand Up @@ -76,7 +77,7 @@ public void addNode(Node n) throws CannotAddDataToDigestInputException
throw new NullPointerException();
}

addToDigestInput(new XMLSignatureInput(n), n.getOwnerDocument());
addToDigestInput(new XMLSignatureNodeInput(n), n.getOwnerDocument());
}

private void addToDigestInput(XMLSignatureInput refData, Document doc) throws CannotAddDataToDigestInputException
Expand All @@ -90,13 +91,9 @@ private void addToDigestInput(XMLSignatureInput refData, Document doc) throws Ca
// Fall through to add the bytes resulting from the canonicalization.
}

if (refData.isByteArray())
{
digestInput.write(refData.getBytes());
} else if (refData.isOctetStream())
{
StreamUtils.readWrite(refData.getOctetStream(), digestInput);
}
digestInput.write(refData.getBytes());
digestInput.close();

mjechow marked this conversation as resolved.
Show resolved Hide resolved
}
catch (Exception ex)
{
Expand Down
8 changes: 3 additions & 5 deletions src/test/java/xades4j/production/OtherSignerTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,12 @@
*/
package xades4j.production;

import org.apache.xml.security.c14n.Canonicalizer;
import org.apache.xml.security.signature.XMLSignatureInput;
import org.apache.xml.security.utils.Constants;
import org.apache.xml.security.utils.DOMNamespaceContext;
import org.apache.xml.security.signature.XMLSignatureStreamInput;
import org.apache.xml.security.utils.resolver.ResourceResolverContext;
import org.apache.xml.security.utils.resolver.ResourceResolverException;
import org.apache.xml.security.utils.resolver.ResourceResolverSpi;
import org.w3c.dom.Attr;
import org.w3c.dom.Node;
import xades4j.algorithms.EnvelopedSignatureTransform;
import xades4j.algorithms.ExclusiveCanonicalXMLWithoutComments;
import xades4j.properties.DataObjectDesc;
Expand All @@ -41,6 +38,7 @@
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathFactory;

import java.io.ByteArrayInputStream;
import java.util.Iterator;

import static org.apache.xml.security.algorithms.MessageDigestAlgorithm.ALGO_ID_DIGEST_SHA256;
Expand Down Expand Up @@ -112,7 +110,7 @@ static class MyResolverSpi extends ResourceResolverSpi
@Override
public XMLSignatureInput engineResolveURI(ResourceResolverContext context) throws ResourceResolverException
{
XMLSignatureInput input = new XMLSignatureInput(context.attr.getValue().getBytes());
XMLSignatureInput input = new XMLSignatureStreamInput(new ByteArrayInputStream(context.attr.getValue().getBytes()));
mjechow marked this conversation as resolved.
Show resolved Hide resolved
resolveCount++;
return input;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,17 @@
*/
package xades4j.production;

import org.apache.xml.security.signature.Manifest;
import org.apache.xml.security.signature.XMLSignatureInput;
import org.apache.xml.security.signature.*;
mjechow marked this conversation as resolved.
Show resolved Hide resolved
import org.apache.xml.security.utils.resolver.ResourceResolverContext;
import org.apache.xml.security.utils.resolver.ResourceResolverException;
import org.apache.xml.security.utils.resolver.ResourceResolverSpi;
import org.w3c.dom.Element;
import xades4j.algorithms.EnvelopedSignatureTransform;
import org.apache.xml.security.utils.Constants;

import java.io.ByteArrayInputStream;
import java.util.Map;

import org.apache.xml.security.signature.ObjectContainer;
import org.apache.xml.security.signature.Reference;
import org.apache.xml.security.signature.XMLSignature;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.w3c.dom.Document;
Expand Down Expand Up @@ -119,7 +116,7 @@ public void testAddManifest() throws Exception
@Override
public XMLSignatureInput engineResolveURI(ResourceResolverContext context)
{
return new XMLSignatureInput(context.uriToResolve.getBytes());
return new XMLSignatureStreamInput(new ByteArrayInputStream(context.uriToResolve.getBytes()));
}

@Override
Expand Down