From 3d982813b34f6f230baf4a467cdc37ec92a77595 Mon Sep 17 00:00:00 2001 From: netconomy Date: Fri, 17 Aug 2007 06:10:56 +0000 Subject: Performance git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/trunk@167 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c --- .../verificators/BinaryVerificator_1_0_0.java | 50 ++++++++++++++-------- 1 file changed, 31 insertions(+), 19 deletions(-) (limited to 'src/main/java/at/knowcenter/wag/egov/egiz/framework/verificators/BinaryVerificator_1_0_0.java') diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/framework/verificators/BinaryVerificator_1_0_0.java b/src/main/java/at/knowcenter/wag/egov/egiz/framework/verificators/BinaryVerificator_1_0_0.java index 469fcee..b389a25 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/framework/verificators/BinaryVerificator_1_0_0.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/framework/verificators/BinaryVerificator_1_0_0.java @@ -22,6 +22,10 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import at.gv.egiz.pdfas.exceptions.ErrorCode; +import at.gv.egiz.pdfas.framework.input.PdfDataSource; +import at.gv.egiz.pdfas.impl.input.ByteArrayPdfDataSourceImpl; + import org.apache.log4j.Logger; import at.knowcenter.wag.egov.egiz.PdfASID; @@ -52,11 +56,12 @@ import at.knowcenter.wag.exactparser.parsing.results.NumberParseResult; import at.knowcenter.wag.exactparser.parsing.results.ObjectParseResult; import at.knowcenter.wag.exactparser.parsing.results.ParseResult; - /** * The BinaryVerificator parses the EGIT Dictionary and extracts the signature * holder from it. * + * @deprecated moved to the new framework + * * @author wprinz */ public class BinaryVerificator_1_0_0 implements Verificator @@ -66,6 +71,16 @@ public class BinaryVerificator_1_0_0 implements Verificator */ public static final PdfASID MY_ID = new PdfASID(SignatorFactory.VENDOR, SignatorFactory.TYPE_BINARY, SignatorFactory.VERSION_1_0_0); + /** + * Use this to override the MY_ID field. + * + * @return Returns the Id of this Verificator. + */ + protected PdfASID getMyId() + { + return MY_ID; + } + /** * The /ODS key in the EGIZ Dict. */ @@ -79,20 +94,17 @@ public class BinaryVerificator_1_0_0 implements Verificator /** * The /ByteRange key in the EGIZ Dict. */ - public static final byte[] EGIZ_BYTE_RANGE_NAME = new byte[] { 'B', 'y', 't', - 'e', 'R', 'a', 'n', 'g', 'e' }; + public static final byte[] EGIZ_BYTE_RANGE_NAME = new byte[] { 'B', 'y', 't', 'e', 'R', 'a', 'n', 'g', 'e' }; /** * The /replaces key in the EGIZ Dict. */ - public static final byte[] EGIZ_REPLACES_NAME = new byte[] { 'r', 'e', 'p', - 'l', 'a', 'c', 'e', 's' }; + public static final byte[] EGIZ_REPLACES_NAME = new byte[] { 'r', 'e', 'p', 'l', 'a', 'c', 'e', 's' }; /** * The /encodings key in the EGIZ Dict. */ - public static final byte[] EGIZ_ENCODINGS_NAME = new byte[] { 'e', 'n', 'c', - 'o', 'd', 'i', 'n', 'g', 's' }; + public static final byte[] EGIZ_ENCODINGS_NAME = new byte[] { 'e', 'n', 'c', 'o', 'd', 'i', 'n', 'g', 's' }; /** * The /Cert key in the EGIZ Dict. @@ -116,13 +128,12 @@ public class BinaryVerificator_1_0_0 implements Verificator * @see at.knowcenter.wag.egov.egiz.framework.Verificator#parseBlock(byte[], * at.knowcenter.wag.exactparser.parsing.results.FooterParseResult, int) */ - public List parseBlock(byte[] pdf, FooterParseResult block, - int start_of_whole_block) throws PresentableException + public List parseBlock(byte[] pdf, FooterParseResult block, int start_of_whole_block) throws PresentableException { int egiz_index = PDFUtils.indexOfName(pdf, block.tpr.dpr.names, VerificationFilter.EGIZ_DICT_NAME); if (egiz_index < 0) { - throw new PDFDocumentException(301, "egiz_index = " + egiz_index); + throw new PDFDocumentException(ErrorCode.COULDNT_VERIFY, "egiz_index = " + egiz_index); } IndirectObjectReferenceParseResult egiz_dict_iorpr = (IndirectObjectReferenceParseResult) block.tpr.dpr.values.get(egiz_index); @@ -140,7 +151,7 @@ public class BinaryVerificator_1_0_0 implements Verificator PdfASID kz = null; String kz_string = VerificationFilter.restoreKZ(pdf, kz_apr); kz = new PdfASID(kz_string); - if (!kz_string.equals(MY_ID.toString())) + if (!kz_string.equals(getMyId().toString())) { logger_.warn("Warning: Kennzeichnung not recognized:" + kz_string); } @@ -223,7 +234,9 @@ public class BinaryVerificator_1_0_0 implements Verificator // bbi); byte[] signed_pdf = BinarySignature.prepareDataToSign(pdf, byte_ranges); - //String signed_text = BinarySignature.retrieveSignableTextFromData(signed_pdf, signed_pdf.length); // has been moved into the BinarySignatureHolder + // String signed_text = + // BinarySignature.retrieveSignableTextFromData(signed_pdf, + // signed_pdf.length); // has been moved into the BinarySignatureHolder SignatureObject signature_object = new SignatureObject(); String default_type = SettingsReader.getInstance().getValueFromKey(SignatureTypes.DEFAULT_TYPE); @@ -300,8 +313,9 @@ public class BinaryVerificator_1_0_0 implements Verificator } } - // FIXME make better - BinarySignatureHolder signature_holder = new BinarySignatureHolder(signed_pdf, signed_pdf.length, signature_object); + // FIXME This blows up the session !!!!! + PdfDataSource ds = new ByteArrayPdfDataSourceImpl(signed_pdf, signed_pdf.length); + BinarySignatureHolder signature_holder = new BinarySignatureHolder(ds, signature_object); List holders = new ArrayList(); holders.add(signature_holder); @@ -322,8 +336,7 @@ public class BinaryVerificator_1_0_0 implements Verificator * @throws PDFDocumentException * Thrown, if the key doesn't exist in the dictionary. */ - protected ParseResult getRequiredValueOfKey(byte[] pdf, - DictionaryParseResult egiz_dict, byte[] name) throws PDFDocumentException + protected ParseResult getRequiredValueOfKey(byte[] pdf, DictionaryParseResult egiz_dict, byte[] name) throws PDFDocumentException { final int index = PDFUtils.indexOfName(pdf, egiz_dict.names, name); checkIndex(index); @@ -343,7 +356,7 @@ public class BinaryVerificator_1_0_0 implements Verificator { if (name_index < 0) { - throw new PDFDocumentException(301, "The name wasn't found in the egiz dict."); + throw new PDFDocumentException(ErrorCode.COULDNT_VERIFY, "The name wasn't found in the egiz dict."); } } @@ -359,8 +372,7 @@ public class BinaryVerificator_1_0_0 implements Verificator * @return Returns the key's value, or null if the dictionary didn't contain * that key. */ - protected ParseResult getValueOfKey(byte[] pdf, - DictionaryParseResult egiz_dict, byte[] name) + protected ParseResult getValueOfKey(byte[] pdf, DictionaryParseResult egiz_dict, byte[] name) { final int index = PDFUtils.indexOfName(pdf, egiz_dict.names, name); if (index < 0) -- cgit v1.2.3