diff options
author | Andreas Fitzek <andreas.fitzek@iaik.tugraz.at> | 2014-01-21 09:57:16 +0100 |
---|---|---|
committer | Andreas Fitzek <andreas.fitzek@iaik.tugraz.at> | 2014-01-21 09:57:16 +0100 |
commit | 2436aa273f00dafb465c2342ea8e7297898915d2 (patch) | |
tree | 27cf115b4ec6d36f84b01b50acc403cf31b3ab6b /pdf-as-legacy/src/test | |
parent | 8d801ab37834b0f11c6a16c240d77da71a6ab816 (diff) | |
download | pdf-as-4-2436aa273f00dafb465c2342ea8e7297898915d2.tar.gz pdf-as-4-2436aa273f00dafb465c2342ea8e7297898915d2.tar.bz2 pdf-as-4-2436aa273f00dafb465c2342ea8e7297898915d2.zip |
Implementations for pdf-as-web and pdf-as-legacy
Diffstat (limited to 'pdf-as-legacy/src/test')
-rw-r--r-- | pdf-as-legacy/src/test/java/ByteArrayDataSink.java | 36 | ||||
-rw-r--r-- | pdf-as-legacy/src/test/java/ByteArrayDataSource.java | 35 | ||||
-rw-r--r-- | pdf-as-legacy/src/test/java/LegacyTest.java | 60 | ||||
-rw-r--r-- | pdf-as-legacy/src/test/java/StreamUtils.java | 7 | ||||
-rw-r--r-- | pdf-as-legacy/src/test/resources/simple.pdf | bin | 0 -> 6257 bytes |
5 files changed, 138 insertions, 0 deletions
diff --git a/pdf-as-legacy/src/test/java/ByteArrayDataSink.java b/pdf-as-legacy/src/test/java/ByteArrayDataSink.java new file mode 100644 index 00000000..7aa74333 --- /dev/null +++ b/pdf-as-legacy/src/test/java/ByteArrayDataSink.java @@ -0,0 +1,36 @@ +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.OutputStream; + +import at.gv.egiz.pdfas.api.io.DataSink; + + +public class ByteArrayDataSink implements DataSink { + + private ByteArrayOutputStream bos = new ByteArrayOutputStream(); + + public ByteArrayDataSink() { + } + + public OutputStream createOutputStream(String mimeType) throws IOException { + return createOutputStream(mimeType, "UTF-8"); + } + + public OutputStream createOutputStream(String mimeType, + String characterEncoding) throws IOException { + return bos; + } + + public String getMimeType() { + return "application/pdf"; + } + + public String getCharacterEncoding() { + return "UTF-8"; + } + + public byte[] getBytes() { + return this.bos.toByteArray(); + } + +} diff --git a/pdf-as-legacy/src/test/java/ByteArrayDataSource.java b/pdf-as-legacy/src/test/java/ByteArrayDataSource.java new file mode 100644 index 00000000..d4b83cc4 --- /dev/null +++ b/pdf-as-legacy/src/test/java/ByteArrayDataSource.java @@ -0,0 +1,35 @@ +import java.io.ByteArrayInputStream; +import java.io.InputStream; + +import at.gv.egiz.pdfas.api.io.DataSource; + + +public class ByteArrayDataSource implements DataSource { + + private byte[] data; + + public ByteArrayDataSource(byte[] data) { + this.data = data; + } + + public InputStream createInputStream() { + return new ByteArrayInputStream(data); + } + + public int getLength() { + return data.length; + } + + public byte[] getAsByteArray() { + return data; + } + + public String getMimeType() { + return "application/pdf"; + } + + public String getCharacterEncoding() { + return "UTF-8"; + } + +} diff --git a/pdf-as-legacy/src/test/java/LegacyTest.java b/pdf-as-legacy/src/test/java/LegacyTest.java new file mode 100644 index 00000000..21d0c3b1 --- /dev/null +++ b/pdf-as-legacy/src/test/java/LegacyTest.java @@ -0,0 +1,60 @@ +import java.io.FileOutputStream; +import java.io.InputStream; +import java.util.Iterator; + +import org.apache.commons.io.IOUtils; + +import at.gv.egiz.pdfas.PdfAsFactory; +import at.gv.egiz.pdfas.api.PdfAs; +import at.gv.egiz.pdfas.api.sign.SignParameters; +import at.gv.egiz.pdfas.api.sign.SignResult; +import at.gv.egiz.pdfas.api.verify.VerifyParameters; +import at.gv.egiz.pdfas.api.verify.VerifyResult; +import at.gv.egiz.pdfas.api.verify.VerifyResults; + +public class LegacyTest { + + public static void main(String[] args) { + try { + PdfAs pdfAS = PdfAsFactory.createPdfAs(); + + SignParameters signParameters = new SignParameters(); + signParameters.setSignatureDevice("bku"); + signParameters.setSignatureProfileId("SIGNATURBLOCK_DE"); + + InputStream is = LegacyTest.class.getResourceAsStream("simple.pdf"); + + byte[] inputData = IOUtils.toByteArray(is); + ByteArrayDataSink bads = new ByteArrayDataSink(); + signParameters.setDocument(new ByteArrayDataSource(inputData)); + signParameters.setOutput(bads); + SignResult result = pdfAS.sign(signParameters); + IOUtils.write(bads.getBytes(), new FileOutputStream("/tmp/test.pdf")); + + System.out.println("Signed @ " + result.getSignaturePosition().toString()); + System.out.println("Signed by " + result.getSignerCertificate().getSubjectDN().getName()); + + VerifyParameters verifyParameters = new VerifyParameters(); + verifyParameters.setDocument(new ByteArrayDataSource(bads.getBytes())); + verifyParameters.setSignatureToVerify(0); + + VerifyResults results = pdfAS.verify(verifyParameters); + + Iterator iter = results.getResults().iterator(); + + while(iter.hasNext()) { + Object obj = iter.next(); + if(obj instanceof VerifyResult) { + VerifyResult vresult = (VerifyResult)obj; + System.out.println("Verified: " + vresult.getValueCheckCode().getCode() + " " + + vresult.getValueCheckCode().getMessage()); + } + } + + } catch (Throwable e) { + System.out.println("ERROR"); + e.printStackTrace(); + } + } + +} diff --git a/pdf-as-legacy/src/test/java/StreamUtils.java b/pdf-as-legacy/src/test/java/StreamUtils.java new file mode 100644 index 00000000..f6822d97 --- /dev/null +++ b/pdf-as-legacy/src/test/java/StreamUtils.java @@ -0,0 +1,7 @@ +import java.io.ByteArrayOutputStream; +import java.io.InputStream; + +import org.apache.commons.io.IOUtils; + +public class StreamUtils { +} diff --git a/pdf-as-legacy/src/test/resources/simple.pdf b/pdf-as-legacy/src/test/resources/simple.pdf Binary files differnew file mode 100644 index 00000000..867f68db --- /dev/null +++ b/pdf-as-legacy/src/test/resources/simple.pdf |