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 --- src/main/java/org/uic/barcode/ssbFrame/SsbHeader.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src/main/java/org/uic/barcode/ssbFrame/SsbHeader.java') diff --git a/src/main/java/org/uic/barcode/ssbFrame/SsbHeader.java b/src/main/java/org/uic/barcode/ssbFrame/SsbHeader.java index 2ea4a51..48c8eaf 100644 --- a/src/main/java/org/uic/barcode/ssbFrame/SsbHeader.java +++ b/src/main/java/org/uic/barcode/ssbFrame/SsbHeader.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 SsbHeader extends SsbTicketPart { @@ -40,13 +41,28 @@ public class SsbHeader extends SsbTicketPart { } - public int encodeContent(byte[] bytes, int offset) { + public int encodeContent(byte[] bytes, int offset) throws EncodingFormatException { BitBuffer bits = new ByteBitBuffer(bytes); + if (version < 0 || version > 15) { + throw new EncodingFormatException("SSB Version too big"); + } + bits.putInteger(0, 4, version); + + if (issuer < 0 || issuer > 9999) { + throw new EncodingFormatException("SSB Issuer code too big"); + } + bits.putInteger(4, 14, issuer); + + if (keyId < 0 || keyId > 15) { + throw new EncodingFormatException("SSB Key Id too big"); + } + bits.putInteger(18, 4, keyId); + bits.putInteger(22, 5, ticketType.ordinal()); return 4 + 14 + 4 + 5; -- cgit v1.2.3