diff options
author | CGantert345 <57003061+CGantert345@users.noreply.github.com> | 2024-11-25 12:00:38 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-25 12:00:38 +0100 |
commit | 79c96b4e0cfacfe25abe8270f828fa84677aab99 (patch) | |
tree | 1170742143d449071fef5c5b98401956043f17cc | |
parent | Merge pull request #87 from UnionInternationalCheminsdeFer/feature/upgrade-pom-version-to-match-tag-1.4.8 (diff) | |
parent | Fix SSB Pass zone limit (diff) | |
download | UIC-barcode-79c96b4e0cfacfe25abe8270f828fa84677aab99.tar UIC-barcode-79c96b4e0cfacfe25abe8270f828fa84677aab99.tar.gz UIC-barcode-79c96b4e0cfacfe25abe8270f828fa84677aab99.tar.bz2 UIC-barcode-79c96b4e0cfacfe25abe8270f828fa84677aab99.tar.lz UIC-barcode-79c96b4e0cfacfe25abe8270f828fa84677aab99.tar.xz UIC-barcode-79c96b4e0cfacfe25abe8270f828fa84677aab99.tar.zst UIC-barcode-79c96b4e0cfacfe25abe8270f828fa84677aab99.zip |
13 files changed, 330 insertions, 180 deletions
@@ -2,7 +2,7 @@ <modelVersion>4.0.0</modelVersion>
<groupId>org.uic.barcode</groupId>
<artifactId>org.uic.barcode</artifactId>
- <version>1.4.9</version>
+ <version>1.4.10</version>
<packaging>jar</packaging>
<name>UIC barcode</name>
<description>Encoding and decoding of Aztec barcode content according to UIC IRS 90918-9</description>
diff --git a/src/main/java/org/uic/barcode/ssbFrame/SsbClass.java b/src/main/java/org/uic/barcode/ssbFrame/SsbClass.java index 48f94b8..f5257d9 100644 --- a/src/main/java/org/uic/barcode/ssbFrame/SsbClass.java +++ b/src/main/java/org/uic/barcode/ssbFrame/SsbClass.java @@ -3,68 +3,68 @@ package org.uic.barcode.ssbFrame; public enum SsbClass { NoClass, - FIRST, + First, Second, - class_3, - class_4, - class_5, - class_6, - class_7, - class_8, - class_9, - class_10, - class_11, - class_12, - class_13, - class_14, - class_15, - class_16, - class_17, - class_18, - class_19, - class_20, - class_21, - class_22, - class_23, - class_24, - class_25, - class_26, - class_27, - class_28, - class_29, - class_30, - class_31, - class_32, - class_33, - class_34, - class_35, - class_36, - class_37, - class_38, - class_39, - class_40, - class_41, - class_42, - class_43, - class_44, - class_45, - class_46, - class_47, - class_48, - class_49, - class_50, - class_51, - class_52, - class_53, - class_54, - class_55, - class_56, - class_57, - class_58, - class_59, - class_60, - class_61, - class_62, - class_63; + Class_3, + Class_4, + Class_5, + Class_6, + Class_7, + Class_8, + Class_9, + Class_A, + Class_B, + Class_C, + Class_D, + Class_E, + Class_F, + Class_G, + Class_H, + Class_I, + Class_J, + Class_K, + Class_L, + Class_M, + Class_N, + Class_O, + Class_P, + Class_Q, + Class_R, + Class_S, + Class_T, + Class_U, + Class_V, + Class_W, + Class_X, + Class_Y, + Class_Z, + Class_36, + Class_37, + Class_38, + Class_39, + Class_40, + Class_41, + Class_42, + Class_43, + Class_44, + Class_45, + Class_46, + Class_47, + Class_48, + Class_49, + Class_50, + Class_51, + Class_52, + Class_53, + Class_54, + Class_55, + Class_56, + Class_57, + Class_58, + Class_59, + Class_60, + Class_61, + Class_62, + Class_63; } diff --git a/src/main/java/org/uic/barcode/ssbFrame/SsbCommonTicketPart.java b/src/main/java/org/uic/barcode/ssbFrame/SsbCommonTicketPart.java index 8eef552..eee8af0 100644 --- a/src/main/java/org/uic/barcode/ssbFrame/SsbCommonTicketPart.java +++ b/src/main/java/org/uic/barcode/ssbFrame/SsbCommonTicketPart.java @@ -30,20 +30,20 @@ public abstract class SsbCommonTicketPart extends SsbTicketPart { int offset = 27; // header offset numberOfAdults = bits.getInteger(offset, 7); - offset = offset + 7; + offset += 7; numberOfChildren = bits.getInteger(offset, 7); - offset = offset + 7; + offset += 7; specimen = bits.get(offset); offset++; int classIndex = bits.getInteger(offset, 6); classCode = SsbClass.values()[classIndex]; - offset = offset + 6; + offset += 6; ticketNumber = bits.getChar6String(offset, 84); - offset = offset + 84; + offset += 84; year = bits.getInteger(offset, 4); - offset = offset + 4; + offset += 4; day = bits.getInteger(offset, 9); - offset = offset + 9; + offset += 9; return offset; } @@ -55,35 +55,35 @@ public abstract class SsbCommonTicketPart extends SsbTicketPart { throw new EncodingFormatException("SSB number of adults too big"); } bits.putInteger(offset,7, numberOfAdults); - offset = offset + 7; + offset += 7; if (numberOfChildren < 0 || numberOfChildren > 99) { throw new EncodingFormatException("SSB number of children too big"); } bits.putInteger(offset, 7, numberOfChildren); - offset = offset + 7; + offset += 7; bits.put(offset,specimen); offset++; bits.putInteger(offset, 6,classCode.ordinal()); - offset = offset + 6; + offset += 6; if (ticketNumber.length() > 14) { throw new EncodingFormatException("SSB Ticket Number too long"); } bits.putChar6String(offset, 84, ticketNumber); - offset = offset + 84; + offset += 84; bits.putInteger(offset, 4, (year % 10)); - offset = offset + 4; + offset += 4; if (day > 512) { throw new EncodingFormatException("SSB day too long"); } bits.putInteger(offset, 9, day); - offset = offset + 9; + offset += 9; return offset; diff --git a/src/main/java/org/uic/barcode/ssbFrame/SsbGroup.java b/src/main/java/org/uic/barcode/ssbFrame/SsbGroup.java index 7751ef6..18881d2 100644 --- a/src/main/java/org/uic/barcode/ssbFrame/SsbGroup.java +++ b/src/main/java/org/uic/barcode/ssbFrame/SsbGroup.java @@ -21,32 +21,32 @@ public class SsbGroup extends SsbCommonTicketPart { @Override protected int decodeContent(byte[] bytes, int offset) { - offset = offset + decodeCommonPart(bytes); + offset = decodeCommonPart(bytes); BitBuffer bits = new ByteBitBuffer(bytes); isReturnJourney = bits.get(offset); - offset = offset++; + offset++; firstDayOfValidity = bits.getInteger(offset, 9); - offset = offset + 9; + offset += 9; lastDayOfValidity = bits.getInteger(offset, 9); - offset = offset + 9; + offset += 9; offset = stations.decode(offset, bytes); groupName = bits.getChar6String(offset, 72); - offset = offset + 72; + offset += 72; counterMarkNumber = bits.getInteger(offset, 9); - offset = offset + 9; + offset += 9; infoCode = bits.getInteger(offset, 14); - offset = offset + 14; + offset += 14; text = bits.getChar6String(offset, 144); - offset = offset + 144; + offset += 144; return offset; @@ -55,7 +55,7 @@ public class SsbGroup extends SsbCommonTicketPart { @Override protected int encodeContent(byte[] bytes, int offset) throws EncodingFormatException { - offset = offset + encodeCommonPart(bytes, offset); + offset += encodeCommonPart(bytes, offset); BitBuffer bits = new ByteBitBuffer(bytes); @@ -66,13 +66,13 @@ public class SsbGroup extends SsbCommonTicketPart { throw new EncodingFormatException("SSB first day of validity too big"); } bits.putInteger(offset, 9, firstDayOfValidity); - offset = offset + 9; + offset += 9; if (lastDayOfValidity < 0 || lastDayOfValidity > 511) { throw new EncodingFormatException("SSB last day of validity too big"); } bits.putInteger(offset, 9, lastDayOfValidity); - offset = offset + 9; + offset += 9; offset = stations.encode(offset, bytes); @@ -80,25 +80,25 @@ public class SsbGroup extends SsbCommonTicketPart { throw new EncodingFormatException("SSB group name too big"); } bits.putChar6String(offset, 72,groupName); - offset = offset + 72; + offset += 72; if (counterMarkNumber < 0 || counterMarkNumber > 246) { throw new EncodingFormatException("SSB number of countermark too big"); } bits.putInteger(offset, 9,counterMarkNumber); - offset = offset + 9; + offset += 9; if (infoCode < 0 || infoCode > 9999) { throw new EncodingFormatException("SSB info code too big"); } bits.putInteger(offset, 14, infoCode); - offset = offset + 14; + offset += 14; if (text.length() > 24) { throw new EncodingFormatException("SSB text too big"); } bits.putChar6String(offset, 144, text); - offset = offset + 144; + offset += 144; return offset; } diff --git a/src/main/java/org/uic/barcode/ssbFrame/SsbNonReservation.java b/src/main/java/org/uic/barcode/ssbFrame/SsbNonReservation.java index 80fc2bc..329d6ea 100644 --- a/src/main/java/org/uic/barcode/ssbFrame/SsbNonReservation.java +++ b/src/main/java/org/uic/barcode/ssbFrame/SsbNonReservation.java @@ -17,26 +17,26 @@ public class SsbNonReservation extends SsbCommonTicketPart { @Override protected int decodeContent(byte[] bytes, int offset) { - offset = offset + decodeCommonPart(bytes); + offset = decodeCommonPart(bytes); BitBuffer bits = new ByteBitBuffer(bytes); isReturnJourney = bits.get(offset); - offset = offset++; + offset++; firstDayOfValidity = bits.getInteger(offset, 9); - offset = offset + 9; + offset += 9; lastDayOfValidity = bits.getInteger(offset, 9); - offset = offset + 9; + offset += 9; offset = stations.decode(offset, bytes); infoCode = bits.getInteger(offset, 14); - offset = offset + 14; + offset += 14; text = bits.getChar6String(offset, 222); - offset = offset + 222; + offset += 222; return offset; @@ -45,24 +45,24 @@ public class SsbNonReservation extends SsbCommonTicketPart { @Override protected int encodeContent(byte[] bytes, int offset) throws EncodingFormatException { - offset = offset + encodeCommonPart(bytes, offset); + offset = encodeCommonPart(bytes, offset); BitBuffer bits = new ByteBitBuffer(bytes); bits.put(offset, isReturnJourney); - offset = offset++; + offset++; if (firstDayOfValidity < 0 || firstDayOfValidity > 511) { throw new EncodingFormatException("SSB first day of validity too big"); } bits.putInteger(offset, 9, firstDayOfValidity); - offset = offset + 9; + offset += 9; if (lastDayOfValidity < 0 || lastDayOfValidity > 511) { throw new EncodingFormatException("SSB last day of validity too big"); } bits.putInteger(offset, 9, lastDayOfValidity); - offset = offset + 9; + offset += 9; offset = stations.encode(offset, bytes); @@ -70,13 +70,13 @@ public class SsbNonReservation extends SsbCommonTicketPart { throw new EncodingFormatException("SSB info code too big"); } bits.putInteger(offset, 14, infoCode); - offset = offset + 14; + offset += 14; if (text.length() > 37) { throw new EncodingFormatException("SSB text too big"); } bits.putChar6String(offset, 222, text); - offset = offset + 222; + offset += 222; return offset; diff --git a/src/main/java/org/uic/barcode/ssbFrame/SsbNonUic.java b/src/main/java/org/uic/barcode/ssbFrame/SsbNonUic.java index 1f0049e..1f9a8a4 100644 --- a/src/main/java/org/uic/barcode/ssbFrame/SsbNonUic.java +++ b/src/main/java/org/uic/barcode/ssbFrame/SsbNonUic.java @@ -20,7 +20,7 @@ public class SsbNonUic extends SsbTicketPart { for (int i = offset; i < openDataLength; i++) { - if (bits.get(i) == false) { + if (bits.get(i) == true) { sb.append("1"); } else { sb.append("0"); @@ -46,7 +46,7 @@ public class SsbNonUic extends SsbTicketPart { for (int i = 0; i< openDataLength ; i++) { - if (i < bitString.length() && bitString.charAt(i) == '0') { + if (i < bitString.length() && bitString.charAt(i) == '1') { bits.put(offset + i, true); } else { bits.put(offset + i, false); diff --git a/src/main/java/org/uic/barcode/ssbFrame/SsbPass.java b/src/main/java/org/uic/barcode/ssbFrame/SsbPass.java index a26fb61..56f674c 100644 --- a/src/main/java/org/uic/barcode/ssbFrame/SsbPass.java +++ b/src/main/java/org/uic/barcode/ssbFrame/SsbPass.java @@ -11,7 +11,7 @@ public class SsbPass extends SsbCommonTicketPart { First day of validity from the issuing date Num (<367) 9 bit 000 = open date for regular Eurail pass to be activated Maximum duration from the issuing date for OVERSEAS; otherwise, last day of validity Num (<278) 9 bit 9 months max. validity Number of days of travel allowed Num (<93) 7 bit - Country code 1 Num (<100) 7 0.875 100 = all countries + Country code 1 Num (<108) 7 0.875 100 = all countries, see TAP TSI B.12 for zones over 100 Country code 2 Num (<99) 7 0.875 If country code 1 is 100, then 00 Country code 3 Num (<99) 7 0.875 If country code 1 is 100, then 00 Country code 4 Num (<99) 7 0.875 If country code 1 is 100, then 00 @@ -38,45 +38,45 @@ public class SsbPass extends SsbCommonTicketPart { @Override protected int decodeContent(byte[] bytes, int offset) { - offset = offset + decodeCommonPart(bytes); + offset = decodeCommonPart(bytes); BitBuffer bits = new ByteBitBuffer(bytes); passSubType = bits.getInteger(offset, 2); - offset = offset + 2; + offset += 2; firstDayOfValidity = bits.getInteger(offset, 9); - offset = offset + 9; + offset += 9; maximumValidityDuration = bits.getInteger(offset, 9); - offset = offset + 9; + offset += 9; numberOfTravels = bits.getInteger(offset, 7); - offset = offset + 7; + offset += 7; country_1 = bits.getInteger(offset, 7); - offset = offset + 7; + offset += 7; country_2 = bits.getInteger(offset, 7); - offset = offset + 7; + offset += 7; country_3 = bits.getInteger(offset, 7); - offset = offset + 7; + offset += 7; country_4 = bits.getInteger(offset, 7); - offset = offset + 7; + offset += 7; country_5 = bits.getInteger(offset, 7); - offset = offset + 7; + offset += 7; hasSecondPage = bits.get(offset); offset++; infoCode = bits.getInteger(offset, 14); - offset = offset + 14; + offset += 14; text = bits.getChar6String(offset, 240); - offset = offset + 240; + offset += 240; return offset; } @@ -84,7 +84,7 @@ public class SsbPass extends SsbCommonTicketPart { @Override protected int encodeContent(byte[] bytes, int offset) throws EncodingFormatException { - offset = offset + encodeCommonPart(bytes, offset); + offset = encodeCommonPart(bytes, offset); BitBuffer bits = new ByteBitBuffer(bytes); @@ -92,55 +92,55 @@ public class SsbPass extends SsbCommonTicketPart { throw new EncodingFormatException("SSB pass type too big"); } bits.putInteger(offset, 2,passSubType); - offset = offset + 2; + offset += 2; if (firstDayOfValidity < 0 || firstDayOfValidity > 511) { throw new EncodingFormatException("SSB first day of validity too big"); } bits.putInteger(offset, 9,firstDayOfValidity); - offset = offset + 9; + offset += 9; if (maximumValidityDuration < 0 || maximumValidityDuration > 511) { throw new EncodingFormatException("SSB validity duration too big"); } bits.putInteger(offset, 9,maximumValidityDuration); - offset = offset + 9; + offset += 9; if (numberOfTravels < 0 || numberOfTravels > 94) { throw new EncodingFormatException("SSB number of travels too big"); } bits.putInteger(offset, 7, numberOfTravels); - offset = offset + 7; + offset += 7; - if (country_1 < 0 || country_1 > 100) { + if (country_1 < 0 || country_1 > 108) { throw new EncodingFormatException("SSB country 1 too big"); } bits.putInteger(offset, 7,country_1); - offset = offset + 7; + offset += 7; if (country_2 < 0 || country_2 > 99) { throw new EncodingFormatException("SSB country 2 too big"); } bits.putInteger(offset, 7,country_2); - offset = offset + 7; + offset += 7; if (country_3 < 0 || country_3 > 99) { throw new EncodingFormatException("SSB country 3 too big"); } bits.putInteger(offset, 7,country_3); - offset = offset + 7; + offset += 7; if (country_4 < 0 || country_4 > 99) { throw new EncodingFormatException("SSB country 4 too big"); } bits.putInteger(offset, 7,country_4); - offset = offset + 7; + offset += 7; if (country_5 < 0 || country_5 > 99) { throw new EncodingFormatException("SSB country 5 too big"); } bits.putInteger(offset, 7,country_5); - offset = offset + 7; + offset += 7; bits.put(offset, hasSecondPage); offset++; @@ -149,13 +149,13 @@ public class SsbPass extends SsbCommonTicketPart { throw new EncodingFormatException("SSB info code too big"); } bits.putInteger(offset, 14, infoCode); - offset = offset + 14; + offset += 14; if (text.length() > 40) { throw new EncodingFormatException("SSB text too big"); } bits.putChar6String(offset, 240,text); - offset = offset + 240; + offset += 240; return offset; } diff --git a/src/main/java/org/uic/barcode/ssbFrame/SsbReservation.java b/src/main/java/org/uic/barcode/ssbFrame/SsbReservation.java index c70c2d1..7496bcc 100644 --- a/src/main/java/org/uic/barcode/ssbFrame/SsbReservation.java +++ b/src/main/java/org/uic/barcode/ssbFrame/SsbReservation.java @@ -33,12 +33,12 @@ public class SsbReservation extends SsbCommonTicketPart { @Override protected int decodeContent(byte[] bytes, int offset) { - offset = offset + decodeCommonPart(bytes); + offset = decodeCommonPart(bytes); BitBuffer bits = new ByteBitBuffer(bytes); ticketSubType = bits.getInteger(offset, 2); - offset = offset + 2; + offset += 2; stations = new SsbStations(); offset = stations.decode(offset, bytes); @@ -55,28 +55,28 @@ public class SsbReservation extends SsbCommonTicketPart { */ departureDate = bits.getInteger(offset, 9); - offset = offset + 9; + offset += 9; departureTime = bits.getInteger(offset, 11); - offset = offset + 11; + offset += 11; train = bits.getChar6String(offset, 30); - offset = offset + 30; + offset += 30; coach = bits.getInteger(offset, 10); - offset = offset + 10; + offset += 10; place = bits.getChar6String(offset, 18); - offset = offset + 18; + offset += 18; overbooking = bits.get(offset); offset++; infoCode = bits.getInteger(offset, 14); - offset = offset + 14; + offset += 14; text = bits.getChar6String(offset, 162); - offset = offset + 162; + offset += 162; return offset; } @@ -84,7 +84,7 @@ public class SsbReservation extends SsbCommonTicketPart { @Override protected int encodeContent(byte[] bytes, int offset) throws EncodingFormatException { - offset = offset + encodeCommonPart(bytes, offset); + offset = encodeCommonPart(bytes, offset); BitBuffer bits = new ByteBitBuffer(bytes); @@ -92,7 +92,7 @@ public class SsbReservation extends SsbCommonTicketPart { throw new EncodingFormatException("SSB pass type too big"); } bits.putInteger(offset, 2,ticketSubType); - offset = offset + 2; + offset += 2; offset = stations.encode(offset, bytes); @@ -111,31 +111,31 @@ public class SsbReservation extends SsbCommonTicketPart { throw new EncodingFormatException("SSB departure date too big"); } bits.putInteger(offset, 9, departureDate); - offset = offset + 9; + offset += 9; if (departureTime < 0 || departureTime > 1440) { throw new EncodingFormatException("SSB departure time too big"); } bits.putInteger(offset, 11,departureTime); - offset = offset + 11; + offset += 11; if (train.length() > 5) { throw new EncodingFormatException("SSB train too big"); } bits.putChar6String(offset, 30,train); - offset = offset + 30; + offset += 30; if (coach < 0 || coach > 999) { throw new EncodingFormatException("SSB coach too big"); } bits.putInteger(offset, 10,coach); - offset = offset + 10; + offset += 10; if (place.length() > 3) { throw new EncodingFormatException("SSB coach too big"); } bits.putChar6String(offset, 18,place); - offset = offset + 18; + offset += 18; bits.put(offset, overbooking); offset++; @@ -144,13 +144,13 @@ public class SsbReservation extends SsbCommonTicketPart { throw new EncodingFormatException("SSB info code too big"); } bits.putInteger(offset, 14, infoCode); - offset = offset + 14; + offset += 14; if (text.length() > 27) { throw new EncodingFormatException("SSB text too big"); } bits.putChar6String(offset, 162, text); - offset = offset + 162; + offset += 162; return offset; diff --git a/src/main/java/org/uic/barcode/ssbFrame/SsbStationCodeTable.java b/src/main/java/org/uic/barcode/ssbFrame/SsbStationCodeTable.java index 8aeaf22..bc421c2 100644 --- a/src/main/java/org/uic/barcode/ssbFrame/SsbStationCodeTable.java +++ b/src/main/java/org/uic/barcode/ssbFrame/SsbStationCodeTable.java @@ -5,5 +5,17 @@ public enum SsbStationCodeTable { UNKNOWN_0, NRT, RESERVATION, - UNKNOWN_3; + UNKNOWN_3, + UNKNOWN_4, + UNKNOWN_5, + UNKNOWN_6, + UNKNOWN_7, + UNKNOWN_8, + UNKNOWN_9, + UNKNOWN_10, + UNKNOWN_11, + UNKNOWN_12, + UNKNOWN_13, + UNKNOWN_14, + UNKNOWN_15; } diff --git a/src/main/java/org/uic/barcode/ssbFrame/SsbStations.java b/src/main/java/org/uic/barcode/ssbFrame/SsbStations.java index e3b7654..13bf40a 100644 --- a/src/main/java/org/uic/barcode/ssbFrame/SsbStations.java +++ b/src/main/java/org/uic/barcode/ssbFrame/SsbStations.java @@ -23,52 +23,50 @@ public class SsbStations { protected String arrivalStationCode = " "; protected String departureStationCode = " "; protected SsbStationCodeTable codeTable = SsbStationCodeTable.NRT; + protected boolean alphaNumeric = true; public int encode(int offset, byte[] bytes) throws EncodingFormatException { - - boolean isAlphaNumeric = false; - BitBuffer bits = new ByteBitBuffer(bytes); - try { + if (!alphaNumeric) try { Integer.parseInt(arrivalStationCode); Integer.parseInt(departureStationCode); - isAlphaNumeric = false; + alphaNumeric = false; } catch(NumberFormatException e) { - isAlphaNumeric = true; + alphaNumeric = true; } - bits.put(offset, isAlphaNumeric); + bits.put(offset, alphaNumeric); offset++; - if (isAlphaNumeric) { + if (alphaNumeric) { if (departureStationCode.length() > 6) { throw new EncodingFormatException("SSB departure station too long"); } bits.putChar6String(offset,30, departureStationCode); - offset = offset + 30; + offset += 30; if (arrivalStationCode.length() > 6) { throw new EncodingFormatException("SSB arrival station too long"); } bits.putChar6String(offset,30, arrivalStationCode); - offset = offset + 30; + offset += 30; } else { bits.putInteger(offset, 4, codeTable.ordinal()); - offset = offset + 4; + offset += 4; int stationCode = Integer.parseInt(departureStationCode); if (stationCode < 0 || stationCode > 9999999) { throw new EncodingFormatException("SSB departure station code too long"); } bits.putInteger(offset, 28, stationCode); - offset = offset + 28; + offset += 28; stationCode = Integer.parseInt(arrivalStationCode); if (stationCode < 0 || stationCode > 9999999) { throw new EncodingFormatException("SSB arrival station code too long"); } bits.putInteger(offset, 28, stationCode); - offset = offset + 28; + offset += 28; } return offset; @@ -79,21 +77,21 @@ public class SsbStations { BitBuffer bits = new ByteBitBuffer(bytes); - boolean isAlphaNumeric = bits.get(offset); + alphaNumeric = bits.get(offset); offset++; - if (isAlphaNumeric) { + if (alphaNumeric) { departureStationCode = bits.getChar6String(offset,30); - offset = offset + 30; + offset += 30; arrivalStationCode = bits.getChar6String(offset,30); - offset = offset + 30; + offset += 30; } else { codeTable = SsbStationCodeTable.values()[bits.getInteger(offset, 4)]; - offset = offset + 4; + offset += 4; departureStationCode = Integer.toString(bits.getInteger(offset, 28)); - offset = offset + 28; + offset += 28; arrivalStationCode = Integer.toString(bits.getInteger(offset, 28)); - offset = offset + 28; + offset += 28; } @@ -126,7 +124,12 @@ public class SsbStations { this.codeTable = codeTable; } - - + public boolean isAlphaNumeric() { + return alphaNumeric; + } + + public void setAlphaNumeric(boolean alphaNumeric) { + this.alphaNumeric = alphaNumeric; + } } diff --git a/src/main/java/org/uic/barcode/ssbFrame/SsbTicketType.java b/src/main/java/org/uic/barcode/ssbFrame/SsbTicketType.java index cb60a26..5b153d6 100644 --- a/src/main/java/org/uic/barcode/ssbFrame/SsbTicketType.java +++ b/src/main/java/org/uic/barcode/ssbFrame/SsbTicketType.java @@ -1,7 +1,7 @@ package org.uic.barcode.ssbFrame; public enum SsbTicketType { - + UIC_0_UNDEFINED, UIC_1_IRT_RES_BOA, UIC_2_NRT, UIC_3_GRP, @@ -32,8 +32,7 @@ public enum SsbTicketType { NONUIC_28_BILATERAL, NONUIC_29_BILATERAL, NONUIC_30_BILATERAL, - NONUIC_31_BILATERAL, - NONUIC_32_BILATERAL; + NONUIC_31_BILATERAL; } diff --git a/src/test/java/org/uic/barcode/test/utils/SsbTicketFactory.java b/src/test/java/org/uic/barcode/test/utils/SsbTicketFactory.java index 539fced..718edd7 100644 --- a/src/test/java/org/uic/barcode/test/utils/SsbTicketFactory.java +++ b/src/test/java/org/uic/barcode/test/utils/SsbTicketFactory.java @@ -26,7 +26,7 @@ public class SsbTicketFactory { ssbPass.setPassData(new SsbPass());
- ssbPass.getPassData().setClassCode(SsbClass.FIRST);
+ ssbPass.getPassData().setClassCode(SsbClass.First);
ssbPass.getPassData().setCountry_1(10);
ssbPass.getPassData().setCountry_2(12);
ssbPass.getPassData().setDay(1);
@@ -57,7 +57,7 @@ public class SsbTicketFactory { ssb.setGroupData(new SsbGroup());
- ssb.getGroupData().setClassCode(SsbClass.FIRST);
+ ssb.getGroupData().setClassCode(SsbClass.First);
ssb.getGroupData().setCounterMarkNumber(1);
ssb.getGroupData().setDay(1);
ssb.getGroupData().setFirstDayOfValidity(10);
@@ -73,6 +73,7 @@ public class SsbTicketFactory { ssb.getGroupData().setTicketNumber("SKCTS86");
ssb.getGroupData().setYear(3);
+ ssb.getReservationData().getStations().setAlphaNumeric(false);
ssb.getGroupData().getStations().setArrivalStationCode("8012345");
ssb.getGroupData().getStations().setDepartureStationCode("8054321");
ssb.getGroupData().getStations().setCodeTable(SsbStationCodeTable.NRT);
@@ -91,7 +92,7 @@ public class SsbTicketFactory { ssb.setNonReservationData(new SsbNonReservation());
- ssb.getNonReservationData().setClassCode(SsbClass.FIRST);
+ ssb.getNonReservationData().setClassCode(SsbClass.First);
ssb.getNonReservationData().setDay(1);
ssb.getNonReservationData().setFirstDayOfValidity(10);
ssb.getNonReservationData().setFirstDayOfValidity(120);
@@ -105,7 +106,7 @@ public class SsbTicketFactory { ssb.getNonReservationData().setTicketNumber("SKCTS86");
ssb.getNonReservationData().setYear(3);
-
+ ssb.getReservationData().getStations().setAlphaNumeric(false);
ssb.getNonReservationData().getStations().setArrivalStationCode("8012345");
ssb.getNonReservationData().getStations().setDepartureStationCode("8054321");
ssb.getNonReservationData().getStations().setCodeTable(SsbStationCodeTable.NRT);
@@ -124,7 +125,7 @@ public class SsbTicketFactory { ssb.setReservationData(new SsbReservation());
- ssb.getReservationData().setClassCode(SsbClass.FIRST);
+ ssb.getReservationData().setClassCode(SsbClass.First);
ssb.getReservationData().setDay(1);
ssb.getReservationData().setCoach(123);
ssb.getReservationData().setDepartureDate(120);
@@ -141,7 +142,7 @@ public class SsbTicketFactory { ssb.getReservationData().setTicketNumber("SKCTS86");
ssb.getReservationData().setYear(3);
-
+ ssb.getReservationData().getStations().setAlphaNumeric(false);
ssb.getReservationData().getStations().setArrivalStationCode("8012345");
ssb.getReservationData().getStations().setDepartureStationCode("8054321");
ssb.getReservationData().getStations().setCodeTable(SsbStationCodeTable.NRT);
@@ -167,6 +168,8 @@ public class SsbTicketFactory { }
public static void compareStations(SsbStations stations, SsbStations stations2) {
+
+ assert (stations.isAlphaNumeric() == stations2.isAlphaNumeric());
assert (stations.getCodeTable().equals(stations2.getCodeTable()));
diff --git a/src/test/java/org/uic/barcode/ticketTests/SZticketTest.java b/src/test/java/org/uic/barcode/ticketTests/SZticketTest.java new file mode 100644 index 0000000..6855aa6 --- /dev/null +++ b/src/test/java/org/uic/barcode/ticketTests/SZticketTest.java @@ -0,0 +1,133 @@ +package org.uic.barcode.ticketTests; + +import java.security.KeyFactory; +import java.security.NoSuchAlgorithmException; +import java.security.Provider; +import java.security.PublicKey; +import java.security.Security; +import java.security.spec.InvalidKeySpecException; +import java.security.spec.X509EncodedKeySpec; +import java.util.Base64; +import java.util.TimeZone; + +import org.bouncycastle.jce.provider.BouncyCastleProvider; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.uic.barcode.Decoder; +import org.uic.barcode.dynamicFrame.Constants; +import org.uic.barcode.logger.LoggerFactory; +import org.uic.barcode.ssbFrame.SsbClass; +import org.uic.barcode.ssbFrame.SsbFrame; +import org.uic.barcode.ssbFrame.SsbStationCodeTable; +import org.uic.barcode.ssbFrame.SsbTicketType; + +public class SZticketTest { + + TimeZone defaulttimeZone = null; + + String ticketBase64 = "MSbEQEACWRUQQQRTUTAAAAJbAAAAg8md4D3SgYAAAAAAAAAAAAAAAAAAAAAA" + + "AAAAAAAAAAAAAAAAAIYJ9h44ZY0Kh/z3y89kgvrmVBIQAodNRwl3wlNU/1q6qcoOOjir/NX8" + + "tZlBGPMrZNQAKdG5WoJc"; + + String publicKeyBase64 = "MIIDQzCCAjUGByqGSM44BAEwggIoAoIBAQDdevkGfuV5U5BmSaaC2ymhw" + + "+SQQcax2yZRbRExZvaTeOr3NkJlqAgzbvpIAUx5U1rZ3J3ZkFWmkADWds8r1sko8vpqJQDpG" + + "js0iXP1r7GYAlciPgGRffmfdn5eVCWgFeG381CLFZ4pUVC7SbwusVzcnGRt/V1wxNdRRxCXG" + + "q1O1L63PiSRNW5RJv/JsVHaqZMbCEigh2NXYkCB0BgDFub+2NTAW7GnllX9F656zpP6gwV6K" + + "AymUha5bH33c1rDuhmO25iNrWwW60Sxrl8rs93k2FQB4AzelCw/6MS9uHerdABdedzlUqN7w" + + "UleJCgc25w3eoTPKnbEF4xdaeR3afvfAh0AiNWFRF2DOZZ+koG4K39Vr94q47YILo7LOeuPO" + + "wKCAQBG0Pt3roTa9Aau2U7hZINGcSUI5hLbpMwtrXtAnDtWkQOqPO11vvXJhYHZQkM4wOmhR" + + "uT4OxolKvWHjvkvlKoGx4gZMdASio8UuaCbtKo2588xQ4SY1+Cs2lhRRuhfYce5rv9DhOjgf" + + "Yv9zxR7Skt6UAbndJtpmSo6mxBK/G2w6FIxzsWBPekaZ/nXWMHFNv/6SDtIrQM3W+DqCckj8" + + "c7tG6zLHcMYh/OIfnc0mVN1EgxsovJz/XmN3LsInIZq8cxQNH9l/TsexLVJrQ3odfA5VmcoH" + + "inIQV8K1Iak3NcclwOzvk5sup8cPKoMf4p1YFO5OcW3WR5HFB42VimkoyK4A4IBBgACggEBA" + + "Kr1MuBndeKbZDHyZ4opf0a3dJd00lBgp5dH5SF7Um8LnqY2SGYd7IvXBOjP1fdFub4CLNPXn" + + "265gQF7HkDBu0zd+Sy2glzCabOz7j1LJezaaEGGHDndBwTsGGrQ0JRcB2SR3cCFdmjmzEFlJ" + + "xarriD7K7N5jSBT1mJCmNvkTk8dgtoBcIW6qxQe+Q72UFyME+6H/6Nnh+X2tv4CbVnmmTXT1" + + "ktaZjf+RrFc5eT1nPVFDZcNaDwzUapf4fLqGXw46JmB0WM5+o5zTR7Q+1AWHEn0D4eqEWoui" + + "wXbIxiV/JQEW55eWnz3oSClRLOFNL3zqEydGrr4RSh0AS4wE8EjNIY="; + + + String algorithmOID = Constants.DSA_SHA224; + + int keySize = 1024; + + Provider provider = null; + + PublicKey publicKey = null; + + + /** + * Prepare tickets. + */ + @Before public void prepare() throws Exception { + + LoggerFactory.setActivateConsoleLog(true); + + defaulttimeZone = TimeZone.getDefault(); + //decode in local CET time zone + TimeZone.setDefault(TimeZone.getTimeZone("CET")); + + provider = new BouncyCastleProvider(); + Security.addProvider(provider); + + // decode public key + byte[] publicKeyContent = Base64.getDecoder().decode(publicKeyBase64); + X509EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(publicKeyContent); + KeyFactory keyFactory = KeyFactory.getInstance("DSA", provider); + publicKey = keyFactory.generatePublic(publicKeySpec); + } + + + /** + * clean up + */ + @After public void resetTimeZone() { + TimeZone.setDefault(defaulttimeZone); + } + + @Test + public void testDecoder() throws Exception { + byte[] content = Base64.getDecoder().decode(ticketBase64); + + Decoder decoder = new Decoder(content); + SsbFrame frame = decoder.getSsbFrame(); + + Assert.assertNotNull(frame); + Assert.assertNotNull(frame.getNonReservationData()); + Assert.assertNull(frame.getReservationData()); + Assert.assertNull(frame.getPassData()); + Assert.assertNull(frame.getGroupData()); + Assert.assertNull(frame.getNonUicData()); + + Assert.assertNotNull(frame.getSignaturePart1()); + Assert.assertNotNull(frame.getSignaturePart2()); + + Assert.assertTrue(frame.verifyByAlgorithmOid(publicKey, algorithmOID, provider)); + + Assert.assertEquals(frame.getHeader().getVersion(), 3); + Assert.assertEquals(frame.getHeader().getIssuer(), 1179); + Assert.assertEquals(frame.getHeader().getKeyId(), 1); + Assert.assertEquals(frame.getHeader().getTicketType(), SsbTicketType.UIC_2_NRT); + + Assert.assertEquals(frame.getNonReservationData().getNumberOfAdults(), 1); + Assert.assertEquals(frame.getNonReservationData().getNumberOfChildren(), 0); + Assert.assertFalse(frame.getNonReservationData().isSpecimen()); + Assert.assertEquals(frame.getNonReservationData().getClassCode(), SsbClass.Second); + Assert.assertEquals(frame.getNonReservationData().getTicketNumber(), "6140001343"); + Assert.assertEquals(frame.getNonReservationData().getYear(), 2); + Assert.assertEquals(frame.getNonReservationData().getDay(), 182); + Assert.assertEquals(frame.getNonReservationData().getFirstDayOfValidity(), 0); + Assert.assertEquals(frame.getNonReservationData().getLastDayOfValidity(), 0); + + Assert.assertFalse(frame.getNonReservationData().getStations().isAlphaNumeric()); + Assert.assertEquals(frame.getNonReservationData().getStations().getCodeTable(), SsbStationCodeTable.NRT); + Assert.assertEquals(frame.getNonReservationData().getStations().getDepartureStationCode(), "7943100"); + Assert.assertEquals(frame.getNonReservationData().getStations().getArrivalStationCode(), "8103171"); + + Assert.assertEquals(frame.getNonReservationData().getInfoCode(), 0); + Assert.assertEquals(frame.getNonReservationData().getText(), ""); + } + +} |