From fc6a4042f7fca1828f0b8e267cfd660e6fe1d40a Mon Sep 17 00:00:00 2001 From: CGantert345 <57003061+CGantert345@users.noreply.github.com> Date: Tue, 22 Nov 2022 14:04:27 +0100 Subject: support for SSB barcodes SSB frame implenmentation including decoding, encoding, signing and verification --- .../java/org/uic/barcode/ssbFrame/SsbGroup.java | 146 +++++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 src/main/java/org/uic/barcode/ssbFrame/SsbGroup.java (limited to 'src/main/java/org/uic/barcode/ssbFrame/SsbGroup.java') diff --git a/src/main/java/org/uic/barcode/ssbFrame/SsbGroup.java b/src/main/java/org/uic/barcode/ssbFrame/SsbGroup.java new file mode 100644 index 0000000..52c3a52 --- /dev/null +++ b/src/main/java/org/uic/barcode/ssbFrame/SsbGroup.java @@ -0,0 +1,146 @@ +package org.uic.barcode.ssbFrame; + +import org.uic.barcode.asn1.uper.BitBuffer; +import org.uic.barcode.asn1.uper.ByteBitBuffer; + +public class SsbGroup extends SsbCommonTicketPart { + + protected int firstDayOfValidity = 0; + protected int lastDayOfValidity = 0; + protected boolean isReturnJourney = false; + private int infoCode = 0; + private String text = null; + private SsbStations stations = new SsbStations(); + + private String groupName = null; + + private int counterMarkNumber = 0; + + + @Override + protected void decodeContent(byte[] bytes) { + + int offset = decodeCommonPart(bytes); + + BitBuffer bits = new ByteBitBuffer(bytes); + + isReturnJourney = bits.get(offset); + offset = offset++; + + firstDayOfValidity = bits.getInteger(offset, 9); + offset = offset + 9; + + lastDayOfValidity = bits.getInteger(offset, 9); + offset = offset + 9; + + offset = stations.decode(offset, bytes); + + groupName = bits.getChar6String(offset, 72); + offset = offset + 72; + + counterMarkNumber = bits.getInteger(offset, 9); + offset = offset + 9; + + infoCode = bits.getInteger(offset, 14); + offset = offset + 14; + + text = bits.getChar6String(offset, 222); + offset = offset + 222; + + } + + @Override + protected void encodeContent(byte[] bytes) { + + int offset = encodeCommonPart(bytes); + + BitBuffer bits = new ByteBitBuffer(bytes); + + bits.put(offset, isReturnJourney); + offset = offset++; + + bits.putInteger(offset, 9, firstDayOfValidity); + offset = offset + 9; + + bits.putInteger(offset, 9, lastDayOfValidity); + offset = offset + 9; + + offset = stations.decode(offset, bytes); + + bits.putChar6String(offset, 72,groupName); + offset = offset + 72; + + bits.putInteger(offset, 9,counterMarkNumber); + offset = offset + 9; + + bits.putInteger(offset, 14, infoCode); + offset = offset + 14; + + bits.putChar6String(offset, 144, text); + offset = offset + 222; + + } + + public int getFirstDayOfValidity() { + return firstDayOfValidity; + } + + public void setFirstDayOfValidity(int firstDayOfValidity) { + this.firstDayOfValidity = firstDayOfValidity; + } + + public int getLastDayOfValidity() { + return lastDayOfValidity; + } + + public void setLastDayOfValidity(int lastDayOfValidity) { + this.lastDayOfValidity = lastDayOfValidity; + } + + public boolean isReturnJourney() { + return isReturnJourney; + } + + public void setReturnJourney(boolean isReturnJourney) { + this.isReturnJourney = isReturnJourney; + } + + public int getInfoCode() { + return infoCode; + } + + public void setInfoCode(int infoCode) { + this.infoCode = infoCode; + } + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + } + + public SsbStations getStations() { + return stations; + } + + public String getGroupName() { + return groupName; + } + + public void setGroupName(String groupName) { + this.groupName = groupName; + } + + public int getCounterMarkNumber() { + return counterMarkNumber; + } + + public void setCounterMarkNumber(int counterMarkNumber) { + this.counterMarkNumber = counterMarkNumber; + } + + + +} -- cgit v1.2.3 From 7ec06722923d96d2e51300bafb44b920ca341d58 Mon Sep 17 00:00:00 2001 From: CGantert345 <57003061+CGantert345@users.noreply.github.com> Date: Fri, 10 Mar 2023 16:49:58 +0100 Subject: ssb unit tests --- src/main/java/org/uic/barcode/ssbFrame/SsbGroup.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'src/main/java/org/uic/barcode/ssbFrame/SsbGroup.java') diff --git a/src/main/java/org/uic/barcode/ssbFrame/SsbGroup.java b/src/main/java/org/uic/barcode/ssbFrame/SsbGroup.java index 52c3a52..1b2f6e7 100644 --- a/src/main/java/org/uic/barcode/ssbFrame/SsbGroup.java +++ b/src/main/java/org/uic/barcode/ssbFrame/SsbGroup.java @@ -18,9 +18,9 @@ public class SsbGroup extends SsbCommonTicketPart { @Override - protected void decodeContent(byte[] bytes) { + protected int decodeContent(byte[] bytes, int offset) { - int offset = decodeCommonPart(bytes); + offset = offset + decodeCommonPart(bytes); BitBuffer bits = new ByteBitBuffer(bytes); @@ -44,15 +44,17 @@ public class SsbGroup extends SsbCommonTicketPart { infoCode = bits.getInteger(offset, 14); offset = offset + 14; - text = bits.getChar6String(offset, 222); - offset = offset + 222; + text = bits.getChar6String(offset, 144); + offset = offset + 144; + + return offset; } @Override - protected void encodeContent(byte[] bytes) { + protected int encodeContent(byte[] bytes, int offset) { - int offset = encodeCommonPart(bytes); + offset = offset + encodeCommonPart(bytes, offset); BitBuffer bits = new ByteBitBuffer(bytes); @@ -65,7 +67,7 @@ public class SsbGroup extends SsbCommonTicketPart { bits.putInteger(offset, 9, lastDayOfValidity); offset = offset + 9; - offset = stations.decode(offset, bytes); + offset = stations.encode(offset, bytes); bits.putChar6String(offset, 72,groupName); offset = offset + 72; @@ -77,8 +79,9 @@ public class SsbGroup extends SsbCommonTicketPart { offset = offset + 14; bits.putChar6String(offset, 144, text); - offset = offset + 222; + offset = offset + 144; + return offset; } public int getFirstDayOfValidity() { -- cgit v1.2.3 From f1a08e7fb82e813ce6985460cc2606fc7b19ae13 Mon Sep 17 00:00:00 2001 From: CGantert345 <57003061+CGantert345@users.noreply.github.com> Date: Tue, 14 Mar 2023 10:15:31 +0100 Subject: SSB encoding format validation --- .../java/org/uic/barcode/ssbFrame/SsbGroup.java | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'src/main/java/org/uic/barcode/ssbFrame/SsbGroup.java') diff --git a/src/main/java/org/uic/barcode/ssbFrame/SsbGroup.java b/src/main/java/org/uic/barcode/ssbFrame/SsbGroup.java index 1b2f6e7..7751ef6 100644 --- a/src/main/java/org/uic/barcode/ssbFrame/SsbGroup.java +++ b/src/main/java/org/uic/barcode/ssbFrame/SsbGroup.java @@ -2,6 +2,7 @@ package org.uic.barcode.ssbFrame; import org.uic.barcode.asn1.uper.BitBuffer; import org.uic.barcode.asn1.uper.ByteBitBuffer; +import org.uic.barcode.ticket.EncodingFormatException; public class SsbGroup extends SsbCommonTicketPart { @@ -52,7 +53,7 @@ public class SsbGroup extends SsbCommonTicketPart { } @Override - protected int encodeContent(byte[] bytes, int offset) { + protected int encodeContent(byte[] bytes, int offset) throws EncodingFormatException { offset = offset + encodeCommonPart(bytes, offset); @@ -61,23 +62,41 @@ public class SsbGroup extends SsbCommonTicketPart { bits.put(offset, isReturnJourney); 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; + if (lastDayOfValidity < 0 || lastDayOfValidity > 511) { + throw new EncodingFormatException("SSB last day of validity too big"); + } bits.putInteger(offset, 9, lastDayOfValidity); offset = offset + 9; offset = stations.encode(offset, bytes); + if (groupName.length() > 12) { + throw new EncodingFormatException("SSB group name too big"); + } bits.putChar6String(offset, 72,groupName); offset = offset + 72; + if (counterMarkNumber < 0 || counterMarkNumber > 246) { + throw new EncodingFormatException("SSB number of countermark too big"); + } bits.putInteger(offset, 9,counterMarkNumber); offset = offset + 9; + if (infoCode < 0 || infoCode > 9999) { + throw new EncodingFormatException("SSB info code too big"); + } bits.putInteger(offset, 14, infoCode); offset = offset + 14; + if (text.length() > 24) { + throw new EncodingFormatException("SSB text too big"); + } bits.putChar6String(offset, 144, text); offset = offset + 144; -- cgit v1.2.3