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/SsbNonReservation.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src/main/java/org/uic/barcode/ssbFrame/SsbNonReservation.java') diff --git a/src/main/java/org/uic/barcode/ssbFrame/SsbNonReservation.java b/src/main/java/org/uic/barcode/ssbFrame/SsbNonReservation.java index a1fb3ae..80fc2bc 100644 --- a/src/main/java/org/uic/barcode/ssbFrame/SsbNonReservation.java +++ b/src/main/java/org/uic/barcode/ssbFrame/SsbNonReservation.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 SsbNonReservation extends SsbCommonTicketPart { @@ -42,7 +43,7 @@ public class SsbNonReservation extends SsbCommonTicketPart { } @Override - protected int encodeContent(byte[] bytes, int offset) { + protected int encodeContent(byte[] bytes, int offset) throws EncodingFormatException { offset = offset + encodeCommonPart(bytes, offset); @@ -51,17 +52,29 @@ public class SsbNonReservation 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 (infoCode < 0 || infoCode > 9999) { + throw new EncodingFormatException("SSB info code too big"); + } bits.putInteger(offset, 14, infoCode); offset = offset + 14; + if (text.length() > 37) { + throw new EncodingFormatException("SSB text too big"); + } bits.putChar6String(offset, 222, text); offset = offset + 222; -- cgit v1.2.3