summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCGantert345 <57003061+CGantert345@users.noreply.github.com>2021-12-15 16:37:37 +0100
committerCGantert345 <57003061+CGantert345@users.noreply.github.com>2021-12-15 16:37:37 +0100
commitfbbc6349283bc8958cad51534da9cb82c46210c9 (patch)
treeaf9ab4bf4ea9c95dd7be00d02088619a8a47610d
parent- unit test for the dynamic content in DOSIPAS (diff)
downloadUIC-barcode-fbbc6349283bc8958cad51534da9cb82c46210c9.tar
UIC-barcode-fbbc6349283bc8958cad51534da9cb82c46210c9.tar.gz
UIC-barcode-fbbc6349283bc8958cad51534da9cb82c46210c9.tar.bz2
UIC-barcode-fbbc6349283bc8958cad51534da9cb82c46210c9.tar.lz
UIC-barcode-fbbc6349283bc8958cad51534da9cb82c46210c9.tar.xz
UIC-barcode-fbbc6349283bc8958cad51534da9cb82c46210c9.tar.zst
UIC-barcode-fbbc6349283bc8958cad51534da9cb82c46210c9.zip
Diffstat (limited to '')
-rw-r--r--src/main/java/org/uic/barcode/dynamicContent/api/DynamicContentCoder.java211
-rw-r--r--src/main/java/org/uic/barcode/dynamicContent/api/IUicDynamicContent.java130
-rw-r--r--src/main/java/org/uic/barcode/dynamicContent/api/SimpleUicDynamicContent.java150
-rw-r--r--src/test/java/org/uic/barcode/test/AsnLevelDynamicContentTest.java112
-rw-r--r--src/test/java/org/uic/barcode/test/DynamicContentCoderTest.java118
5 files changed, 721 insertions, 0 deletions
diff --git a/src/main/java/org/uic/barcode/dynamicContent/api/DynamicContentCoder.java b/src/main/java/org/uic/barcode/dynamicContent/api/DynamicContentCoder.java
new file mode 100644
index 0000000..d8bf3b4
--- /dev/null
+++ b/src/main/java/org/uic/barcode/dynamicContent/api/DynamicContentCoder.java
@@ -0,0 +1,211 @@
+package org.uic.barcode.dynamicContent.api;
+
+import java.util.Date;
+import java.util.List;
+
+import org.uic.barcode.dynamicContent.fdc1.GeoCoordinateType;
+import org.uic.barcode.dynamicContent.fdc1.SequenceOfExtension;
+import org.uic.barcode.dynamicContent.fdc1.TimeStamp;
+import org.uic.barcode.dynamicContent.fdc1.UicDynamicContentDataFDC1;
+import org.uic.barcode.ticket.EncodingFormatException;
+import org.uic.barcode.asn1.uper.UperEncoder;
+import org.uic.barcode.dynamicContent.fdc1.ExtensionData;
+import org.uic.barcode.dynamicContent.fdc1.GeoCoordinateSystemType;
+import org.uic.barcode.dynamicContent.fdc1.GeoUnitType;
+import org.uic.barcode.dynamicContent.fdc1.HemisphereLatitudeType;
+import org.uic.barcode.dynamicContent.fdc1.HemisphereLongitudeType;
+import org.uic.barcode.ticket.api.impl.SimpleExtension;
+import org.uic.barcode.ticket.api.impl.SimpleGeoCoordinate;
+import org.uic.barcode.ticket.api.spec.IExtension;
+import org.uic.barcode.ticket.api.spec.IGeoCoordinate;
+import org.uic.barcode.ticket.api.spec.IGeoCoordinateSystemType;
+import org.uic.barcode.ticket.api.spec.IGeoUnitType;
+import org.uic.barcode.ticket.api.spec.IHemisphereLatitudeType;
+import org.uic.barcode.ticket.api.spec.IHemisphereLongitudeType;
+import org.uic.barcode.ticket.api.utils.UicEncoderUtils;
+
+public class DynamicContentCoder {
+
+ public static byte[] encode(IUicDynamicContent content, String format) throws EncodingFormatException {
+
+ if (format != null && !format.equals("FDC1")) {
+ throw new EncodingFormatException("Format of dynamic content not supported!");
+ }
+
+ UicDynamicContentDataFDC1 asn = new UicDynamicContentDataFDC1();
+
+ asn.setAppId(content.getAppId());
+
+ if (content.getChallengeString() != null && content.getChallengeString().length() > 0) {
+ asn.setChallengeString(content.getChallengeString());
+ }
+
+ asn.setDynamicContentExtension(getAsnExtension(content.getExtension()));
+
+ asn.setGeoCoordinate(getAsnGeoCoordinate(content.getGeoCoordinate()));
+
+ asn.setTimeStamp(getAsnTimeStamp(content.getTimeStamp()));
+
+ asn.setExtensions(getAsnContentExtensions(asn, content.getDynamicContentResponseList()));
+
+ return UperEncoder.encode(asn);
+
+ }
+
+
+
+ private static SequenceOfExtension getAsnContentExtensions(UicDynamicContentDataFDC1 asn, List<IExtension> dynamicContentResponseList) throws EncodingFormatException {
+ if (dynamicContentResponseList != null && !dynamicContentResponseList.isEmpty()){
+
+ SequenceOfExtension asnList = asn.getExtensions();
+ if (asnList == null) asnList = new SequenceOfExtension();
+ for (IExtension extension : dynamicContentResponseList){
+ ExtensionData asnExtension = getAsnExtension(extension);
+ if (asnExtension!= null) {
+ asnList.add(asnExtension);
+ }
+ }
+ if (!asnList.isEmpty()){
+ return asnList;
+ }
+ }
+
+ return null;
+ }
+
+ private static TimeStamp getAsnTimeStamp(Date date) {
+
+ if (date == null) return null;
+
+ TimeStamp asnTimeStamp = new TimeStamp();
+ asnTimeStamp.setDateTime(date);
+
+ return asnTimeStamp;
+
+ }
+
+ private static GeoCoordinateType getAsnGeoCoordinate(IGeoCoordinate point) {
+
+ if (point == null) return null;
+
+ GeoCoordinateType asnPoint = new GeoCoordinateType();
+
+ asnPoint.setLatitude(point.getLatitude());
+ asnPoint.setLongitude(point.getLongitude());
+
+ if (point.getUnit() != IGeoUnitType.milliDegree && point.getUnit() != null){
+ asnPoint.setGeoUnit(GeoUnitType.valueOf(point.getUnit().name()));
+ }
+
+ if (point.getAccuracy() != null) {
+ asnPoint.setAccuracy(GeoUnitType.valueOf(point.getAccuracy().name()));
+ }
+
+ if (point.getHemisphereLatitude() != IHemisphereLatitudeType.east && point.getHemisphereLatitude() != null) {
+ asnPoint.setHemisphereLatitude(HemisphereLatitudeType.valueOf(point.getHemisphereLatitude().name()));
+ }
+
+ if (point.getHemisphereLongitude() != IHemisphereLongitudeType.north && point.getHemisphereLongitude() != null) {
+ asnPoint.setHemisphereLongitude(HemisphereLongitudeType.valueOf(point.getHemisphereLongitude().name()));
+ }
+
+ if (point.getSystem() != IGeoCoordinateSystemType.wgs84 && point.getSystem() != null){
+ asnPoint.setCoordinateSystem(GeoCoordinateSystemType.valueOf(point.getSystem().name()));
+ }
+
+
+ return asnPoint;
+ }
+
+ private static ExtensionData getAsnExtension(IExtension extension) throws EncodingFormatException {
+ if (extension==null) return null;
+
+ if (extension.getBinarydata() == null || extension.getBinarydata().length == 0) {
+ throw new EncodingFormatException("Extension does not include data");
+ }
+
+ if (extension.getId() == null || extension.getId().length() == 0) {
+ throw new EncodingFormatException("Extension does not include id");
+ }
+
+ ExtensionData asnExtension = new ExtensionData();
+
+ asnExtension.setExtensionData(extension.getBinarydata());
+ asnExtension.setExtensionId(UicEncoderUtils.getIA5(extension.getId()));
+
+ return asnExtension;
+ }
+
+ public static IUicDynamicContent decode(byte[] bytes) {
+
+ UicDynamicContentDataFDC1 asn = UperEncoder.decode(bytes, UicDynamicContentDataFDC1.class);
+
+ IUicDynamicContent content = new SimpleUicDynamicContent();
+
+ content.setAppId(asn.getAppId());
+
+ content.setChallengeString(asn.getChallengeString());
+
+ content.setExtension(getExtension(asn.getDynamicContentExtension()));
+
+ if (asn.getExtensions() != null && !asn.getExtensions().isEmpty()) {
+ for (ExtensionData e : asn.getExtensions()) {
+ content.addDynamicContentResponse(getExtension(e));
+ }
+ }
+
+ content.setGeoCoordinate(getGeoCoordinate(asn.getGeoCoordinate()));
+
+ content.setTimeStamp(asn.getTimeStamp().getTimeAsDate());
+
+
+ return content;
+
+ }
+
+ private static IGeoCoordinate getGeoCoordinate(GeoCoordinateType asnCoordinate) {
+
+ IGeoCoordinate g = new SimpleGeoCoordinate();
+
+ g.setLatitude(asnCoordinate.getLatitude());
+ g.setLongitude(asnCoordinate.getLongitude());
+
+ if (asnCoordinate.getCoordinateSystem() != null) {
+ g.setSystem(IGeoCoordinateSystemType.valueOf(asnCoordinate.getCoordinateSystem().name()));
+ }
+
+ if (asnCoordinate.getAccuracy() != null) {
+ g.setAccuracy(IGeoUnitType.valueOf(asnCoordinate.getAccuracy().name()));
+ }
+
+ if (asnCoordinate.getGeoUnit() != null) {
+ g.setUnit(IGeoUnitType.valueOf(asnCoordinate.getGeoUnit().name()));
+ }
+
+ if (asnCoordinate.getHemisphereLatitude() != null) {
+ g.setHemisphereLatitude(IHemisphereLatitudeType.valueOf(asnCoordinate.getHemisphereLatitude().name()));
+ }
+
+ if (asnCoordinate.getHemisphereLongitude() != null) {
+ g.setHemisphereLongitude(IHemisphereLongitudeType.valueOf(asnCoordinate.getHemisphereLongitude().name()));
+ }
+
+
+ return g;
+ }
+
+
+
+ private static IExtension getExtension(ExtensionData asnExtension) {
+
+ if (asnExtension == null) return null;
+
+ SimpleExtension e = new SimpleExtension();
+ e.setBinarydata(asnExtension.getExtensionData());
+ e.setId(asnExtension.getExtensionId());
+
+ return e;
+ }
+
+
+}
diff --git a/src/main/java/org/uic/barcode/dynamicContent/api/IUicDynamicContent.java b/src/main/java/org/uic/barcode/dynamicContent/api/IUicDynamicContent.java
new file mode 100644
index 0000000..718d013
--- /dev/null
+++ b/src/main/java/org/uic/barcode/dynamicContent/api/IUicDynamicContent.java
@@ -0,0 +1,130 @@
+package org.uic.barcode.dynamicContent.api;
+
+import java.util.Date;
+import java.util.List;
+
+import org.uic.barcode.ticket.api.spec.IExtension;
+import org.uic.barcode.ticket.api.spec.IGeoCoordinate;
+
+// TODO: Auto-generated Javadoc
+/**
+ * The Interface IUicDynamicContent.
+ */
+public interface IUicDynamicContent {
+
+ /**
+ * Gets the app id.
+ *
+ * @return the app id
+ */
+ public String getAppId();
+
+ /**
+ * Sets the app id.
+ * @param string
+ *
+ * @return the string
+ */
+ public void setAppId(String string);
+
+ /**
+ * Gets the time stamp.
+ *
+ * @return the time stamp
+ */
+ public Date getTimeStamp();
+
+ /**
+ * Sets the time stamp.
+ *
+ * @param date the new time stamp
+ */
+ public void setTimeStamp(Date date);
+
+ /**
+ * Gets the geo coordinate.
+ *
+ * @return the geo coordinate
+ */
+ public IGeoCoordinate getGeoCoordinate();
+
+ /**
+ * Sets the geo coordinate.
+ *
+ * @param geoCoordinate the new geo coordinate
+ */
+ public void setGeoCoordinate(IGeoCoordinate geoCoordinate);
+
+
+ /**
+ * Gets the extension.
+ *
+ * @return the extension
+ */
+ public IExtension getExtension();
+
+ /**
+ * Sets the extension.
+ *
+ * @param extension the new extension
+ */
+ public void setExtension(IExtension extension);
+
+ /**
+ * Gets the challenge string.
+ *
+ * @return the challenge string
+ */
+ public String getChallengeString();
+
+ /**
+ * Sets the challenge string.
+ *
+ * @param challenge the new challenge string
+ */
+ public void setChallengeString(String challenge);
+
+ /**
+ * Gets the phone id hash.
+ *
+ * @return the phone id hash
+ */
+ public byte[] getPhoneIdHash();
+
+ /**
+ * Sets the phone id hash.
+ *
+ * @param phoneIdHash the new phone id hash
+ */
+ public void setPhoneIdHash(byte[] phoneIdHash);
+
+ /**
+ * Gets the pass id hash.
+ *
+ * @return the pass id hash
+ */
+ public byte[] getPassIdHash();
+
+ /**
+ * Sets the pass id hash.
+ *
+ * @param passIdHash the new pass id hash
+ */
+ public void setPassIdHash(byte[] passIdHash);
+
+ /**
+ * Gets the dynamic content response list.
+ *
+ * @return the dynamic content response list
+ */
+ public List<IExtension> getDynamicContentResponseList();
+
+ /**
+ * Adds the dynamic content response.
+ *
+ * @param challenge the challenge
+ */
+ public void addDynamicContentResponse(IExtension challenge);
+
+
+}
diff --git a/src/main/java/org/uic/barcode/dynamicContent/api/SimpleUicDynamicContent.java b/src/main/java/org/uic/barcode/dynamicContent/api/SimpleUicDynamicContent.java
new file mode 100644
index 0000000..ca5880d
--- /dev/null
+++ b/src/main/java/org/uic/barcode/dynamicContent/api/SimpleUicDynamicContent.java
@@ -0,0 +1,150 @@
+package org.uic.barcode.dynamicContent.api;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import org.uic.barcode.ticket.api.impl.SimpleExtension;
+import org.uic.barcode.ticket.api.spec.IExtension;
+import org.uic.barcode.ticket.api.spec.IGeoCoordinate;
+
+public class SimpleUicDynamicContent implements IUicDynamicContent {
+
+
+ protected String appId;
+
+ protected Date timeStamp;
+
+ protected String challenge;
+
+ protected IGeoCoordinate geoCoordinate;
+
+ protected IExtension dynamicContentExtension;
+
+ protected List<IExtension> dynamicContentResponseList;
+
+
+
+ public String getAppId() {
+ return appId;
+ }
+
+ public void setAppId(String appId) {
+ this.appId = appId;
+ }
+
+
+ public IGeoCoordinate getGeoCoordinate() {
+ return geoCoordinate;
+ }
+
+ public void setGeoCoordinate(IGeoCoordinate geoCoordinate) {
+ this.geoCoordinate = geoCoordinate;
+ }
+
+ public IExtension getDynamicContentExtension() {
+ return dynamicContentExtension;
+ }
+
+ public void setDynamicContentExtension(IExtension dynamicContentExtension) {
+ this.dynamicContentExtension = dynamicContentExtension;
+ }
+
+
+ @Override
+ public Date getTimeStamp() {
+ return timeStamp;
+ }
+
+ @Override
+ public void setTimeStamp(Date date) {
+ timeStamp = date;
+
+ }
+
+ @Override
+ public IExtension getExtension() {
+ return dynamicContentExtension;
+ }
+
+ @Override
+ public void setExtension(IExtension extension) {
+ dynamicContentExtension = extension;
+ }
+
+ @Override
+ public String getChallengeString() {
+ return challenge;
+ }
+
+ @Override
+ public void setChallengeString(String challenge) {
+ this.challenge = challenge;
+ }
+
+ @Override
+ public byte[] getPhoneIdHash() {
+ return getExtensionData("phone");
+ }
+
+ @Override
+ public void setPhoneIdHash(byte[] phoneIdHash) {
+ if (dynamicContentResponseList == null) {
+ dynamicContentResponseList = new ArrayList<IExtension>();
+ }
+
+ IExtension e = new SimpleExtension();
+ e.setBinarydata(phoneIdHash);
+ e.setId("phone");
+ getDynamicContentResponseList().add(e);
+ }
+
+ @Override
+ public byte[] getPassIdHash() {
+ return getExtensionData("pass");
+ }
+
+ private byte[] getExtensionData(String name) {
+ if (dynamicContentResponseList == null) return null;
+ for (IExtension e : dynamicContentResponseList) {
+ if (e.getId().equals(name)){
+ return e.getBinarydata();
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public void setPassIdHash(byte[] passIdHash) {
+ if (dynamicContentResponseList == null) {
+ dynamicContentResponseList = new ArrayList<IExtension>();
+ }
+
+ IExtension e = new SimpleExtension();
+ e.setBinarydata(passIdHash);
+ e.setId("pass");
+ getDynamicContentResponseList().add(e);
+ }
+
+ @Override
+ public List<IExtension> getDynamicContentResponseList() {
+ if (dynamicContentResponseList == null) {
+ dynamicContentResponseList = new ArrayList<IExtension>();
+ }
+
+ return dynamicContentResponseList;
+ }
+
+ @Override
+ public void addDynamicContentResponse(IExtension challenge) {
+
+ if (this.dynamicContentResponseList == null) {
+ this.dynamicContentResponseList = new ArrayList<IExtension>();
+ }
+
+ this.dynamicContentResponseList.add(challenge);
+
+ }
+
+
+}
diff --git a/src/test/java/org/uic/barcode/test/AsnLevelDynamicContentTest.java b/src/test/java/org/uic/barcode/test/AsnLevelDynamicContentTest.java
new file mode 100644
index 0000000..955066d
--- /dev/null
+++ b/src/test/java/org/uic/barcode/test/AsnLevelDynamicContentTest.java
@@ -0,0 +1,112 @@
+package org.uic.barcode.test;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.uic.barcode.asn1.uper.UperEncoder;
+import org.uic.barcode.dynamicContent.fdc1.ExtensionData;
+import org.uic.barcode.dynamicContent.fdc1.TimeStamp;
+import org.uic.barcode.dynamicContent.fdc1.UicDynamicContentDataFDC1;
+import org.uic.barcode.dynamicContent.fdc1.GeoCoordinateType;
+
+public class AsnLevelDynamicContentTest {
+
+ UicDynamicContentDataFDC1 asn = null;
+
+ @Before public void initialize() {
+
+
+ asn = new UicDynamicContentDataFDC1();
+
+ asn.setAppId("appID");
+
+ asn.setChallengeString("challenge string");
+
+ ExtensionData asnE1 = new ExtensionData();
+ asnE1.setExtensionData(UperEncoder.bytesFromHexString("82DA"));
+ asnE1.setExtensionId("challenge_extension_id1");
+ asn.setDynamicContentExtension(asnE1);
+
+
+ asn.getExtensions().add(asnE1);
+
+ ExtensionData asnE2 = new ExtensionData();
+ asnE2.setExtensionData(UperEncoder.bytesFromHexString("83DA"));
+ asnE2.setExtensionId("phone");
+ asn.getExtensions().add(asnE2);
+
+ ExtensionData asnE3 = new ExtensionData();
+ asnE3.setExtensionData(UperEncoder.bytesFromHexString("84DA"));
+ asnE3.setExtensionId("pass");
+ asn.getExtensions().add(asnE3);
+
+
+
+ asn.setGeoCoordinate(new GeoCoordinateType());
+ asn.getGeoCoordinate().setLongitude( 12345L);
+ asn.getGeoCoordinate().setLatitude( 56789L);
+
+ TimeStamp t = new TimeStamp();
+ t.setTime(100L);
+ t.setDay(20L);
+ asn.setTimeStamp(t);
+
+
+
+ }
+
+ @Test public void testDynamicContentEncoding() {
+
+ byte[] encodedBytes = UperEncoder.encode(asn);
+
+ String encoding = UperEncoder.hexStringFromBytes(encodedBytes);
+
+ String expectedEncoding = "7C170F0E126204C00C800230390300DDD504017A20C6D0C2D8D8CADCCECA40E6E8E4D2DCCE2F8F461D9B32EECF96FE5F1D32EEE7A77EEBFA72310282DA05E1A37EECA0507B409C30F3E60509B42F8F461D9B32EECF96FE5F1D32EEE7A77EEBFA72310282DA";
+
+ assert(expectedEncoding.equals(encoding));
+
+ }
+
+ @Test public void testDynamicContentDecoding() {
+
+ String encoding = "7C170F0E126204C00C800230390300DDD504017A20C6D0C2D8D8CADCCECA40E6E8E4D2DCCE2F8F461D9B32EECF96FE5F1D32EEE7A77EEBFA72310282DA05E1A37EECA0507B409C30F3E60509B42F8F461D9B32EECF96FE5F1D32EEE7A77EEBFA72310282DA";
+
+ UicDynamicContentDataFDC1 asn = UperEncoder.decode(UperEncoder.bytesFromHexString(encoding), UicDynamicContentDataFDC1.class);
+
+
+ assert("appID".equals(asn.getAppId()));
+
+ assert("challenge string".equals(asn.getChallengeString()));
+
+ ExtensionData asnE1 = asn.getDynamicContentExtension();
+ assert(UperEncoder.hexStringFromBytes(asnE1.getExtensionData()).equals("82DA"));
+ assert(asnE1.getExtensionId().equals("challenge_extension_id1"));
+
+
+ assert(asn.getExtensions().size() == 4);
+
+ assert(UperEncoder.hexStringFromBytes(asn.getExtensions().get(0).getExtensionData()).equals("6368616C6C656E676520737472696E67"));
+ assert(asn.getExtensions().get(0).getExtensionId().equals("="));
+
+ assert(UperEncoder.hexStringFromBytes(asn.getExtensions().get(1).getExtensionData()).equals("82DA"));
+ assert(asn.getExtensions().get(1).getExtensionId().equals("challenge_extension_id1"));
+
+ assert(UperEncoder.hexStringFromBytes(asn.getExtensions().get(2).getExtensionData()).equals("83DA"));
+ assert(asn.getExtensions().get(2).getExtensionId().equals("phone"));
+
+ assert(UperEncoder.hexStringFromBytes(asn.getExtensions().get(3).getExtensionData()).equals("84DA"));
+ assert(asn.getExtensions().get(3).getExtensionId().equals("pass"));
+
+
+ assert(asn.getGeoCoordinate() != null);
+ assert(asn.getGeoCoordinate().getLongitude() == 12345L);
+ assert(asn.getGeoCoordinate().getLatitude() == 56789L);
+
+ assert(asn.getTimeStamp() != null);
+ assert(asn.getTimeStamp().getDay() == 20L);
+ assert(asn.getTimeStamp().getTime() == 100L);
+
+ }
+
+
+
+}
diff --git a/src/test/java/org/uic/barcode/test/DynamicContentCoderTest.java b/src/test/java/org/uic/barcode/test/DynamicContentCoderTest.java
new file mode 100644
index 0000000..10963c5
--- /dev/null
+++ b/src/test/java/org/uic/barcode/test/DynamicContentCoderTest.java
@@ -0,0 +1,118 @@
+package org.uic.barcode.test;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.uic.barcode.asn1.uper.UperEncoder;
+import org.uic.barcode.dynamicContent.api.DynamicContentCoder;
+import org.uic.barcode.dynamicContent.api.IUicDynamicContent;
+import org.uic.barcode.dynamicContent.api.SimpleUicDynamicContent;
+import org.uic.barcode.ticket.EncodingFormatException;
+import org.uic.barcode.ticket.api.impl.SimpleExtension;
+import org.uic.barcode.ticket.api.impl.SimpleGeoCoordinate;
+import org.uic.barcode.ticket.api.spec.IExtension;
+import org.uic.barcode.ticket.api.spec.IGeoCoordinate;
+
+public class DynamicContentCoderTest {
+
+ IUicDynamicContent content = null;
+
+ @Before public void initialize() {
+
+ content = new SimpleUicDynamicContent();
+
+ content.setAppId("appID");
+
+ content.setChallengeString("challenge string");
+
+ IExtension e = new SimpleExtension();
+ e.setId("challenge_extension_id1");
+ e.setBinarydata(UperEncoder.bytesFromHexString("82DA"));
+ content.setExtension(e);
+
+ IExtension e1 = new SimpleExtension();
+ e1.setId("challenge_extension_id1");
+ e1.setBinarydata(UperEncoder.bytesFromHexString("82DA"));
+ content.addDynamicContentResponse(e1);
+
+ content.setPhoneIdHash(UperEncoder.bytesFromHexString("83DA"));
+
+ content.setPassIdHash(UperEncoder.bytesFromHexString("84DA"));
+
+ IGeoCoordinate g = new SimpleGeoCoordinate();
+ g.setLongitude( 12345L);
+ g.setLatitude( 56789L);
+ content.setGeoCoordinate(g);
+
+ try {
+ content.setTimeStamp(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.04-12:30" ));
+ } catch (ParseException e2) {
+ //
+ }
+
+ }
+
+ @Test public void testDynamicContentEncoding() {
+
+
+ byte[] encodedBytes = null;
+ try {
+ encodedBytes = DynamicContentCoder.encode(content, null);
+ } catch (EncodingFormatException e) {
+ assert(false);
+ }
+
+ String encoding = UperEncoder.hexStringFromBytes(encodedBytes);
+
+ String expectedEncoding = "7C170F0E12620F9437000230390300DDD504017A20C6D0C2D8D8CADCCECA40E6E8E4D2DCCE2F8F461D9B32EECF96FE5F1D32EEE7A77EEBFA72310282DA05E1A37EECA0507B409C30F3E60509B42F8F461D9B32EECF96FE5F1D32EEE7A77EEBFA72310282DA";
+
+ assert(expectedEncoding.equals(encoding));
+
+ }
+
+ @Test public void testDynamicContentDecoding() {
+
+ String encoding = "7C170F0E12620F9437000230390300DDD504017A20C6D0C2D8D8CADCCECA40E6E8E4D2DCCE2F8F461D9B32EECF96FE5F1D32EEE7A77EEBFA72310282DA05E1A37EECA0507B409C30F3E60509B42F8F461D9B32EECF96FE5F1D32EEE7A77EEBFA72310282DA";
+
+ IUicDynamicContent content = DynamicContentCoder.decode(UperEncoder.bytesFromHexString(encoding));
+
+
+ assert("appID".equals(content.getAppId()));
+
+ assert("challenge string".equals(content.getChallengeString()));
+
+ IExtension e1 = content.getExtension();
+ assert(UperEncoder.hexStringFromBytes(e1.getBinarydata()).equals("82DA"));
+ assert(e1.getId().equals("challenge_extension_id1"));
+
+
+ assert(content.getChallengeString().equals("challenge string"));
+
+ byte[] ce = null;
+ for (IExtension e : content.getDynamicContentResponseList()) {
+ if (e.getId().equals("challenge_extension_id1")) {
+ ce = e.getBinarydata();
+ }
+ }
+ assert(UperEncoder.hexStringFromBytes(ce).equals("82DA"));
+
+ assert(UperEncoder.hexStringFromBytes(content.getPhoneIdHash()).equals("83DA"));
+
+ assert(UperEncoder.hexStringFromBytes(content.getPassIdHash()).equals("84DA"));
+
+ assert(content.getGeoCoordinate() != null);
+ assert(content.getGeoCoordinate().getLongitude() == 12345L);
+ assert(content.getGeoCoordinate().getLatitude() == 56789L);
+
+ assert(content.getTimeStamp() != null);
+
+ assert(content.getTimeStamp().toString().equals("Wed Dec 15 12:30:00 CET 2021" ));
+
+
+ }
+
+
+
+}