summaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
authorCGantert345 <57003061+CGantert345@users.noreply.github.com>2022-02-01 14:16:00 +0100
committerCGantert345 <57003061+CGantert345@users.noreply.github.com>2022-02-01 14:16:00 +0100
commit9ff0dde49e818348df5ba9c7bca91d165227234b (patch)
tree08b06389a431866bd02149bab7dae625f9d63d3b /src/main/java
parent- missing fieldOrder added (diff)
downloadUIC-barcode-9ff0dde49e818348df5ba9c7bca91d165227234b.tar
UIC-barcode-9ff0dde49e818348df5ba9c7bca91d165227234b.tar.gz
UIC-barcode-9ff0dde49e818348df5ba9c7bca91d165227234b.tar.bz2
UIC-barcode-9ff0dde49e818348df5ba9c7bca91d165227234b.tar.lz
UIC-barcode-9ff0dde49e818348df5ba9c7bca91d165227234b.tar.xz
UIC-barcode-9ff0dde49e818348df5ba9c7bca91d165227234b.tar.zst
UIC-barcode-9ff0dde49e818348df5ba9c7bca91d165227234b.zip
Diffstat (limited to '')
-rw-r--r--src/main/java/org/uic/barcode/Encoder.java52
1 files changed, 52 insertions, 0 deletions
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