summaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
authorCGantert345 <57003061+CGantert345@users.noreply.github.com>2021-11-25 16:39:28 +0100
committerGitHub <noreply@github.com>2021-11-25 16:39:28 +0100
commitc9f27f2de9b3fa713d10cb2f8014aad4e8af3070 (patch)
treeca00d8bae19bfcb5d7d55b388b568136ea62b57d /src/main/java
parentMerge pull request #34 from UnionInternationalCheminsdeFer/1.2.7 (diff)
parenttest and bug fix on countermark and viaStation (diff)
downloadUIC-barcode-c9f27f2de9b3fa713d10cb2f8014aad4e8af3070.tar
UIC-barcode-c9f27f2de9b3fa713d10cb2f8014aad4e8af3070.tar.gz
UIC-barcode-c9f27f2de9b3fa713d10cb2f8014aad4e8af3070.tar.bz2
UIC-barcode-c9f27f2de9b3fa713d10cb2f8014aad4e8af3070.tar.lz
UIC-barcode-c9f27f2de9b3fa713d10cb2f8014aad4e8af3070.tar.xz
UIC-barcode-c9f27f2de9b3fa713d10cb2f8014aad4e8af3070.tar.zst
UIC-barcode-c9f27f2de9b3fa713d10cb2f8014aad4e8af3070.zip
Diffstat (limited to '')
-rw-r--r--src/main/java/org/uic/barcode/Decoder.java2
-rw-r--r--src/main/java/org/uic/barcode/Encoder.java8
-rw-r--r--src/main/java/org/uic/barcode/asn1/datatypes/Alphabet.java1
-rw-r--r--src/main/java/org/uic/barcode/asn1/datatypes/AlphabetBuilder.java32
-rw-r--r--src/main/java/org/uic/barcode/asn1/datatypes/Bitstring.java2
-rw-r--r--src/main/java/org/uic/barcode/asn1/datatypes/Optional.java96
-rw-r--r--src/main/java/org/uic/barcode/asn1/uper/BigIntCoder.java97
-rw-r--r--src/main/java/org/uic/barcode/asn1/uper/BitStringCoder.java50
-rw-r--r--src/main/java/org/uic/barcode/asn1/uper/UperEncoder.java13
-rw-r--r--src/main/java/org/uic/barcode/dynamicContent/fdc1/TimeStamp.java63
-rw-r--r--src/main/java/org/uic/barcode/dynamicContent/fdc1/UicDynamicContentDataFDC1.java4
-rw-r--r--src/main/java/org/uic/barcode/dynamicFrame/Constants.java1
-rw-r--r--src/main/java/org/uic/barcode/dynamicFrame/DataType.java2
-rw-r--r--src/main/java/org/uic/barcode/dynamicFrame/DynamicFrame.java6
-rw-r--r--src/main/java/org/uic/barcode/dynamicFrame/Level1DataType.java2
-rw-r--r--src/main/java/org/uic/barcode/ticket/UicRailTicketCoder.java2
-rw-r--r--src/main/java/org/uic/barcode/ticket/api/asn/omv1/CountermarkData.java6
-rw-r--r--src/main/java/org/uic/barcode/ticket/api/asn/omv1/ViaStationType.java2
-rw-r--r--src/main/java/org/uic/barcode/ticket/api/asn/omv2/CountermarkData.java6
-rw-r--r--src/main/java/org/uic/barcode/ticket/api/asn/omv2/ViaStationType.java2
-rw-r--r--src/main/java/org/uic/barcode/ticket/api/asn/omv3/CountermarkData.java6
-rw-r--r--src/main/java/org/uic/barcode/ticket/api/asn/omv3/ViaStationType.java2
-rw-r--r--src/main/java/org/uic/barcode/ticket/api/spec/uicBarcodeHeader0.1.asn151
23 files changed, 88 insertions, 468 deletions
diff --git a/src/main/java/org/uic/barcode/Decoder.java b/src/main/java/org/uic/barcode/Decoder.java
index 09ee839..9f102d3 100644
--- a/src/main/java/org/uic/barcode/Decoder.java
+++ b/src/main/java/org/uic/barcode/Decoder.java
@@ -172,6 +172,8 @@ public class Decoder {
uicTicket = uicTicketCoder.decodeFromAsn(level1Content.getByteData(), 1);
} else if (level1Content.getFormat().equals("FCB2")) {
uicTicket = uicTicketCoder.decodeFromAsn(level1Content.getByteData(), 2);
+ } else if (level1Content.getFormat().equals("FCB3")) {
+ uicTicket = uicTicketCoder.decodeFromAsn(level1Content.getByteData(), 3);
}
}
diff --git a/src/main/java/org/uic/barcode/Encoder.java b/src/main/java/org/uic/barcode/Encoder.java
index e906881..f0f8d14 100644
--- a/src/main/java/org/uic/barcode/Encoder.java
+++ b/src/main/java/org/uic/barcode/Encoder.java
@@ -100,7 +100,13 @@ public class Encoder {
DataType ticketData = new DataType();
UicRailTicketCoder uicTicketCoder = new UicRailTicketCoder();
- ticketData.setFormat(Constants.DATA_TYPE_FCB_VERSION_1);
+ if (fcbVersion == 1 || fcbVersion == 13) {
+ ticketData.setFormat(Constants.DATA_TYPE_FCB_VERSION_1);
+ } else if (fcbVersion == 2) {
+ ticketData.setFormat(Constants.DATA_TYPE_FCB_VERSION_2);
+ } else if (fcbVersion == 3) {
+ ticketData.setFormat(Constants.DATA_TYPE_FCB_VERSION_3);
+ }
ticketData.setData(new OctetString(uicTicketCoder.encode(ticket, fcbVersion)));
dynamicFrame.getLevel2SignedData().getLevel1Data().getData().add(ticketData);
diff --git a/src/main/java/org/uic/barcode/asn1/datatypes/Alphabet.java b/src/main/java/org/uic/barcode/asn1/datatypes/Alphabet.java
index 2b153ae..0202e16 100644
--- a/src/main/java/org/uic/barcode/asn1/datatypes/Alphabet.java
+++ b/src/main/java/org/uic/barcode/asn1/datatypes/Alphabet.java
@@ -3,7 +3,6 @@ package org.uic.barcode.asn1.datatypes;
/**
* Alphabet class for Restricted Strings.
*
- * Use {@link AlphabetBuilder} for convenient construction of restriction alphabets.
*/
public abstract class Alphabet {
diff --git a/src/main/java/org/uic/barcode/asn1/datatypes/AlphabetBuilder.java b/src/main/java/org/uic/barcode/asn1/datatypes/AlphabetBuilder.java
deleted file mode 100644
index b768897..0000000
--- a/src/main/java/org/uic/barcode/asn1/datatypes/AlphabetBuilder.java
+++ /dev/null
@@ -1,32 +0,0 @@
-package org.uic.barcode.asn1.datatypes;
-
-
-public class AlphabetBuilder {
-
- private final StringBuilder sb = new StringBuilder();
-
- public AlphabetBuilder() {}
-
- public String chars() {
- return sb.toString();
- }
-
- public AlphabetBuilder withRange(char from, char to) {
- for (char c = from; c <= to; c++) {
- sb.append(c);
- }
- return this;
- }
-
- public AlphabetBuilder withChars(String str) {
- sb.append(str);
- return this;
- }
-
- public AlphabetBuilder withChars(Character... chars) {
- for (char c : chars) {
- sb.append(c);
- }
- return this;
- }
-}
diff --git a/src/main/java/org/uic/barcode/asn1/datatypes/Bitstring.java b/src/main/java/org/uic/barcode/asn1/datatypes/Bitstring.java
index 1543f64..4771931 100644
--- a/src/main/java/org/uic/barcode/asn1/datatypes/Bitstring.java
+++ b/src/main/java/org/uic/barcode/asn1/datatypes/Bitstring.java
@@ -9,7 +9,7 @@ import java.lang.annotation.Target;
* In UPER, a SEQUENCE OF Booleans would look exactly as bitstring, so this annotation can be
* omitted for {@code List<Boolean>}.
*/
-@Target({ElementType.TYPE})
+@Target({ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
public @interface Bitstring {
diff --git a/src/main/java/org/uic/barcode/asn1/datatypes/Optional.java b/src/main/java/org/uic/barcode/asn1/datatypes/Optional.java
deleted file mode 100644
index 757ba29..0000000
--- a/src/main/java/org/uic/barcode/asn1/datatypes/Optional.java
+++ /dev/null
@@ -1,96 +0,0 @@
-package org.uic.barcode.asn1.datatypes;
-
-import java.util.NoSuchElementException;
-import java.util.Objects;
-
-/** Represents optional values.
- *
- * Should be replaced by java.util.Optional from Java 8, when project moves to Java 8.
- *
- * @param <T> type of contained elements */
-public class Optional<T> {
-
- private final T element;
- private final boolean isPresent;
-
- private Optional(T element, boolean isPresent) {
- this.element = element;
- this.isPresent = isPresent;
- }
-
- /** @return true if the Option contains a value */
- public boolean isPresent() {
- return isPresent;
- }
-
- /** @return the element if the option is not empty
- * @throws java.util.NoSuchElementException if the option is empty */
- public T get() {
- if (isPresent) {
- return element;
- } else {
- throw new NoSuchElementException("None.get");
- }
- }
-
- /** @return the value, if present, otherwise return {@code other}
- * @param other the value to be returned if there is no value present */
- public T orElse(T other) {
- return isPresent() ? get() : other;
- }
-
- /**
- * Indicates whether some other object is "equal to" this Optional. The
- * other object is considered equal if:
- * <ul>
- * <li>it is also an {@code Optional} and;
- * <li>both instances have no value present or;
- * <li>the present values are "equal to" each other via {@code equals()}.
- * </ul>
- *
- * @param obj an object to be tested for equality
- * @return {code true} if the other object is "equal to" this object
- * otherwise {@code false}
- */
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
-
- if (!(obj instanceof Optional)) {
- return false;
- }
-
- Optional<?> other = (Optional<?>) obj;
- return Objects.equals(element, other.element);
- }
-
- /**
- * Returns the hash code value of the present value, if any, or 0 (zero) if
- * no value is present.
- *
- * @return hash code value of the present value or 0 if no value is present
- */
- @Override
- public int hashCode() {
- return Objects.hashCode(element);
- }
-
- /** Returns an Option containing the value.
- *
- * @param <A> the type of the value
- * @param element contained value
- * @return a new Option that contains the value */
- public static <A> Optional<A> of(final A element) {
- return new Optional<A>(element, true);
- }
-
- /** Returns an empty option.
- *
- * @param <A>
- * @return an empty Option */
- public static <A> Optional<A> empty() {
- return new Optional<A>(null, false);
- }
-}
diff --git a/src/main/java/org/uic/barcode/asn1/uper/BigIntCoder.java b/src/main/java/org/uic/barcode/asn1/uper/BigIntCoder.java
deleted file mode 100644
index 94e4b05..0000000
--- a/src/main/java/org/uic/barcode/asn1/uper/BigIntCoder.java
+++ /dev/null
@@ -1,97 +0,0 @@
-package org.uic.barcode.asn1.uper;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Field;
-import java.math.BigInteger;
-
-import org.uic.barcode.asn1.datatypes.Asn1BigInteger;
-import org.uic.barcode.asn1.datatypes.Asn1Default;
-import org.uic.barcode.asn1.datatypes.IntRange;
-
-class BigIntCoder implements Encoder, Decoder {
-
- @Override public <T> boolean canDecode(Class<T> classOfT, Annotation[] extraAnnotations) {
- return Asn1BigInteger.class.isAssignableFrom(classOfT);
- }
-
- @Override public <T> T decode(BitBuffer bitbuffer,
- Class<T> classOfT, Field f,
- Annotation[] extraAnnotations) {
- AnnotationStore annotations = new AnnotationStore(classOfT.getAnnotations(),
- extraAnnotations);
-
- String pos = String.format("%d.%d", bitbuffer.position()/8 , bitbuffer.position() % 8);
- UperEncoder.logger.debug(String.format("Position %s BIG INT",pos));
- IntRange intRange = annotations.getAnnotation(IntRange.class);
- if (intRange != null && intRange.maxValue() > 0) {
- throw new UnsupportedOperationException("Big int with upper range is not supported yet");
- }
-
- int lengthInOctets = (int) UperEncoder.decodeLengthDeterminant(bitbuffer);
- BitBuffer valueBits = ByteBitBuffer.allocate(lengthInOctets * 8);
- for (int i = 0; i < lengthInOctets * 8; i++) {
- valueBits.put(bitbuffer.get());
- }
- valueBits.flip();
- BigInteger resultValue = new BigInteger(+1, valueBits.array());
- UperEncoder.logger.debug(String.format("big int Decoded as %s", resultValue));
-
-
- //CG support for int range
- if (intRange != null){
- resultValue.add(BigInteger.valueOf(intRange.minValue()));
- }
-
-
- return UperEncoder.instantiate(classOfT, resultValue);
- }
-
- @Override public <T> boolean canEncode(T obj, Annotation[] extraAnnotations) {
- return obj instanceof Asn1BigInteger;
- }
-
- @Override public <T> void encode(BitBuffer bitbuffer, T obj, Annotation[] extraAnnotations) throws Asn1EncodingException {
- Class<?> type = obj.getClass();
- AnnotationStore annotations = new AnnotationStore(type.getAnnotations(), extraAnnotations);
- IntRange range = annotations.getAnnotation(IntRange.class);
-
- //CG implementation with lower range limit added
- BigInteger bint = ((Asn1BigInteger) obj).toBigInteger();
- if (range != null) {
- throw new UnsupportedOperationException("Asn1 BigInteger with range is not supported");
- }
- byte[] array = bint.toByteArray();
- int lengthInOctets = array.length;
- int position1 = bitbuffer.position();
- try {
- UperEncoder.encodeLengthDeterminant(bitbuffer, lengthInOctets);
- } catch (Asn1EncodingException e) {
- throw new Asn1EncodingException(" length determinant of " + type.getName(), e);
- }
- int position2 = bitbuffer.position();
- for (byte b : array) {
- bitbuffer.putByte(b);
- }
- UperEncoder.logger.debug(String.format("Big Int(%s): len %s, val %s", obj,
- bitbuffer.toBooleanString(position1, position2 - position1),
- bitbuffer.toBooleanStringFromPosition(position2)));
- return;
- }
-
- @Override
- public <T> T getDefault(Class<T> classOfT, Annotation[] extraAnnotations) {
- AnnotationStore annotations = new AnnotationStore(classOfT.getAnnotations(), extraAnnotations);
- Asn1Default defaultAnnotation = annotations.getAnnotation(Asn1Default.class);
- if (defaultAnnotation == null) return null;
- //check whether the class has a constructor for numeric types
- String valueString = defaultAnnotation.value();
- long value = Long.parseLong(valueString);
- UperEncoder.logger.debug(String.format("Default INTEGER: %d",value ));
-
- @SuppressWarnings("unchecked")
- T t = (T) new Asn1BigInteger(value);
- return t;
-
- }
-
-} \ No newline at end of file
diff --git a/src/main/java/org/uic/barcode/asn1/uper/BitStringCoder.java b/src/main/java/org/uic/barcode/asn1/uper/BitStringCoder.java
index ba1692c..19aac9b 100644
--- a/src/main/java/org/uic/barcode/asn1/uper/BitStringCoder.java
+++ b/src/main/java/org/uic/barcode/asn1/uper/BitStringCoder.java
@@ -4,12 +4,12 @@ import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.util.List;
import org.uic.barcode.asn1.datatypes.Asn1VarSizeBitstring;
import org.uic.barcode.asn1.datatypes.Bitstring;
import org.uic.barcode.asn1.datatypes.FixedSize;
import org.uic.barcode.asn1.datatypes.SizeRange;
-import org.uic.barcode.asn1.uper.UperEncoder.Asn1ContainerFieldSorter;
class BitStringCoder implements Decoder, Encoder {
@@ -29,18 +29,24 @@ class BitStringCoder implements Decoder, Encoder {
throw new UnsupportedOperationException(
"Bitstring with extensions is not implemented yet");
}
- FixedSize size = type.getAnnotation(FixedSize.class);
+ FixedSize size = annotations.getAnnotation(FixedSize.class);
int position = bitbuffer.position();
if (size != null) {
- Asn1ContainerFieldSorter sorter = new Asn1ContainerFieldSorter(type);
- if (sorter.ordinaryFields.size() != size.value()) { throw new AssertionError(
+ if (!List.class.isAssignableFrom(type)) {
+ throw new AssertionError("Field should be a list of booleans!");
+ }
+
+ List<Boolean> list = (List<Boolean>)obj;
+ if (list.size() != size.value()) {
+ throw new AssertionError(
"Declared size (" + size.value() +
- ") and number of fields (" + sorter.ordinaryFields.size() +
- ") do not match!"); }
- for (Field f : sorter.ordinaryFields) {
+ ") and number of fields (" + list.size() +
+ ") do not match!");
+ }
+ for (Boolean f : list) {
try {
- bitbuffer.put(f.getBoolean(obj));
- } catch (IllegalArgumentException | IllegalAccessException e) {
+ bitbuffer.put(f);
+ } catch (IllegalArgumentException e) {
throw new IllegalArgumentException("can't encode" + obj, e);
}
}
@@ -100,26 +106,28 @@ class BitStringCoder implements Decoder, Encoder {
if (fixedSize == null) { throw new UnsupportedOperationException(
"bitstrings of non-fixed size that do not extend Asn1VarSizeBitstring are not supported yet");
}
- Asn1ContainerFieldSorter sorter = new Asn1ContainerFieldSorter(classOfT);
- if (fixedSize.value() != sorter.ordinaryFields.size()) { throw new IllegalArgumentException(
- "Fixed size annotation " + fixedSize.value()
- + " does not match the number of fields "
- + sorter.ordinaryFields.size() + " in " + classOfT.getName()); }
if (UperEncoder.hasExtensionMarker(annotations)) {
boolean extensionPresent = bitbuffer.get();
if (extensionPresent) { throw new UnsupportedOperationException(
"extensions in fixed-size bitlist are not supported yet"); }
}
T result = UperEncoder.instantiate(classOfT);
- for (Field f : sorter.ordinaryFields) {
- boolean value = bitbuffer.get();
- UperEncoder.logger.debug(String.format("Field %s set to %s", f.getName(), value));
+
+ Method addBooleanMethod;
+ try {
+ addBooleanMethod = classOfT.getDeclaredMethod("add", Object.class);
+ addBooleanMethod.setAccessible(true);
+ } catch (SecurityException | NoSuchMethodException e) {
+ throw new AssertionError("Can't find/access add " + e);
+ }
+
+ for (int i = 0; i < fixedSize.value(); i++) {
try {
- f.set(result, value);
- } catch (IllegalArgumentException | IllegalAccessException e) {
- throw new IllegalArgumentException("can't decode " + classOfT, e);
+ addBooleanMethod.invoke(result, bitbuffer.get());
+ } catch (IllegalArgumentException | InvocationTargetException | IllegalAccessException e) {
+ throw new IllegalArgumentException("Can't invoke add", e);
}
- }
+ }
return result;
} else {
UperEncoder.logger.debug("Bitlist(var-size)");
diff --git a/src/main/java/org/uic/barcode/asn1/uper/UperEncoder.java b/src/main/java/org/uic/barcode/asn1/uper/UperEncoder.java
index a5ef5c5..bba64e2 100644
--- a/src/main/java/org/uic/barcode/asn1/uper/UperEncoder.java
+++ b/src/main/java/org/uic/barcode/asn1/uper/UperEncoder.java
@@ -162,7 +162,6 @@ public final class UperEncoder {
static {
encoders.add(new IntCoder());
- //encoders.add(new BigIntCoder());
encoders.add(new ByteCoder());
encoders.add(new BooleanCoder());
encoders.add(new SequenceCoder());
@@ -173,7 +172,6 @@ public final class UperEncoder {
encoders.add(new StringCoder());
decoders.add(new IntCoder());
- //decoders.add(new BigIntCoder());
decoders.add(new ByteCoder());
decoders.add(new BooleanCoder());
decoders.add(new SequenceCoder());
@@ -691,17 +689,6 @@ public final class UperEncoder {
return sb.toString();
}
- public static byte[] bytesFromBinaryString(String s) {
- int len = s.length();
- byte[] result = new byte[(len + Byte.SIZE - 1) / Byte.SIZE];
- char c;
- for (int i = 0; i < len; i++)
- if ((c = s.charAt(i)) == '1') result[i / Byte.SIZE] = (byte) (result[i / Byte.SIZE] | (0x80 >>> (i % Byte.SIZE)));
- else if (c != '0')
- throw new IllegalArgumentException();
- return result;
- }
-
private static BitBuffer bitBufferFromBinaryString(String s) {
ByteBitBuffer result = ByteBitBuffer.allocate(s.length());
for (int i = 0; i < s.length(); i++) {
diff --git a/src/main/java/org/uic/barcode/dynamicContent/fdc1/TimeStamp.java b/src/main/java/org/uic/barcode/dynamicContent/fdc1/TimeStamp.java
index 32cce65..ecbb226 100644
--- a/src/main/java/org/uic/barcode/dynamicContent/fdc1/TimeStamp.java
+++ b/src/main/java/org/uic/barcode/dynamicContent/fdc1/TimeStamp.java
@@ -1,16 +1,17 @@
package org.uic.barcode.dynamicContent.fdc1;
import java.time.Instant;
+import java.time.ZoneId;
+import java.time.ZoneOffset;
+import java.time.ZonedDateTime;
import java.time.temporal.ChronoField;
-import java.util.Calendar;
import java.util.Date;
-import java.util.TimeZone;
import org.uic.barcode.asn1.datatypes.FieldOrder;
import org.uic.barcode.asn1.datatypes.IntRange;
import org.uic.barcode.asn1.datatypes.Sequence;
-// TODO: Auto-generated Javadoc
+
/**
* The Class TimeStamp.
*/
@@ -20,16 +21,10 @@ public class TimeStamp {
/*
-- Moment of generation of the dynamic content, expressed in UTC :
- -- * dynamicContentDay is the number of days from issuing date
- -- (UicRailTicketData.issuingDetail.issuingYear and issuingDay)
- -- The range 0..1070 allows a validity equal to that of the validFrom (700) plus
- -- validUntil (370) elements of the different transport documents of UicRailTicketData.
+ -- * dynamicContentDay is the number of day in the year
-- * dynamicContentTime is the number of seconds of the day
-- (from 0 = 0:00:00 to 86399 = 23:59:59)
- -- These two elements shall be either both present, either both absent
- dynamicContentDay INTEGER (0..366),
- *
- */
+ */
@FieldOrder(order = 0)
@IntRange(minValue=1, maxValue=366)
public Long day;
@@ -46,7 +41,7 @@ public class TimeStamp {
* Instantiates a new time stamp and sets the time-stamp to now.
*/
public TimeStamp() {
- Instant now = Instant.now();
+ ZonedDateTime now = ZonedDateTime.now(ZoneId.of("UTC"));
day = new Long(now.get(ChronoField.DAY_OF_YEAR));
secondOfDay = new Long(now.get(ChronoField.SECOND_OF_DAY));
}
@@ -55,7 +50,7 @@ public class TimeStamp {
* Sets the the time-stamp to now.
*/
public void setNow() {
- Instant now = Instant.now();
+ ZonedDateTime now = ZonedDateTime.now(ZoneId.of("UTC"));
day = new Long(now.get(ChronoField.DAY_OF_YEAR));
secondOfDay = new Long(now.get(ChronoField.SECOND_OF_DAY));
}
@@ -102,25 +97,26 @@ public class TimeStamp {
* @return the date and time of content creation in UTC
*/
public Date getTimeAsDate() {
-
- Calendar cal = Calendar.getInstance();
- int dayOfYear = cal.get(Calendar.DAY_OF_YEAR);
-
+
+ ZonedDateTime now = Instant.now().atZone(ZoneOffset.UTC);
+ int dayOfYear = now.getDayOfYear();
+
if (dayOfYear - day.intValue() > 250) {
- cal.add(Calendar.YEAR, 1);
+ now = now.plusDays(1);
}
if (day.intValue() - dayOfYear > 250) {
- cal.add(Calendar.YEAR, -1);
+ now = now.minusDays(1);
}
-
- cal.setTimeZone(TimeZone.getTimeZone("UTC"));
- cal.set(Calendar.SECOND,0);
- cal.set(Calendar.HOUR,0);
- cal.set(Calendar.MINUTE,0);
- cal.set(Calendar.DAY_OF_YEAR, day.intValue());
- cal.add(Calendar.SECOND, secondOfDay.intValue());
+
+ now = now.withDayOfYear(1);
+ now = now.withSecond(0);
+ now = now.withHour(0);
+ now = now.withMinute(0);
+ now = now.withDayOfYear(dayOfYear);
+ now = now.plusSeconds(secondOfDay);
- return cal.getTime();
+ return Date.from(now.toInstant());
+
}
/**
@@ -129,15 +125,14 @@ public class TimeStamp {
* @param dateUTC the current date and time in UTC
*/
public void setDateTime(Date dateUTC) {
-
- Calendar cal = Calendar.getInstance();
- cal.setTime(dateUTC);
- day = Long.valueOf(cal.get(Calendar.DAY_OF_YEAR));
+ ZonedDateTime date = dateUTC.toInstant().atZone(ZoneOffset.UTC);
+
+ day = (long) date.getDayOfYear();
- secondOfDay = (long) cal.get(Calendar.SECOND);
- secondOfDay = secondOfDay + 60 * (long) cal.get(Calendar.MINUTE);
- secondOfDay = secondOfDay + 60 * 60 * (long) cal.get(Calendar.HOUR_OF_DAY);
+ secondOfDay = (long) date.getSecond();
+ secondOfDay = secondOfDay + 60 * (long) date.getMinute();
+ secondOfDay = secondOfDay + 60 * 60 * (long) date.getHour();
}
diff --git a/src/main/java/org/uic/barcode/dynamicContent/fdc1/UicDynamicContentDataFDC1.java b/src/main/java/org/uic/barcode/dynamicContent/fdc1/UicDynamicContentDataFDC1.java
index ae352d1..c658448 100644
--- a/src/main/java/org/uic/barcode/dynamicContent/fdc1/UicDynamicContentDataFDC1.java
+++ b/src/main/java/org/uic/barcode/dynamicContent/fdc1/UicDynamicContentDataFDC1.java
@@ -161,13 +161,13 @@ public class UicDynamicContentDataFDC1 {
return null;
}
- public void setPassIdHash(byte[] phoneIdHash) {
+ public void setPassIdHash(byte[] passIdHash) {
if (extensions == null) {
extensions = new SequenceOfExtension();
};
ExtensionData ed = new ExtensionData();
ed.setExtensionId("pass");
- ed.setExtensionData(phoneIdHash);
+ ed.setExtensionData(passIdHash);
extensions.add(ed);
}
diff --git a/src/main/java/org/uic/barcode/dynamicFrame/Constants.java b/src/main/java/org/uic/barcode/dynamicFrame/Constants.java
index 774475a..8f47986 100644
--- a/src/main/java/org/uic/barcode/dynamicFrame/Constants.java
+++ b/src/main/java/org/uic/barcode/dynamicFrame/Constants.java
@@ -16,6 +16,7 @@ public class Constants {
public static String DATA_TYPE_FCB_VERSION_1 = "FCB1";
public static String DATA_TYPE_FCB_VERSION_2 = "FCB2";
+ public static String DATA_TYPE_FCB_VERSION_3 = "FCB3";
public static String DYNAMIC_BARCODE_FORMAT_DEFAULT = "U1";
diff --git a/src/main/java/org/uic/barcode/dynamicFrame/DataType.java b/src/main/java/org/uic/barcode/dynamicFrame/DataType.java
index 2d6d984..2ea63ca 100644
--- a/src/main/java/org/uic/barcode/dynamicFrame/DataType.java
+++ b/src/main/java/org/uic/barcode/dynamicFrame/DataType.java
@@ -1,6 +1,5 @@
package org.uic.barcode.dynamicFrame;
-import org.uic.barcode.asn1.datatypes.Asn1Default;
import org.uic.barcode.asn1.datatypes.CharacterRestriction;
import org.uic.barcode.asn1.datatypes.RestrictedString;
import org.uic.barcode.asn1.datatypes.Sequence;
@@ -20,7 +19,6 @@ public class DataType {
* -- FCB2 FCB version 2
* -- RICS company code + ...
**/
- @Asn1Default("FCB1")
@RestrictedString(CharacterRestriction.IA5String)
public String format;
diff --git a/src/main/java/org/uic/barcode/dynamicFrame/DynamicFrame.java b/src/main/java/org/uic/barcode/dynamicFrame/DynamicFrame.java
index 6cc1eaa..c74215d 100644
--- a/src/main/java/org/uic/barcode/dynamicFrame/DynamicFrame.java
+++ b/src/main/java/org/uic/barcode/dynamicFrame/DynamicFrame.java
@@ -14,7 +14,6 @@ import java.security.spec.X509EncodedKeySpec;
import org.uic.barcode.asn1.datatypes.Asn1Optional;
import org.uic.barcode.asn1.datatypes.CharacterRestriction;
import org.uic.barcode.asn1.datatypes.FieldOrder;
-import org.uic.barcode.asn1.datatypes.HasExtensionMarker;
import org.uic.barcode.asn1.datatypes.RestrictedString;
import org.uic.barcode.asn1.datatypes.Sequence;
import org.uic.barcode.asn1.datatypesimpl.OctetString;
@@ -29,7 +28,6 @@ import org.uic.barcode.utils.AlgorithmNameResolver;
* Implementation of the Draft under discussion, not final.
*/
@Sequence
-@HasExtensionMarker
public class DynamicFrame extends Object{
public DynamicFrame() {}
@@ -152,7 +150,9 @@ public class DynamicFrame extends Object{
byte[] keyBytes = this.getLevel2SignedData().getLevel1Data().level2publicKey.toByteArray();
X509EncodedKeySpec keySpec = new X509EncodedKeySpec(keyBytes);
key = KeyFactory.getInstance(keyAlgName).generatePublic(keySpec);
- } catch (InvalidKeySpecException | NoSuchAlgorithmException e1) {
+ } catch (InvalidKeySpecException e1) {
+ return Constants.LEVEL2_VALIDATION_KEY_ALG_NOT_IMPLEMENTED;
+ } catch (NoSuchAlgorithmException e1) {
return Constants.LEVEL2_VALIDATION_KEY_ALG_NOT_IMPLEMENTED;
}
diff --git a/src/main/java/org/uic/barcode/dynamicFrame/Level1DataType.java b/src/main/java/org/uic/barcode/dynamicFrame/Level1DataType.java
index aac0188..958cafc 100644
--- a/src/main/java/org/uic/barcode/dynamicFrame/Level1DataType.java
+++ b/src/main/java/org/uic/barcode/dynamicFrame/Level1DataType.java
@@ -34,7 +34,7 @@ public class Level1DataType {
/** The key id. */
@FieldOrder(order = 2)
- @IntRange(minValue=1,maxValue=99999)
+ @IntRange(minValue=0,maxValue=99999)
@Asn1Optional public Long keyId;
diff --git a/src/main/java/org/uic/barcode/ticket/UicRailTicketCoder.java b/src/main/java/org/uic/barcode/ticket/UicRailTicketCoder.java
index e9d2eb4..0586ed4 100644
--- a/src/main/java/org/uic/barcode/ticket/UicRailTicketCoder.java
+++ b/src/main/java/org/uic/barcode/ticket/UicRailTicketCoder.java
@@ -33,7 +33,7 @@ public class UicRailTicketCoder {
public byte[] encode (IUicRailTicket uicRailTicket, int version) throws IOException, EncodingFormatException{
- if (version == 13) {
+ if (version == 13 || version == 1) {
Api2OpenAsnEncoder uicEncoder = new Api2OpenAsnEncoder();
diff --git a/src/main/java/org/uic/barcode/ticket/api/asn/omv1/CountermarkData.java b/src/main/java/org/uic/barcode/ticket/api/asn/omv1/CountermarkData.java
index 76625d4..579342e 100644
--- a/src/main/java/org/uic/barcode/ticket/api/asn/omv1/CountermarkData.java
+++ b/src/main/java/org/uic/barcode/ticket/api/asn/omv1/CountermarkData.java
@@ -72,15 +72,15 @@ public class CountermarkData extends Object {
@FieldOrder(order = 8)
@IntRange(minValue=1,maxValue=200)
- @Asn1Optional public Long numberOfCountermark;
+ public Long numberOfCountermark;
@FieldOrder(order = 9)
@IntRange(minValue=1,maxValue=200)
- @Asn1Optional public Long totalOfCountermarks;
+ public Long totalOfCountermarks;
@FieldOrder(order = 10)
@RestrictedString(CharacterRestriction.UTF8String)
- @Asn1Optional public String groupName;
+ public String groupName;
@FieldOrder(order = 11)
@Asn1Default("stationUIC")
diff --git a/src/main/java/org/uic/barcode/ticket/api/asn/omv1/ViaStationType.java b/src/main/java/org/uic/barcode/ticket/api/asn/omv1/ViaStationType.java
index dfc1e56..ddabf0b 100644
--- a/src/main/java/org/uic/barcode/ticket/api/asn/omv1/ViaStationType.java
+++ b/src/main/java/org/uic/barcode/ticket/api/asn/omv1/ViaStationType.java
@@ -55,7 +55,7 @@ public class ViaStationType extends Object {
@Asn1Optional public SequenceOfViaStationType route;
@FieldOrder(order = 5)
- @Asn1Optional public Boolean border = false;
+ public Boolean border = false;
@FieldOrder(order = 6)
@Asn1Optional public SequenceOfCarrierNum carriersNum;
diff --git a/src/main/java/org/uic/barcode/ticket/api/asn/omv2/CountermarkData.java b/src/main/java/org/uic/barcode/ticket/api/asn/omv2/CountermarkData.java
index aefdc3b..4c5a961 100644
--- a/src/main/java/org/uic/barcode/ticket/api/asn/omv2/CountermarkData.java
+++ b/src/main/java/org/uic/barcode/ticket/api/asn/omv2/CountermarkData.java
@@ -72,15 +72,15 @@ public class CountermarkData extends Object {
@FieldOrder(order = 8)
@IntRange(minValue=1,maxValue=200)
- @Asn1Optional public Long numberOfCountermark;
+ public Long numberOfCountermark;
@FieldOrder(order = 9)
@IntRange(minValue=1,maxValue=200)
- @Asn1Optional public Long totalOfCountermarks;
+ public Long totalOfCountermarks;
@FieldOrder(order = 10)
@RestrictedString(CharacterRestriction.UTF8String)
- @Asn1Optional public String groupName;
+ public String groupName;
@FieldOrder(order = 11)
@Asn1Default("stationUIC")
diff --git a/src/main/java/org/uic/barcode/ticket/api/asn/omv2/ViaStationType.java b/src/main/java/org/uic/barcode/ticket/api/asn/omv2/ViaStationType.java
index 0e2ca6c..f7aa1bb 100644
--- a/src/main/java/org/uic/barcode/ticket/api/asn/omv2/ViaStationType.java
+++ b/src/main/java/org/uic/barcode/ticket/api/asn/omv2/ViaStationType.java
@@ -55,7 +55,7 @@ public class ViaStationType extends Object {
@Asn1Optional public SequenceOfViaStationType route;
@FieldOrder(order = 5)
- @Asn1Optional public Boolean border = false;
+ public Boolean border = false;
@FieldOrder(order = 6)
@Asn1Optional public SequenceOfCarrierNum carriersNum;
diff --git a/src/main/java/org/uic/barcode/ticket/api/asn/omv3/CountermarkData.java b/src/main/java/org/uic/barcode/ticket/api/asn/omv3/CountermarkData.java
index 733ccf0..510ec6f 100644
--- a/src/main/java/org/uic/barcode/ticket/api/asn/omv3/CountermarkData.java
+++ b/src/main/java/org/uic/barcode/ticket/api/asn/omv3/CountermarkData.java
@@ -72,15 +72,15 @@ public class CountermarkData extends Object {
@FieldOrder(order = 8)
@IntRange(minValue=1,maxValue=200)
- @Asn1Optional public Long numberOfCountermark;
+ public Long numberOfCountermark;
@FieldOrder(order = 9)
@IntRange(minValue=1,maxValue=200)
- @Asn1Optional public Long totalOfCountermarks;
+ public Long totalOfCountermarks;
@FieldOrder(order = 10)
@RestrictedString(CharacterRestriction.UTF8String)
- @Asn1Optional public String groupName;
+ String groupName;
@FieldOrder(order = 11)
@Asn1Default("stationUIC")
diff --git a/src/main/java/org/uic/barcode/ticket/api/asn/omv3/ViaStationType.java b/src/main/java/org/uic/barcode/ticket/api/asn/omv3/ViaStationType.java
index d47bd98..2d8b751 100644
--- a/src/main/java/org/uic/barcode/ticket/api/asn/omv3/ViaStationType.java
+++ b/src/main/java/org/uic/barcode/ticket/api/asn/omv3/ViaStationType.java
@@ -55,7 +55,7 @@ public class ViaStationType extends Object {
@Asn1Optional public SequenceOfViaStationType route;
@FieldOrder(order = 5)
- @Asn1Optional public Boolean border = false;
+ public Boolean border = false;
@FieldOrder(order = 6)
@Asn1Optional public SequenceOfCarrierNum carriersNum;
diff --git a/src/main/java/org/uic/barcode/ticket/api/spec/uicBarcodeHeader0.1.asn b/src/main/java/org/uic/barcode/ticket/api/spec/uicBarcodeHeader0.1.asn
deleted file mode 100644
index 2999d18..0000000
--- a/src/main/java/org/uic/barcode/ticket/api/spec/uicBarcodeHeader0.1.asn
+++ /dev/null
@@ -1,151 +0,0 @@
--- Creator: ASN.1 Editor (http://asneditor.sourceforge.net)
--- Author: ClemensGantert
--- Created: Tue Aug 11 11:40:28 CEST 2015
-ASN-Module DEFINITIONS AUTOMATIC TAGS ::= BEGIN
-
--- imports and exports
--- EXPORTS ALL;
-
-
--- ##############################################################################################
--- #
--- # UIC barcode header - first draft
--- #
--- ##############################################################################################
-
-
--- ##############################################################################################
--- #
--- # Naming and encoding conventions
--- #
--- # Elements included as String and as Numeric values:
--- # Some elements are included in different formats to reduce the data size.
--- # These elements must be included only once.
--- # These elements are named with the same name and appendix
--- # Num (numeric values)
--- # IA5 (String values according to ASN IA5String (7Bit))
--- #
--- # RICS codes must be used to encode companies (issuer, product owner, ...) where available
--- # other codes are possible based on bilateral agreements
--- # the format is kept more flexible to cover upcoming extensions of the RICS code by ERA
--- #
--- # Stations can be coded using the UIC and upcoming ERA code lists. Proprietary codes are
--- # possible based on bilateral agreements. Format: 1..9999999 or alphanumeric without
--- # special character (IA5String)
--- #
--- #
--- # ! INTEGERS must not exceed the value of 9,223,372,036,854,775,807 (64 bit) even in case
--- # ! they are unrestricted!!!
--- # !
--- # ! Some elements like ReferenceNum or cardIdNum are defined as an unrestricted integer.
--- # ! Unlike other numerical values the cardIdNum and referenceNum can be larger than a usual 32 bit Integer
--- # ! Some ASN.1 implementation tools are limited to 32 bit integers which is too small.
--- # ! Please ensure to use a tool capable of dealing with larger numbers.
--- #
--- # BOOLEAN is always non optional
--- #
--- # Encoding of time:
--- # time is encoded as the number of minutes of the day 0 = 00:00, 1440 = 24:00,
--- # time data elements end with "time" in their name
--- #
--- # Encoding of date:
--- # .........................................................................................................
--- # The issuing date is given in UTC, but some other date values are given in local time where the exact time zone is not known.
--- #
--- #
--- #
--- # ASN.1 Extensions:
--- #
--- # The specification makes use of extension (",...").
--- # These extesions might be defined in future versions of the UIC specification
--- # Implementations must support the extension feature of ASN.1, at least they must be able to ignore extensions while decoding the data
--- # ASN.1 extensions will be defined by UIC. It is not allowed to define bilateral extensions.
--- #
--- # Bilateral Extensions:
--- # Bilateral extensions can be included in the data element "ExtensionData".
--- #
--- #
--- #
--- #########################################################################################
-
-
--- ############################################################################################
-
-
--- type assignments
-
- -- #########################################################################################
- -- the basic entry point of the data structure
- -- the data include:
- -- -issuer informations
- -- -the details of the transport document
- -- -informations required for the control process
- -- -informations on the travelers independent from the transport document
- -- -proprietary extensions
- --
- -- ##########################################################################################
- UicBarcodeHeader ::= SEQUENCE {
- -- format type
- format IA5String,
- -- "UIC" = UIC ticket
-
- version Integer (1..16),
-
- -- provider of the signature (RICS code)
- securityProviderNum INTEGER (1..32000) OPTIONAL,
- securityProviderIA5 IA5String OPTIONAL,
-
-
- staticData SEQUENCE OF DataType,
- staticSignature SignatureType OPTIONAL,
-
-
-
- -- additional dynamic data i.e. phone number, IMEI, timestamp , .... --> To be defined separately
- dynamicDataFormat IA5String OPTIONAL,
- dynamicData OCTET STRING OPTIONAL,
- dynamicPublicKey OCTET STRING OPTIONAL,
- dynamicSignature SignatureType OPTIONAL
-
- -- proprietary data defined bilaterally
- extension SEQUENCE OF ExtensionData OPTIONAL
- ,...
-
- }
-
- DataType ::= SEQUENCE {
- staticDataFormat IA5String DEFAULT "FCB1",
- -- FCB1 FCB version 1
- -- 1080XYZ
- staticData OCTET STRING
- }
-
-
-
- SignatureType ::= SEQUENCE {
- signingAlg IA5String,
- keyId IA5String (SIZE(1..5)),
- signature OCTET STRING,
- }
-
-
-
- -- ###########################################################################################
- -- generic non standard extension element
- -- the generic non - standard element contains:
- -- - an extension id to distinguish different extensions
- -- - the extension data as binary data
- -- proprietary extensions are by definition proprietary. This standard provides
- -- the means to identify these extensions
- -- within the data and to skip these data.
- -- the evaluation of these data and the unique identification of the extensions
- -- via the extension id is in the
- -- responsibility of the railways which use these extensions.
- -- ###########################################################################################
- ExtensionData ::= SEQUENCE {
- extensionId IA5String,
- extensionData OCTET STRING
- }
-
-
-END \ No newline at end of file