summaryrefslogtreecommitdiffstats
path: root/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/uic/barcode/test/DynamicContentCoderTest.java2
-rw-r--r--src/test/java/org/uic/barcode/test/DynamicFrameDoubleSignatureProviderSelectionTest.java10
-rw-r--r--src/test/java/org/uic/barcode/test/DynamicFrameDoubleSignatureTest.java10
-rw-r--r--src/test/java/org/uic/barcode/test/DynamicFrameDynamicContentTest.java7
-rw-r--r--src/test/java/org/uic/barcode/test/DynamicFrameFcbVersion1Test.java8
-rw-r--r--src/test/java/org/uic/barcode/test/DynamicFrameFcbVersion3Test.java6
-rw-r--r--src/test/java/org/uic/barcode/test/DynamicFrameLOwLevelTest.java2
-rw-r--r--src/test/java/org/uic/barcode/test/utils/Level2TestDataFactory.java10
-rw-r--r--src/test/java/org/uic/barcode/test/utils/SimpleDynamicFrameTestBarcode.java24
9 files changed, 44 insertions, 35 deletions
diff --git a/src/test/java/org/uic/barcode/test/DynamicContentCoderTest.java b/src/test/java/org/uic/barcode/test/DynamicContentCoderTest.java
index 10963c5..5355d5d 100644
--- a/src/test/java/org/uic/barcode/test/DynamicContentCoderTest.java
+++ b/src/test/java/org/uic/barcode/test/DynamicContentCoderTest.java
@@ -108,7 +108,7 @@ public class DynamicContentCoderTest {
assert(content.getTimeStamp() != null);
- assert(content.getTimeStamp().toString().equals("Wed Dec 15 12:30:00 CET 2021" ));
+ assert(content.getTimeStamp().toString().contains("04 12:30:00 CET"));
}
diff --git a/src/test/java/org/uic/barcode/test/DynamicFrameDoubleSignatureProviderSelectionTest.java b/src/test/java/org/uic/barcode/test/DynamicFrameDoubleSignatureProviderSelectionTest.java
index 84f7795..0730e69 100644
--- a/src/test/java/org/uic/barcode/test/DynamicFrameDoubleSignatureProviderSelectionTest.java
+++ b/src/test/java/org/uic/barcode/test/DynamicFrameDoubleSignatureProviderSelectionTest.java
@@ -22,7 +22,7 @@ import org.junit.Test;
import org.uic.barcode.Decoder;
import org.uic.barcode.Encoder;
import org.uic.barcode.dynamicFrame.Constants;
-import org.uic.barcode.dynamicFrame.DataType;
+import org.uic.barcode.dynamicFrame.api.IData;
import org.uic.barcode.test.utils.Level2TestDataFactory;
import org.uic.barcode.test.utils.SimpleUICTestTicket;
import org.uic.barcode.ticket.EncodingFormatException;
@@ -93,7 +93,7 @@ public class DynamicFrameDoubleSignatureProviderSelectionTest {
assert(enc != null);
- DataType level2Data = Level2TestDataFactory.getLevel2SimpleTestData();
+ IData level2Data = Level2TestDataFactory.getLevel2SimpleTestData();
try {
enc.setLevel2Data(level2Data);
enc.signLevel2(keyPairLevel2.getPrivate(),prov);
@@ -135,15 +135,15 @@ public class DynamicFrameDoubleSignatureProviderSelectionTest {
signatureCheck = 0;
try {
signatureCheck = dec.validateLevel2(prov);
- } catch (IllegalArgumentException | UnsupportedOperationException e) {
+ } catch (Exception e) {
assert(false);
}
assert(signatureCheck == Constants.LEVEL2_VALIDATION_OK);
- DataType level2DataDec = dec.getLevel2Data();
+ IData level2DataDec = dec.getLevel2Data();
assert(level2Data.getFormat().equals(level2DataDec.getFormat()));
- assert(Arrays.equals(level2Data.getData().toByteArray(),level2DataDec.getData().toByteArray()));
+ assert(Arrays.equals(level2Data.getData(),level2DataDec.getData()));
SimpleUICTestTicket.compare(ticket, dec.getUicTicket());
diff --git a/src/test/java/org/uic/barcode/test/DynamicFrameDoubleSignatureTest.java b/src/test/java/org/uic/barcode/test/DynamicFrameDoubleSignatureTest.java
index a316cfc..787ebae 100644
--- a/src/test/java/org/uic/barcode/test/DynamicFrameDoubleSignatureTest.java
+++ b/src/test/java/org/uic/barcode/test/DynamicFrameDoubleSignatureTest.java
@@ -21,7 +21,7 @@ import org.junit.Test;
import org.uic.barcode.Decoder;
import org.uic.barcode.Encoder;
import org.uic.barcode.dynamicFrame.Constants;
-import org.uic.barcode.dynamicFrame.DataType;
+import org.uic.barcode.dynamicFrame.api.IData;
import org.uic.barcode.test.utils.Level2TestDataFactory;
import org.uic.barcode.test.utils.SimpleUICTestTicket;
import org.uic.barcode.ticket.EncodingFormatException;
@@ -89,7 +89,7 @@ public class DynamicFrameDoubleSignatureTest {
assert(enc != null);
- DataType level2Data = Level2TestDataFactory.getLevel2SimpleTestData();
+ IData level2Data = Level2TestDataFactory.getLevel2SimpleTestData();
try {
enc.setLevel2Data(level2Data);
enc.signLevel2(keyPairLevel2.getPrivate());
@@ -131,15 +131,15 @@ public class DynamicFrameDoubleSignatureTest {
signatureCheck = 0;
try {
signatureCheck = dec.validateLevel2();
- } catch (IllegalArgumentException | UnsupportedOperationException e) {
+ } catch (Exception e) {
assert(false);
}
assert(signatureCheck == Constants.LEVEL2_VALIDATION_OK);
- DataType level2DataDec = dec.getLevel2Data();
+ IData level2DataDec = dec.getLevel2Data();
assert(level2Data.getFormat().equals(level2DataDec.getFormat()));
- assert(Arrays.equals(level2Data.getData().toByteArray(),level2DataDec.getData().toByteArray()));
+ assert(Arrays.equals(level2Data.getData(),level2DataDec.getData()));
SimpleUICTestTicket.compare(ticket, dec.getUicTicket());
diff --git a/src/test/java/org/uic/barcode/test/DynamicFrameDynamicContentTest.java b/src/test/java/org/uic/barcode/test/DynamicFrameDynamicContentTest.java
index a5f91ca..4cfca12 100644
--- a/src/test/java/org/uic/barcode/test/DynamicFrameDynamicContentTest.java
+++ b/src/test/java/org/uic/barcode/test/DynamicFrameDynamicContentTest.java
@@ -24,6 +24,7 @@ import org.junit.Before;
import org.junit.Test;
import org.uic.barcode.Decoder;
import org.uic.barcode.Encoder;
+import org.uic.barcode.dynamicContent.api.IUicDynamicContent;
import org.uic.barcode.dynamicContent.fdc1.GeoCoordinateType;
import org.uic.barcode.dynamicContent.fdc1.TimeStamp;
import org.uic.barcode.dynamicContent.fdc1.UicDynamicContentDataFDC1;
@@ -217,7 +218,7 @@ public class DynamicFrameDynamicContentTest {
assert(level2check == Constants.LEVEL2_VALIDATION_OK);
- UicDynamicContentDataFDC1 dynamicData = dec.getDynamicHeader().getDynamicDataFDC1();
+ IUicDynamicContent dynamicData = dec.getDynamicHeader().getDynamicContent();
assert(dynamicData.getChallengeString().equals("CHALLENGE"));
@@ -228,9 +229,9 @@ public class DynamicFrameDynamicContentTest {
assert(Arrays.equals(dynamicData.getPhoneIdHash(),phoneIdHash));
assert(dynamicData.getGeoCoordinate().getLatitude() == 123456L);
- assert(dynamicData.getGeoCoordinate().getLongitude() == 823456L);
+ assert(dynamicData.getGeoCoordinate().getLongitude() == 103456L);
- Date timeStamp = dynamicData.getTimeStamp().getTimeAsDate();
+ Date timeStamp = dynamicData.getTimeStamp();
ZonedDateTime retrievedTimeStamp = timeStamp.toInstant().atZone(ZoneId.of("UTC"));
long diff = ChronoUnit.SECONDS.between(originalTimeStamp, retrievedTimeStamp);
diff --git a/src/test/java/org/uic/barcode/test/DynamicFrameFcbVersion1Test.java b/src/test/java/org/uic/barcode/test/DynamicFrameFcbVersion1Test.java
index 63ba68e..861fc85 100644
--- a/src/test/java/org/uic/barcode/test/DynamicFrameFcbVersion1Test.java
+++ b/src/test/java/org/uic/barcode/test/DynamicFrameFcbVersion1Test.java
@@ -20,6 +20,7 @@ import org.junit.Test;
import org.uic.barcode.Decoder;
import org.uic.barcode.Encoder;
import org.uic.barcode.dynamicFrame.Constants;
+import org.uic.barcode.dynamicFrame.api.IData;
import org.uic.barcode.test.utils.SimpleUICTestTicket;
import org.uic.barcode.ticket.EncodingFormatException;
import org.uic.barcode.ticket.api.spec.IUicRailTicket;
@@ -144,9 +145,10 @@ public class DynamicFrameFcbVersion1Test {
assert(dec.getDynamicHeader().getFormat().equals("U1"));
- assert(dec.getDynamicHeader().getLevel2SignedData().getLevel1Data().getData().get(0).getFormat().equals("FCB1"));
-
-
+ for (IData data : dec.getDynamicHeader().getLevel2Data().getLevel1Data().getData()) {
+ assert(data.getFormat().equals("FCB1") );
+ }
+
SimpleUICTestTicket.compare(ticket, dec.getUicTicket());
diff --git a/src/test/java/org/uic/barcode/test/DynamicFrameFcbVersion3Test.java b/src/test/java/org/uic/barcode/test/DynamicFrameFcbVersion3Test.java
index 4f0897e..fa055dc 100644
--- a/src/test/java/org/uic/barcode/test/DynamicFrameFcbVersion3Test.java
+++ b/src/test/java/org/uic/barcode/test/DynamicFrameFcbVersion3Test.java
@@ -20,6 +20,7 @@ import org.junit.Test;
import org.uic.barcode.Decoder;
import org.uic.barcode.Encoder;
import org.uic.barcode.dynamicFrame.Constants;
+import org.uic.barcode.dynamicFrame.api.IData;
import org.uic.barcode.test.utils.SimpleUICTestTicket;
import org.uic.barcode.ticket.EncodingFormatException;
import org.uic.barcode.ticket.api.spec.IUicRailTicket;
@@ -144,8 +145,9 @@ public class DynamicFrameFcbVersion3Test {
assert(dec.getDynamicHeader().getFormat().equals("U1"));
- assert(dec.getDynamicHeader().getLevel2SignedData().getLevel1Data().getData().get(0).getFormat().equals("FCB3"));
-
+ for (IData data : dec.getDynamicHeader().getLevel2Data().getLevel1Data().getData()) {
+ assert(data.getFormat().equals("FCB3") );
+ }
SimpleUICTestTicket.compare(ticket, dec.getUicTicket());
diff --git a/src/test/java/org/uic/barcode/test/DynamicFrameLOwLevelTest.java b/src/test/java/org/uic/barcode/test/DynamicFrameLOwLevelTest.java
index 5dd9668..d354837 100644
--- a/src/test/java/org/uic/barcode/test/DynamicFrameLOwLevelTest.java
+++ b/src/test/java/org/uic/barcode/test/DynamicFrameLOwLevelTest.java
@@ -21,7 +21,7 @@ import org.junit.Before;
import org.junit.Test;
import org.uic.barcode.asn1.uper.UperEncoder;
import org.uic.barcode.dynamicFrame.Constants;
-import org.uic.barcode.dynamicFrame.DynamicFrame;
+import org.uic.barcode.dynamicFrame.v1.DynamicFrame;
import org.uic.barcode.test.utils.SimpleDynamicFrameTestBarcode;
public class DynamicFrameLOwLevelTest {
diff --git a/src/test/java/org/uic/barcode/test/utils/Level2TestDataFactory.java b/src/test/java/org/uic/barcode/test/utils/Level2TestDataFactory.java
index b1eb0f5..bdabdc6 100644
--- a/src/test/java/org/uic/barcode/test/utils/Level2TestDataFactory.java
+++ b/src/test/java/org/uic/barcode/test/utils/Level2TestDataFactory.java
@@ -1,17 +1,17 @@
package org.uic.barcode.test.utils;
-import org.uic.barcode.asn1.datatypesimpl.OctetString;
-import org.uic.barcode.dynamicFrame.DataType;
+import org.uic.barcode.dynamicFrame.api.IData;
+import org.uic.barcode.dynamicFrame.api.SimpleData;
public class Level2TestDataFactory {
- public static DataType getLevel2SimpleTestData() {
+ public static IData getLevel2SimpleTestData() {
String testContent = "2020.10.01T12:12.20";
- DataType level2Data = new DataType();
+ IData level2Data = new SimpleData();
level2Data.setFormat("TEST");
- level2Data.setData(new OctetString(testContent.getBytes()));
+ level2Data.setData(testContent.getBytes());
return level2Data;
}
diff --git a/src/test/java/org/uic/barcode/test/utils/SimpleDynamicFrameTestBarcode.java b/src/test/java/org/uic/barcode/test/utils/SimpleDynamicFrameTestBarcode.java
index 0060fcd..f2ef0f3 100644
--- a/src/test/java/org/uic/barcode/test/utils/SimpleDynamicFrameTestBarcode.java
+++ b/src/test/java/org/uic/barcode/test/utils/SimpleDynamicFrameTestBarcode.java
@@ -1,28 +1,27 @@
package org.uic.barcode.test.utils;
import java.security.KeyPair;
+import java.security.Signature;
+import org.uic.barcode.asn1.uper.UperEncoder;
import org.uic.barcode.dynamicFrame.Constants;
-import org.uic.barcode.dynamicFrame.DataType;
-import org.uic.barcode.dynamicFrame.DynamicFrame;
-import org.uic.barcode.dynamicFrame.Level1DataType;
-import org.uic.barcode.dynamicFrame.Level2DataType;
-import org.uic.barcode.dynamicFrame.SequenceOfDataType;
+import org.uic.barcode.dynamicFrame.v1.DataType;
+import org.uic.barcode.dynamicFrame.v1.DynamicFrame;
+import org.uic.barcode.dynamicFrame.v1.Level1DataType;
+import org.uic.barcode.dynamicFrame.v1.Level2DataType;
+import org.uic.barcode.dynamicFrame.v1.SequenceOfDataType;
import org.uic.barcode.ticket.EncodingFormatException;
import org.uic.barcode.ticket.api.asn.omv1.UicRailTicketData;
import org.uic.barcode.ticket.api.test.testtickets.SimpleUicTestTicket;
+import org.uic.barcode.utils.AlgorithmNameResolver;
public class SimpleDynamicFrameTestBarcode {
public static DynamicFrame getSimpleDynamicHeaderBarcode(String algorithm, KeyPair keyPair) {
-
-
DynamicFrame barcode = null;
-
-
try {
barcode = new DynamicFrame();
barcode.setFormat(Constants.DYNAMIC_BARCODE_FORMAT_DEFAULT);
@@ -47,7 +46,12 @@ public class SimpleDynamicFrameTestBarcode {
level1Data.getData().add(data);
try {
- level2Data.signLevel1(keyPair.getPrivate());
+ String algo = AlgorithmNameResolver.getSignatureAlgorithmName(level1Data.getLevel1SigningAlg());
+ Signature sig = Signature.getInstance(algo);
+ sig.initSign(keyPair.getPrivate());
+ byte[] data2 = UperEncoder.encode(level1Data);
+ sig.update(data2);
+ level2Data.setLevel1Signature(sig.sign());
} catch (Exception e) {
assert(false);
}