From 9ff0dde49e818348df5ba9c7bca91d165227234b Mon Sep 17 00:00:00 2001 From: CGantert345 <57003061+CGantert345@users.noreply.github.com> Date: Tue, 1 Feb 2022 14:16:00 +0100 Subject: - smplified api for level 2 signature --- src/main/java/org/uic/barcode/Encoder.java | 52 ++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'src/main/java/org/uic') diff --git a/src/main/java/org/uic/barcode/Encoder.java b/src/main/java/org/uic/barcode/Encoder.java index 51e86a2..9afddce 100644 --- a/src/main/java/org/uic/barcode/Encoder.java +++ b/src/main/java/org/uic/barcode/Encoder.java @@ -4,6 +4,7 @@ import java.io.IOException; import java.security.PrivateKey; import java.security.Provider; import java.security.PublicKey; +import java.util.zip.DataFormatException; import org.uic.barcode.dynamicContent.api.IUicDynamicContent; import org.uic.barcode.dynamicContent.fdc1.UicDynamicContentDataFDC1; @@ -163,6 +164,57 @@ public class Encoder { } + /** + * Instantiates a new encoder for a level 2 encoding with tan encoded dynamic frame containing the level 1 data and signature. + * + * @param level1Data the level 1 data (binary as signed) + * @param signatureLevel1 the signature of the level 1 data + * @param version the version of the bar code + * @throws IOException Signals that an I/O exception has occurred. + * @throws EncodingFormatException the encoding format exception + * @throws DataFormatException + */ + public Encoder(byte[] encoded, int version) throws IOException, EncodingFormatException, DataFormatException { + + Decoder decoder = new Decoder(encoded); + + if (decoder.getDynamicFrame() == null) { + throw new EncodingFormatException("No dynamic frame included"); + } + + + dynamicFrame = decoder.getDynamicFrame(); + byte[] level1DataBin = decoder.getEncodedLevel1Data(); + byte[] signatureLevel1 = decoder.getLevel1Signature(); + + if (version == 1) { + + dynamicFrame.setFormat(Constants.DYNAMIC_BARCODE_FORMAT_VERSION_1); + + ILevel1Data l1 = DynamicFrameCoderV1.decodeLevel1(level1DataBin); + + dynamicFrame.getLevel2Data().setLevel1Data(l1); + + dynamicFrame.getLevel2Data().setLevel1Signature(signatureLevel1); + + } else if (version == 2) { + + dynamicFrame.setFormat(Constants.DYNAMIC_BARCODE_FORMAT_VERSION_2); + + ILevel1Data l1 = DynamicFrameCoderV2.decodeLevel1(level1DataBin); + + dynamicFrame.getLevel2Data().setLevel1Data(l1); + + dynamicFrame.getLevel2Data().setLevel1Signature(signatureLevel1); + + } else { + throw new EncodingFormatException("Version of the dynamic header not supported"); + } + + + } + + /** * Signing level 2 of a dynamic bar code -- cgit v1.2.3