From d7d87c6004c814ebed0ffd9064468a92dde981db Mon Sep 17 00:00:00 2001 From: Stefan Feuerhahn Date: Wed, 17 Jun 2020 15:02:30 +0200 Subject: [PATCH] switched to newest snapshot of jasn1 which was renamed to asn1bean --- asn1/iso-acse-layer/compile.sh | 2 +- asn1/iso-presentation-layer/compile.sh | 2 +- asn1/mms/compile.sh | 2 +- asn1/mms/rename-berboolean.sh | 2 +- build.gradle.kts | 7 +- doc/openiec61850-user-guide.md | 2 +- .../internal/acse/asn1/AAREApdu.java | 180 ++++----- .../internal/acse/asn1/AARQApdu.java | 206 ++++++----- .../internal/acse/asn1/ACSEApdu.java | 41 ++- .../internal/acse/asn1/ACSERequirements.java | 4 +- .../acse/asn1/AEInvocationIdentifier.java | 4 +- .../internal/acse/asn1/AEQualifier.java | 29 +- .../internal/acse/asn1/AEQualifierForm2.java | 4 +- .../josistack/internal/acse/asn1/AETitle.java | 29 +- .../internal/acse/asn1/AETitleForm2.java | 4 +- .../acse/asn1/APInvocationIdentifier.java | 4 +- .../josistack/internal/acse/asn1/APTitle.java | 29 +- .../internal/acse/asn1/APTitleForm2.java | 4 +- .../acse/asn1/ApplicationContextName.java | 4 +- .../acse/asn1/ApplicationContextNameList.java | 54 +-- .../internal/acse/asn1/AssociateResult.java | 4 +- .../acse/asn1/AssociateSourceDiagnostic.java | 45 ++- .../acse/asn1/AssociationInformation.java | 54 +-- .../acse/asn1/AuthenticationValue.java | 41 ++- .../acse/asn1/ImplementationData.java | 4 +- .../internal/acse/asn1/MechanismName.java | 4 +- .../internal/acse/asn1/Myexternal.java | 111 +++--- .../internal/acse/asn1/Myexternal2.java | 111 +++--- .../internal/acse/asn1/OidValues.java | 4 +- .../internal/acse/asn1/RLREApdu.java | 68 ++-- .../internal/acse/asn1/RLRQApdu.java | 68 ++-- .../acse/asn1/ReleaseRequestReason.java | 4 +- .../acse/asn1/ReleaseResponseReason.java | 4 +- .../presentation/asn1/AbstractSyntaxName.java | 4 +- .../internal/presentation/asn1/CPAPPDU.java | 150 ++++---- .../internal/presentation/asn1/CPType.java | 166 +++++---- .../asn1/CalledPresentationSelector.java | 2 +- .../asn1/CallingPresentationSelector.java | 2 +- .../presentation/asn1/ContextList.java | 159 ++++---- .../presentation/asn1/DefaultContextName.java | 62 ++-- .../presentation/asn1/FullyEncodedData.java | 54 +-- .../presentation/asn1/ModeSelector.java | 52 +-- .../internal/presentation/asn1/PDVList.java | 109 +++--- .../PresentationContextDefinitionList.java | 2 +- ...esentationContextDefinitionResultList.java | 2 +- .../asn1/PresentationContextIdentifier.java | 4 +- .../asn1/PresentationRequirements.java | 4 +- .../asn1/PresentationSelector.java | 4 +- .../presentation/asn1/ProtocolVersion.java | 4 +- .../asn1/RespondingPresentationSelector.java | 2 +- .../internal/presentation/asn1/Result.java | 4 +- .../presentation/asn1/ResultList.java | 120 +++--- .../presentation/asn1/SimplyEncodedData.java | 4 +- .../presentation/asn1/TransferSyntaxName.java | 4 +- .../internal/presentation/asn1/UserData.java | 33 +- .../asn1/UserSessionRequirements.java | 4 +- .../internal/mms/asn1/AccessResult.java | 37 +- .../internal/mms/asn1/AlternateAccess.java | 82 +++-- .../mms/asn1/AlternateAccessSelection.java | 327 +++++++++-------- .../internal/mms/asn1/BasicIdentifier.java | 4 +- .../internal/mms/asn1/ConcludeRequestPDU.java | 4 +- .../internal/mms/asn1/ConfirmedErrorPDU.java | 66 ++-- .../mms/asn1/ConfirmedRequestPDU.java | 65 ++-- .../mms/asn1/ConfirmedResponsePDU.java | 65 ++-- .../mms/asn1/ConfirmedServiceRequest.java | 83 +++-- .../mms/asn1/ConfirmedServiceResponse.java | 73 ++-- .../openiec61850/internal/mms/asn1/Data.java | 177 +++++---- .../internal/mms/asn1/DataAccessError.java | 4 +- .../asn1/DefineNamedVariableListRequest.java | 67 ++-- .../asn1/DefineNamedVariableListResponse.java | 4 +- .../asn1/DeleteNamedVariableListRequest.java | 150 ++++---- .../asn1/DeleteNamedVariableListResponse.java | 62 ++-- .../internal/mms/asn1/DirectoryEntry.java | 62 ++-- .../internal/mms/asn1/FileAttributes.java | 66 ++-- .../internal/mms/asn1/FileCloseRequest.java | 2 +- .../internal/mms/asn1/FileCloseResponse.java | 4 +- .../internal/mms/asn1/FileDeleteRequest.java | 2 +- .../internal/mms/asn1/FileDeleteResponse.java | 4 +- .../mms/asn1/FileDirectoryRequest.java | 68 ++-- .../mms/asn1/FileDirectoryResponse.java | 112 +++--- .../internal/mms/asn1/FileName.java | 56 +-- .../internal/mms/asn1/FileOpenRequest.java | 62 ++-- .../internal/mms/asn1/FileOpenResponse.java | 62 ++-- .../internal/mms/asn1/FileReadRequest.java | 2 +- .../internal/mms/asn1/FileReadResponse.java | 66 ++-- .../internal/mms/asn1/FloatingPoint.java | 4 +- .../internal/mms/asn1/GetNameListRequest.java | 108 +++--- .../mms/asn1/GetNameListResponse.java | 109 +++--- ...GetNamedVariableListAttributesRequest.java | 2 +- ...etNamedVariableListAttributesResponse.java | 62 ++-- .../GetVariableAccessAttributesRequest.java | 35 +- .../GetVariableAccessAttributesResponse.java | 65 ++-- .../internal/mms/asn1/Identifier.java | 4 +- .../internal/mms/asn1/InformationReport.java | 114 +++--- .../internal/mms/asn1/InitiateErrorPDU.java | 2 +- .../internal/mms/asn1/InitiateRequestPDU.java | 136 ++++--- .../mms/asn1/InitiateResponsePDU.java | 136 ++++--- .../internal/mms/asn1/Integer16.java | 4 +- .../internal/mms/asn1/Integer32.java | 4 +- .../internal/mms/asn1/Integer8.java | 4 +- .../internal/mms/asn1/MMSString.java | 4 +- .../internal/mms/asn1/MMSpdu.java | 61 ++-- .../internal/mms/asn1/ObjectClass.java | 31 +- .../internal/mms/asn1/ObjectName.java | 93 ++--- .../mms/asn1/ParameterSupportOptions.java | 4 +- .../internal/mms/asn1/ReadRequest.java | 63 ++-- .../internal/mms/asn1/ReadResponse.java | 110 +++--- .../internal/mms/asn1/RejectPDU.java | 127 ++++--- .../internal/mms/asn1/ServiceError.java | 149 ++++---- .../mms/asn1/ServiceSupportOptions.java | 4 +- .../internal/mms/asn1/TimeOfDay.java | 4 +- .../internal/mms/asn1/TypeDescription.java | 343 ++++++++++-------- .../internal/mms/asn1/TypeSpecification.java | 33 +- .../internal/mms/asn1/UnconfirmedPDU.java | 59 +-- .../internal/mms/asn1/UnconfirmedService.java | 29 +- .../internal/mms/asn1/Unsigned16.java | 4 +- .../internal/mms/asn1/Unsigned32.java | 4 +- .../internal/mms/asn1/Unsigned8.java | 4 +- .../internal/mms/asn1/UtcTime.java | 4 +- .../mms/asn1/VariableAccessSpecification.java | 39 +- .../internal/mms/asn1/VariableDefs.java | 115 +++--- .../mms/asn1/VariableSpecification.java | 35 +- .../internal/mms/asn1/WriteRequest.java | 114 +++--- .../internal/mms/asn1/WriteResponse.java | 84 +++-- .../com/beanit/josistack/AcseAssociation.java | 10 +- .../com/beanit/openiec61850/BdaBitString.java | 2 +- .../com/beanit/openiec61850/BdaBoolean.java | 2 +- .../com/beanit/openiec61850/BdaInt128.java | 2 +- .../com/beanit/openiec61850/BdaInt16.java | 2 +- .../com/beanit/openiec61850/BdaInt16U.java | 2 +- .../com/beanit/openiec61850/BdaInt32.java | 2 +- .../com/beanit/openiec61850/BdaInt32U.java | 2 +- .../com/beanit/openiec61850/BdaInt64.java | 2 +- .../java/com/beanit/openiec61850/BdaInt8.java | 2 +- .../com/beanit/openiec61850/BdaInt8U.java | 2 +- .../beanit/openiec61850/BdaOctetString.java | 2 +- .../com/beanit/openiec61850/BdaTimestamp.java | 2 +- .../beanit/openiec61850/BdaVisibleString.java | 2 +- .../openiec61850/ClientAssociation.java | 10 +- .../openiec61850/ServerAssociation.java | 8 +- .../java/com/beanit/openiec61850/Urcb.java | 2 +- .../openiec61850/internal/BerBoolean.java | 17 +- 142 files changed, 3518 insertions(+), 2785 deletions(-) diff --git a/asn1/iso-acse-layer/compile.sh b/asn1/iso-acse-layer/compile.sh index 475f91f..a51c82d 100755 --- a/asn1/iso-acse-layer/compile.sh +++ b/asn1/iso-acse-layer/compile.sh @@ -4,4 +4,4 @@ cd `dirname $0` rm ../../src/main/java-gen/com/beanit/josistack/internal/acse/asn1/* -jasn1-compiler -o "../../src/main/java-gen/" -p "com.beanit.josistack.internal.acse" -f iso-acse-layer.asn -dv +asn1bean-compiler -o "../../src/main/java-gen/" -p "com.beanit.josistack.internal.acse" -f iso-acse-layer.asn -dv diff --git a/asn1/iso-presentation-layer/compile.sh b/asn1/iso-presentation-layer/compile.sh index 1d51017..d8a0863 100755 --- a/asn1/iso-presentation-layer/compile.sh +++ b/asn1/iso-presentation-layer/compile.sh @@ -3,4 +3,4 @@ cd `dirname $0` rm ../../src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/*.java -jasn1-compiler -o ../../src/main/java-gen/ -p com.beanit.josistack.internal.presentation -f iso-presentation-layer.asn -dv +asn1bean-compiler -o ../../src/main/java-gen/ -p com.beanit.josistack.internal.presentation -f iso-presentation-layer.asn -dv diff --git a/asn1/mms/compile.sh b/asn1/mms/compile.sh index d31112e..90566da 100755 --- a/asn1/mms/compile.sh +++ b/asn1/mms/compile.sh @@ -4,4 +4,4 @@ cd `dirname $0` rm -r ../../src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/* -jasn1-compiler -o "../../src/main/java-gen" -p "com.beanit.openiec61850.internal.mms" -f mms.asn -dv +asn1bean-compiler -o "../../src/main/java-gen" -p "com.beanit.openiec61850.internal.mms" -f mms.asn -dv diff --git a/asn1/mms/rename-berboolean.sh b/asn1/mms/rename-berboolean.sh index f87034d..3d1fa51 100755 --- a/asn1/mms/rename-berboolean.sh +++ b/asn1/mms/rename-berboolean.sh @@ -2,4 +2,4 @@ cd `dirname $0` -find ../../ -iname "*.java" | xargs sed -i 's/import com\.beanit\.jasn1\.ber\.types\.BerBoolean/import com\.beanit\.openiec61850\.internal\.BerBoolean/g' +find ../../ -iname "*.java" | xargs sed -i 's/import com\.beanit\.asn1bean\.ber\.types\.BerBoolean/import com\.beanit\.openiec61850\.internal\.BerBoolean/g' diff --git a/build.gradle.kts b/build.gradle.kts index 3ab1bf1..0215353 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -31,7 +31,7 @@ val javaProjects: Set = allprojects val distributionProjects = javaProjects val docProjects = javaProjects val repositoryProjects = javaProjects -val cfgModuleName = "com.beanit.jasn1" +val cfgModuleName = "com.beanit.openiec61850" tasks.register("tar") { into(project.name) { @@ -65,7 +65,7 @@ tasks.register("tar") { //-----java root project configurations dependencies { - implementation("com.beanit:jasn1:1.11.0") + implementation("com.beanit:asn1bean:1.11.4-SNAPSHOT") implementation("com.toedter:jcalendar:1.4") implementation("org.slf4j:slf4j-api:1.7.25") runtimeOnly("ch.qos.logback:logback-classic:1.2.3") @@ -78,7 +78,7 @@ tasks["jar"].withConvention(aQute.bnd.gradle.BundleTaskConvention::class) { Bundle-Name: OpenIEC61850 Bundle-SymbolicName: ${project.extra["cfgModuleName"]} -exportcontents: !*.internal.*,* - Import-Package: com.beanit.jasn1.*,javax.net,*;resolution:=optional + Import-Package: com.beanit.asn1bean.*,javax.net,*;resolution:=optional """) } @@ -138,6 +138,7 @@ configure(javaProjects) { repositories { mavenCentral() + mavenLocal() } java { diff --git a/doc/openiec61850-user-guide.md b/doc/openiec61850-user-guide.md index f839551..188c91c 100644 --- a/doc/openiec61850-user-guide.md +++ b/doc/openiec61850-user-guide.md @@ -15,7 +15,7 @@ After extracting the distribution tar file, the OpenIEC61850 library can be foun Besides the OpenIEC61850 library the folder *build/libs-all/* contains the following external libraries: -* *jasn1* - the ASN.1 BER encoding/decoding library by beanit, license: Apache 2.0, https://www.beanit.com +* *asn1bean* - the ASN.1 BER encoding/decoding library by beanit, license: Apache 2.0, https://www.beanit.com * *slf4j-api* - a popular logging API. It is only needed if openiec61850 is used to implement a server. The client part does not log anything. License: MIT, http://www.slf4j.org diff --git a/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/AAREApdu.java b/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/AAREApdu.java index a9bd930..a5eeab8 100644 --- a/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/AAREApdu.java +++ b/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/AAREApdu.java @@ -1,12 +1,12 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.josistack.internal.acse.asn1; -import com.beanit.jasn1.ber.BerLength; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerBitString; -import com.beanit.jasn1.ber.types.BerObjectIdentifier; -import com.beanit.jasn1.ber.types.BerType; +import com.beanit.asn1bean.ber.BerLength; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerBitString; +import com.beanit.asn1bean.ber.types.BerObjectIdentifier; +import com.beanit.asn1bean.ber.types.BerType; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -16,7 +16,7 @@ public class AAREApdu implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.APPLICATION_CLASS, BerTag.CONSTRUCTED, 1); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private BerBitString protocolVersion = null; private BerObjectIdentifier applicationContextName = null; private AssociateResult result = null; @@ -152,6 +152,7 @@ public class AAREApdu implements BerType, Serializable { this.userInformation = userInformation; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -159,9 +160,7 @@ public class AAREApdu implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -288,160 +287,174 @@ public class AAREApdu implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); + tlByteCount += length.decode(is); + int lengthVal = length.val; + vByteCount += berTag.decode(is); - int totalLength = length.val; - codeLength += totalLength; - - subCodeLength += berTag.decode(is); if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) { protocolVersion = new BerBitString(); - subCodeLength += protocolVersion.decode(is, false); - subCodeLength += berTag.decode(is); + vByteCount += protocolVersion.decode(is, false); + vByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) { - subCodeLength += length.decode(is); + vByteCount += length.decode(is); applicationContextName = new BerObjectIdentifier(); - subCodeLength += applicationContextName.decode(is, true); - subCodeLength += berTag.decode(is); + vByteCount += applicationContextName.decode(is, true); + vByteCount += length.readEocIfIndefinite(is); + vByteCount += berTag.decode(is); } else { - throw new IOException("Tag does not match the mandatory sequence element tag."); + throw new IOException("Tag does not match mandatory sequence component."); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 2)) { - subCodeLength += length.decode(is); + vByteCount += length.decode(is); result = new AssociateResult(); - subCodeLength += result.decode(is, true); - subCodeLength += berTag.decode(is); + vByteCount += result.decode(is, true); + vByteCount += length.readEocIfIndefinite(is); + vByteCount += berTag.decode(is); } else { - throw new IOException("Tag does not match the mandatory sequence element tag."); + throw new IOException("Tag does not match mandatory sequence component."); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 3)) { - subCodeLength += length.decode(is); + vByteCount += length.decode(is); resultSourceDiagnostic = new AssociateSourceDiagnostic(); - subCodeLength += resultSourceDiagnostic.decode(is, null); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += resultSourceDiagnostic.decode(is, null); + vByteCount += length.readEocIfIndefinite(is); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } - subCodeLength += berTag.decode(is); + vByteCount += berTag.decode(is); } else { - throw new IOException("Tag does not match the mandatory sequence element tag."); + throw new IOException("Tag does not match mandatory sequence component."); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 4)) { - subCodeLength += length.decode(is); + vByteCount += length.decode(is); respondingAPTitle = new APTitle(); - subCodeLength += respondingAPTitle.decode(is, null); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += respondingAPTitle.decode(is, null); + vByteCount += length.readEocIfIndefinite(is); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } - subCodeLength += berTag.decode(is); + vByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 5)) { - subCodeLength += length.decode(is); + vByteCount += length.decode(is); respondingAEQualifier = new AEQualifier(); - subCodeLength += respondingAEQualifier.decode(is, null); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += respondingAEQualifier.decode(is, null); + vByteCount += length.readEocIfIndefinite(is); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } - subCodeLength += berTag.decode(is); + vByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 6)) { - subCodeLength += length.decode(is); + vByteCount += length.decode(is); respondingAPInvocationIdentifier = new APInvocationIdentifier(); - subCodeLength += respondingAPInvocationIdentifier.decode(is, true); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += respondingAPInvocationIdentifier.decode(is, true); + vByteCount += length.readEocIfIndefinite(is); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } - subCodeLength += berTag.decode(is); + vByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 7)) { - subCodeLength += length.decode(is); + vByteCount += length.decode(is); respondingAEInvocationIdentifier = new AEInvocationIdentifier(); - subCodeLength += respondingAEInvocationIdentifier.decode(is, true); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += respondingAEInvocationIdentifier.decode(is, true); + vByteCount += length.readEocIfIndefinite(is); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } - subCodeLength += berTag.decode(is); + vByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 8)) { responderAcseRequirements = new ACSERequirements(); - subCodeLength += responderAcseRequirements.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += responderAcseRequirements.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } - subCodeLength += berTag.decode(is); + vByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 9)) { mechanismName = new MechanismName(); - subCodeLength += mechanismName.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += mechanismName.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } - subCodeLength += berTag.decode(is); + vByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 10)) { - subCodeLength += length.decode(is); + vByteCount += length.decode(is); respondingAuthenticationValue = new AuthenticationValue(); - subCodeLength += respondingAuthenticationValue.decode(is, null); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += respondingAuthenticationValue.decode(is, null); + vByteCount += length.readEocIfIndefinite(is); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } - subCodeLength += berTag.decode(is); + vByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 11)) { applicationContextNameList = new ApplicationContextNameList(); - subCodeLength += applicationContextNameList.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += applicationContextNameList.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } - subCodeLength += berTag.decode(is); + vByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 29)) { implementationInformation = new ImplementationData(); - subCodeLength += implementationInformation.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += implementationInformation.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } - subCodeLength += berTag.decode(is); + vByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 30)) { userInformation = new AssociationInformation(); - subCodeLength += userInformation.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += userInformation.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } + vByteCount += berTag.decode(is); } + + if (lengthVal < 0) { + if (!berTag.equals(0, 0, 0)) { + throw new IOException("Decoded sequence has wrong end of contents octets"); + } + vByteCount += BerLength.readEocByte(is); + return tlByteCount + vByteCount; + } + throw new IOException( - "Unexpected end of sequence, length tag: " - + totalLength - + ", actual sequence length: " - + subCodeLength); + "Unexpected end of sequence, length tag: " + lengthVal + ", bytes decoded: " + vByteCount); } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -450,6 +463,7 @@ public class AAREApdu implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/AARQApdu.java b/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/AARQApdu.java index 504834a..843934d 100644 --- a/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/AARQApdu.java +++ b/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/AARQApdu.java @@ -1,12 +1,12 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.josistack.internal.acse.asn1; -import com.beanit.jasn1.ber.BerLength; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerBitString; -import com.beanit.jasn1.ber.types.BerObjectIdentifier; -import com.beanit.jasn1.ber.types.BerType; +import com.beanit.asn1bean.ber.BerLength; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerBitString; +import com.beanit.asn1bean.ber.types.BerObjectIdentifier; +import com.beanit.asn1bean.ber.types.BerType; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -16,7 +16,7 @@ public class AARQApdu implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.APPLICATION_CLASS, BerTag.CONSTRUCTED, 0); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private BerBitString protocolVersion = null; private BerObjectIdentifier applicationContextName = null; private APTitle calledAPTitle = null; @@ -170,6 +170,7 @@ public class AARQApdu implements BerType, Serializable { this.userInformation = userInformation; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -177,9 +178,7 @@ public class AARQApdu implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -328,182 +327,198 @@ public class AARQApdu implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); + tlByteCount += length.decode(is); + int lengthVal = length.val; + vByteCount += berTag.decode(is); - int totalLength = length.val; - codeLength += totalLength; - - subCodeLength += berTag.decode(is); if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) { protocolVersion = new BerBitString(); - subCodeLength += protocolVersion.decode(is, false); - subCodeLength += berTag.decode(is); + vByteCount += protocolVersion.decode(is, false); + vByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) { - subCodeLength += length.decode(is); + vByteCount += length.decode(is); applicationContextName = new BerObjectIdentifier(); - subCodeLength += applicationContextName.decode(is, true); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += applicationContextName.decode(is, true); + vByteCount += length.readEocIfIndefinite(is); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } - subCodeLength += berTag.decode(is); + vByteCount += berTag.decode(is); } else { - throw new IOException("Tag does not match the mandatory sequence element tag."); + throw new IOException("Tag does not match mandatory sequence component."); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 2)) { - subCodeLength += length.decode(is); + vByteCount += length.decode(is); calledAPTitle = new APTitle(); - subCodeLength += calledAPTitle.decode(is, null); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += calledAPTitle.decode(is, null); + vByteCount += length.readEocIfIndefinite(is); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } - subCodeLength += berTag.decode(is); + vByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 3)) { - subCodeLength += length.decode(is); + vByteCount += length.decode(is); calledAEQualifier = new AEQualifier(); - subCodeLength += calledAEQualifier.decode(is, null); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += calledAEQualifier.decode(is, null); + vByteCount += length.readEocIfIndefinite(is); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } - subCodeLength += berTag.decode(is); + vByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 4)) { - subCodeLength += length.decode(is); + vByteCount += length.decode(is); calledAPInvocationIdentifier = new APInvocationIdentifier(); - subCodeLength += calledAPInvocationIdentifier.decode(is, true); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += calledAPInvocationIdentifier.decode(is, true); + vByteCount += length.readEocIfIndefinite(is); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } - subCodeLength += berTag.decode(is); + vByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 5)) { - subCodeLength += length.decode(is); + vByteCount += length.decode(is); calledAEInvocationIdentifier = new AEInvocationIdentifier(); - subCodeLength += calledAEInvocationIdentifier.decode(is, true); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += calledAEInvocationIdentifier.decode(is, true); + vByteCount += length.readEocIfIndefinite(is); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } - subCodeLength += berTag.decode(is); + vByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 6)) { - subCodeLength += length.decode(is); + vByteCount += length.decode(is); callingAPTitle = new APTitle(); - subCodeLength += callingAPTitle.decode(is, null); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += callingAPTitle.decode(is, null); + vByteCount += length.readEocIfIndefinite(is); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } - subCodeLength += berTag.decode(is); + vByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 7)) { - subCodeLength += length.decode(is); + vByteCount += length.decode(is); callingAEQualifier = new AEQualifier(); - subCodeLength += callingAEQualifier.decode(is, null); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += callingAEQualifier.decode(is, null); + vByteCount += length.readEocIfIndefinite(is); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } - subCodeLength += berTag.decode(is); + vByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 8)) { - subCodeLength += length.decode(is); + vByteCount += length.decode(is); callingAPInvocationIdentifier = new APInvocationIdentifier(); - subCodeLength += callingAPInvocationIdentifier.decode(is, true); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += callingAPInvocationIdentifier.decode(is, true); + vByteCount += length.readEocIfIndefinite(is); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } - subCodeLength += berTag.decode(is); + vByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 9)) { - subCodeLength += length.decode(is); + vByteCount += length.decode(is); callingAEInvocationIdentifier = new AEInvocationIdentifier(); - subCodeLength += callingAEInvocationIdentifier.decode(is, true); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += callingAEInvocationIdentifier.decode(is, true); + vByteCount += length.readEocIfIndefinite(is); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } - subCodeLength += berTag.decode(is); + vByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 10)) { senderAcseRequirements = new ACSERequirements(); - subCodeLength += senderAcseRequirements.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += senderAcseRequirements.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } - subCodeLength += berTag.decode(is); + vByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 11)) { mechanismName = new MechanismName(); - subCodeLength += mechanismName.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += mechanismName.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } - subCodeLength += berTag.decode(is); + vByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 12)) { - subCodeLength += length.decode(is); + vByteCount += length.decode(is); callingAuthenticationValue = new AuthenticationValue(); - subCodeLength += callingAuthenticationValue.decode(is, null); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += callingAuthenticationValue.decode(is, null); + vByteCount += length.readEocIfIndefinite(is); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } - subCodeLength += berTag.decode(is); + vByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 13)) { applicationContextNameList = new ApplicationContextNameList(); - subCodeLength += applicationContextNameList.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += applicationContextNameList.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } - subCodeLength += berTag.decode(is); + vByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 29)) { implementationInformation = new ImplementationData(); - subCodeLength += implementationInformation.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += implementationInformation.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } - subCodeLength += berTag.decode(is); + vByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 30)) { userInformation = new AssociationInformation(); - subCodeLength += userInformation.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += userInformation.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } + vByteCount += berTag.decode(is); } + + if (lengthVal < 0) { + if (!berTag.equals(0, 0, 0)) { + throw new IOException("Decoded sequence has wrong end of contents octets"); + } + vByteCount += BerLength.readEocByte(is); + return tlByteCount + vByteCount; + } + throw new IOException( - "Unexpected end of sequence, length tag: " - + totalLength - + ", actual sequence length: " - + subCodeLength); + "Unexpected end of sequence, length tag: " + lengthVal + ", bytes decoded: " + vByteCount); } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -512,6 +527,7 @@ public class AARQApdu implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/ACSEApdu.java b/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/ACSEApdu.java index d8f8e2b..f6c9dce 100644 --- a/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/ACSEApdu.java +++ b/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/ACSEApdu.java @@ -1,9 +1,9 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.josistack.internal.acse.asn1; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerType; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerType; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -13,7 +13,7 @@ public class ACSEApdu implements BerType, Serializable { private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private AARQApdu aarq = null; private AAREApdu aare = null; private RLRQApdu rlrq = null; @@ -57,12 +57,11 @@ public class ACSEApdu implements BerType, Serializable { this.rlre = rlre; } + @Override public int encode(OutputStream reverseOS) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); return code.length; } @@ -90,45 +89,46 @@ public class ACSEApdu implements BerType, Serializable { throw new IOException("Error encoding CHOICE: No element of CHOICE was selected."); } + @Override public int decode(InputStream is) throws IOException { return decode(is, null); } public int decode(InputStream is, BerTag berTag) throws IOException { - int codeLength = 0; - BerTag passedTag = berTag; + int tlvByteCount = 0; + boolean tagWasPassed = (berTag != null); if (berTag == null) { berTag = new BerTag(); - codeLength += berTag.decode(is); + tlvByteCount += berTag.decode(is); } if (berTag.equals(AARQApdu.tag)) { aarq = new AARQApdu(); - codeLength += aarq.decode(is, false); - return codeLength; + tlvByteCount += aarq.decode(is, false); + return tlvByteCount; } if (berTag.equals(AAREApdu.tag)) { aare = new AAREApdu(); - codeLength += aare.decode(is, false); - return codeLength; + tlvByteCount += aare.decode(is, false); + return tlvByteCount; } if (berTag.equals(RLRQApdu.tag)) { rlrq = new RLRQApdu(); - codeLength += rlrq.decode(is, false); - return codeLength; + tlvByteCount += rlrq.decode(is, false); + return tlvByteCount; } if (berTag.equals(RLREApdu.tag)) { rlre = new RLREApdu(); - codeLength += rlre.decode(is, false); - return codeLength; + tlvByteCount += rlre.decode(is, false); + return tlvByteCount; } - if (passedTag != null) { + if (tagWasPassed) { return 0; } @@ -141,6 +141,7 @@ public class ACSEApdu implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/ACSERequirements.java b/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/ACSERequirements.java index 34d9556..4edbe52 100644 --- a/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/ACSERequirements.java +++ b/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/ACSERequirements.java @@ -1,7 +1,7 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.josistack.internal.acse.asn1; -import com.beanit.jasn1.ber.types.BerBitString; +import com.beanit.asn1bean.ber.types.BerBitString; public class ACSERequirements extends BerBitString { diff --git a/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/AEInvocationIdentifier.java b/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/AEInvocationIdentifier.java index e74a710..20de2a9 100644 --- a/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/AEInvocationIdentifier.java +++ b/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/AEInvocationIdentifier.java @@ -1,7 +1,7 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.josistack.internal.acse.asn1; -import com.beanit.jasn1.ber.types.BerInteger; +import com.beanit.asn1bean.ber.types.BerInteger; import java.math.BigInteger; public class AEInvocationIdentifier extends BerInteger { diff --git a/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/AEQualifier.java b/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/AEQualifier.java index 9170081..e9733c3 100644 --- a/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/AEQualifier.java +++ b/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/AEQualifier.java @@ -1,9 +1,9 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.josistack.internal.acse.asn1; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerType; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerType; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -13,7 +13,7 @@ public class AEQualifier implements BerType, Serializable { private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private AEQualifierForm2 aeQualifierForm2 = null; public AEQualifier() {} @@ -30,12 +30,11 @@ public class AEQualifier implements BerType, Serializable { this.aeQualifierForm2 = aeQualifierForm2; } + @Override public int encode(OutputStream reverseOS) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); return code.length; } @@ -48,27 +47,28 @@ public class AEQualifier implements BerType, Serializable { throw new IOException("Error encoding CHOICE: No element of CHOICE was selected."); } + @Override public int decode(InputStream is) throws IOException { return decode(is, null); } public int decode(InputStream is, BerTag berTag) throws IOException { - int codeLength = 0; - BerTag passedTag = berTag; + int tlvByteCount = 0; + boolean tagWasPassed = (berTag != null); if (berTag == null) { berTag = new BerTag(); - codeLength += berTag.decode(is); + tlvByteCount += berTag.decode(is); } if (berTag.equals(AEQualifierForm2.tag)) { aeQualifierForm2 = new AEQualifierForm2(); - codeLength += aeQualifierForm2.decode(is, false); - return codeLength; + tlvByteCount += aeQualifierForm2.decode(is, false); + return tlvByteCount; } - if (passedTag != null) { + if (tagWasPassed) { return 0; } @@ -81,6 +81,7 @@ public class AEQualifier implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/AEQualifierForm2.java b/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/AEQualifierForm2.java index d42d585..08e67d1 100644 --- a/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/AEQualifierForm2.java +++ b/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/AEQualifierForm2.java @@ -1,7 +1,7 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.josistack.internal.acse.asn1; -import com.beanit.jasn1.ber.types.BerInteger; +import com.beanit.asn1bean.ber.types.BerInteger; import java.math.BigInteger; public class AEQualifierForm2 extends BerInteger { diff --git a/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/AETitle.java b/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/AETitle.java index d198314..0039e05 100644 --- a/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/AETitle.java +++ b/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/AETitle.java @@ -1,9 +1,9 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.josistack.internal.acse.asn1; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerType; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerType; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -13,7 +13,7 @@ public class AETitle implements BerType, Serializable { private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private AETitleForm2 aeTitleForm2 = null; public AETitle() {} @@ -30,12 +30,11 @@ public class AETitle implements BerType, Serializable { this.aeTitleForm2 = aeTitleForm2; } + @Override public int encode(OutputStream reverseOS) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); return code.length; } @@ -48,27 +47,28 @@ public class AETitle implements BerType, Serializable { throw new IOException("Error encoding CHOICE: No element of CHOICE was selected."); } + @Override public int decode(InputStream is) throws IOException { return decode(is, null); } public int decode(InputStream is, BerTag berTag) throws IOException { - int codeLength = 0; - BerTag passedTag = berTag; + int tlvByteCount = 0; + boolean tagWasPassed = (berTag != null); if (berTag == null) { berTag = new BerTag(); - codeLength += berTag.decode(is); + tlvByteCount += berTag.decode(is); } if (berTag.equals(AETitleForm2.tag)) { aeTitleForm2 = new AETitleForm2(); - codeLength += aeTitleForm2.decode(is, false); - return codeLength; + tlvByteCount += aeTitleForm2.decode(is, false); + return tlvByteCount; } - if (passedTag != null) { + if (tagWasPassed) { return 0; } @@ -81,6 +81,7 @@ public class AETitle implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/AETitleForm2.java b/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/AETitleForm2.java index 9a6466d..c9e7441 100644 --- a/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/AETitleForm2.java +++ b/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/AETitleForm2.java @@ -1,7 +1,7 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.josistack.internal.acse.asn1; -import com.beanit.jasn1.ber.types.BerObjectIdentifier; +import com.beanit.asn1bean.ber.types.BerObjectIdentifier; public class AETitleForm2 extends BerObjectIdentifier { diff --git a/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/APInvocationIdentifier.java b/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/APInvocationIdentifier.java index 3d99f8b..feab1d6 100644 --- a/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/APInvocationIdentifier.java +++ b/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/APInvocationIdentifier.java @@ -1,7 +1,7 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.josistack.internal.acse.asn1; -import com.beanit.jasn1.ber.types.BerInteger; +import com.beanit.asn1bean.ber.types.BerInteger; import java.math.BigInteger; public class APInvocationIdentifier extends BerInteger { diff --git a/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/APTitle.java b/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/APTitle.java index 642f324..e286ed6 100644 --- a/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/APTitle.java +++ b/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/APTitle.java @@ -1,9 +1,9 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.josistack.internal.acse.asn1; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerType; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerType; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -13,7 +13,7 @@ public class APTitle implements BerType, Serializable { private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private APTitleForm2 apTitleForm2 = null; public APTitle() {} @@ -30,12 +30,11 @@ public class APTitle implements BerType, Serializable { this.apTitleForm2 = apTitleForm2; } + @Override public int encode(OutputStream reverseOS) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); return code.length; } @@ -48,27 +47,28 @@ public class APTitle implements BerType, Serializable { throw new IOException("Error encoding CHOICE: No element of CHOICE was selected."); } + @Override public int decode(InputStream is) throws IOException { return decode(is, null); } public int decode(InputStream is, BerTag berTag) throws IOException { - int codeLength = 0; - BerTag passedTag = berTag; + int tlvByteCount = 0; + boolean tagWasPassed = (berTag != null); if (berTag == null) { berTag = new BerTag(); - codeLength += berTag.decode(is); + tlvByteCount += berTag.decode(is); } if (berTag.equals(APTitleForm2.tag)) { apTitleForm2 = new APTitleForm2(); - codeLength += apTitleForm2.decode(is, false); - return codeLength; + tlvByteCount += apTitleForm2.decode(is, false); + return tlvByteCount; } - if (passedTag != null) { + if (tagWasPassed) { return 0; } @@ -81,6 +81,7 @@ public class APTitle implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/APTitleForm2.java b/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/APTitleForm2.java index ba478ca..e2e6cc2 100644 --- a/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/APTitleForm2.java +++ b/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/APTitleForm2.java @@ -1,7 +1,7 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.josistack.internal.acse.asn1; -import com.beanit.jasn1.ber.types.BerObjectIdentifier; +import com.beanit.asn1bean.ber.types.BerObjectIdentifier; public class APTitleForm2 extends BerObjectIdentifier { diff --git a/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/ApplicationContextName.java b/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/ApplicationContextName.java index 79f942b..501ee3d 100644 --- a/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/ApplicationContextName.java +++ b/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/ApplicationContextName.java @@ -1,7 +1,7 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.josistack.internal.acse.asn1; -import com.beanit.jasn1.ber.types.BerObjectIdentifier; +import com.beanit.asn1bean.ber.types.BerObjectIdentifier; public class ApplicationContextName extends BerObjectIdentifier { diff --git a/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/ApplicationContextNameList.java b/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/ApplicationContextNameList.java index e5d65f4..1b1c42e 100644 --- a/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/ApplicationContextNameList.java +++ b/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/ApplicationContextNameList.java @@ -1,10 +1,10 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.josistack.internal.acse.asn1; -import com.beanit.jasn1.ber.BerLength; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerType; +import com.beanit.asn1bean.ber.BerLength; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerType; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -17,7 +17,7 @@ public class ApplicationContextNameList implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private List seqOf = null; public ApplicationContextNameList() { @@ -35,6 +35,7 @@ public class ApplicationContextNameList implements BerType, Serializable { return seqOf; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -42,9 +43,7 @@ public class ApplicationContextNameList implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -65,36 +64,46 @@ public class ApplicationContextNameList implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; + BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); - int totalLength = length.val; + tlByteCount += length.decode(is); + int lengthVal = length.val; + + while (vByteCount < lengthVal || lengthVal < 0) { + vByteCount += berTag.decode(is); + + if (lengthVal < 0 && berTag.equals(0, 0, 0)) { + vByteCount += BerLength.readEocByte(is); + break; + } - while (subCodeLength < totalLength) { + if (!berTag.equals(ApplicationContextName.tag)) { + throw new IOException("Tag does not match mandatory sequence of/set of component."); + } ApplicationContextName element = new ApplicationContextName(); - subCodeLength += element.decode(is, true); + vByteCount += element.decode(is, false); seqOf.add(element); } - if (subCodeLength != totalLength) { + if (lengthVal >= 0 && vByteCount != lengthVal) { throw new IOException( "Decoded SequenceOf or SetOf has wrong length. Expected " - + totalLength + + lengthVal + " but has " - + subCodeLength); + + vByteCount); } - codeLength += subCodeLength; - - return codeLength; + return tlByteCount + vByteCount; } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -103,6 +112,7 @@ public class ApplicationContextNameList implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/AssociateResult.java b/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/AssociateResult.java index e902038..39cad20 100644 --- a/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/AssociateResult.java +++ b/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/AssociateResult.java @@ -1,7 +1,7 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.josistack.internal.acse.asn1; -import com.beanit.jasn1.ber.types.BerInteger; +import com.beanit.asn1bean.ber.types.BerInteger; import java.math.BigInteger; public class AssociateResult extends BerInteger { diff --git a/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/AssociateSourceDiagnostic.java b/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/AssociateSourceDiagnostic.java index 4556532..eb2ef1e 100644 --- a/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/AssociateSourceDiagnostic.java +++ b/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/AssociateSourceDiagnostic.java @@ -1,11 +1,11 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.josistack.internal.acse.asn1; -import com.beanit.jasn1.ber.BerLength; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerInteger; -import com.beanit.jasn1.ber.types.BerType; +import com.beanit.asn1bean.ber.BerLength; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerInteger; +import com.beanit.asn1bean.ber.types.BerType; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -15,7 +15,7 @@ public class AssociateSourceDiagnostic implements BerType, Serializable { private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private BerInteger acseServiceUser = null; private BerInteger acseServiceProvider = null; @@ -41,12 +41,11 @@ public class AssociateSourceDiagnostic implements BerType, Serializable { this.acseServiceProvider = acseServiceProvider; } + @Override public int encode(OutputStream reverseOS) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); return code.length; } @@ -76,35 +75,40 @@ public class AssociateSourceDiagnostic implements BerType, Serializable { throw new IOException("Error encoding CHOICE: No element of CHOICE was selected."); } + @Override public int decode(InputStream is) throws IOException { return decode(is, null); } public int decode(InputStream is, BerTag berTag) throws IOException { - int codeLength = 0; - BerTag passedTag = berTag; + int tlvByteCount = 0; + boolean tagWasPassed = (berTag != null); if (berTag == null) { berTag = new BerTag(); - codeLength += berTag.decode(is); + tlvByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) { - codeLength += BerLength.skip(is); + BerLength explicitTagLength = new BerLength(); + tlvByteCount += explicitTagLength.decode(is); acseServiceUser = new BerInteger(); - codeLength += acseServiceUser.decode(is, true); - return codeLength; + tlvByteCount += acseServiceUser.decode(is, true); + tlvByteCount += explicitTagLength.readEocIfIndefinite(is); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 2)) { - codeLength += BerLength.skip(is); + BerLength explicitTagLength = new BerLength(); + tlvByteCount += explicitTagLength.decode(is); acseServiceProvider = new BerInteger(); - codeLength += acseServiceProvider.decode(is, true); - return codeLength; + tlvByteCount += acseServiceProvider.decode(is, true); + tlvByteCount += explicitTagLength.readEocIfIndefinite(is); + return tlvByteCount; } - if (passedTag != null) { + if (tagWasPassed) { return 0; } @@ -117,6 +121,7 @@ public class AssociateSourceDiagnostic implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/AssociationInformation.java b/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/AssociationInformation.java index c1f13ae..9ce16e7 100644 --- a/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/AssociationInformation.java +++ b/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/AssociationInformation.java @@ -1,10 +1,10 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.josistack.internal.acse.asn1; -import com.beanit.jasn1.ber.BerLength; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerType; +import com.beanit.asn1bean.ber.BerLength; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerType; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -17,7 +17,7 @@ public class AssociationInformation implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private List seqOf = null; public AssociationInformation() { @@ -35,6 +35,7 @@ public class AssociationInformation implements BerType, Serializable { return seqOf; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -42,9 +43,7 @@ public class AssociationInformation implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -65,36 +64,46 @@ public class AssociationInformation implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; + BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); - int totalLength = length.val; + tlByteCount += length.decode(is); + int lengthVal = length.val; + + while (vByteCount < lengthVal || lengthVal < 0) { + vByteCount += berTag.decode(is); + + if (lengthVal < 0 && berTag.equals(0, 0, 0)) { + vByteCount += BerLength.readEocByte(is); + break; + } - while (subCodeLength < totalLength) { + if (!berTag.equals(Myexternal.tag)) { + throw new IOException("Tag does not match mandatory sequence of/set of component."); + } Myexternal element = new Myexternal(); - subCodeLength += element.decode(is, true); + vByteCount += element.decode(is, false); seqOf.add(element); } - if (subCodeLength != totalLength) { + if (lengthVal >= 0 && vByteCount != lengthVal) { throw new IOException( "Decoded SequenceOf or SetOf has wrong length. Expected " - + totalLength + + lengthVal + " but has " - + subCodeLength); + + vByteCount); } - codeLength += subCodeLength; - - return codeLength; + return tlByteCount + vByteCount; } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -103,6 +112,7 @@ public class AssociationInformation implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/AuthenticationValue.java b/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/AuthenticationValue.java index 8f360f4..e103ee0 100644 --- a/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/AuthenticationValue.java +++ b/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/AuthenticationValue.java @@ -1,11 +1,11 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.josistack.internal.acse.asn1; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerBitString; -import com.beanit.jasn1.ber.types.BerType; -import com.beanit.jasn1.ber.types.string.BerGraphicString; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerBitString; +import com.beanit.asn1bean.ber.types.BerType; +import com.beanit.asn1bean.ber.types.string.BerGraphicString; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -15,7 +15,7 @@ public class AuthenticationValue implements BerType, Serializable { private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private BerGraphicString charstring = null; private BerBitString bitstring = null; private Myexternal2 external = null; @@ -50,12 +50,11 @@ public class AuthenticationValue implements BerType, Serializable { this.external = external; } + @Override public int encode(OutputStream reverseOS) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); return code.length; } @@ -87,39 +86,40 @@ public class AuthenticationValue implements BerType, Serializable { throw new IOException("Error encoding CHOICE: No element of CHOICE was selected."); } + @Override public int decode(InputStream is) throws IOException { return decode(is, null); } public int decode(InputStream is, BerTag berTag) throws IOException { - int codeLength = 0; - BerTag passedTag = berTag; + int tlvByteCount = 0; + boolean tagWasPassed = (berTag != null); if (berTag == null) { berTag = new BerTag(); - codeLength += berTag.decode(is); + tlvByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) { charstring = new BerGraphicString(); - codeLength += charstring.decode(is, false); - return codeLength; + tlvByteCount += charstring.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) { bitstring = new BerBitString(); - codeLength += bitstring.decode(is, false); - return codeLength; + tlvByteCount += bitstring.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 2)) { external = new Myexternal2(); - codeLength += external.decode(is, false); - return codeLength; + tlvByteCount += external.decode(is, false); + return tlvByteCount; } - if (passedTag != null) { + if (tagWasPassed) { return 0; } @@ -132,6 +132,7 @@ public class AuthenticationValue implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/ImplementationData.java b/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/ImplementationData.java index 4a12278..58225d4 100644 --- a/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/ImplementationData.java +++ b/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/ImplementationData.java @@ -1,7 +1,7 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.josistack.internal.acse.asn1; -import com.beanit.jasn1.ber.types.string.BerGraphicString; +import com.beanit.asn1bean.ber.types.string.BerGraphicString; public class ImplementationData extends BerGraphicString { diff --git a/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/MechanismName.java b/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/MechanismName.java index 5d4ca70..da8b798 100644 --- a/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/MechanismName.java +++ b/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/MechanismName.java @@ -1,7 +1,7 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.josistack.internal.acse.asn1; -import com.beanit.jasn1.ber.types.BerObjectIdentifier; +import com.beanit.asn1bean.ber.types.BerObjectIdentifier; public class MechanismName extends BerObjectIdentifier { diff --git a/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/Myexternal.java b/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/Myexternal.java index f13ca0b..092869b 100644 --- a/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/Myexternal.java +++ b/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/Myexternal.java @@ -1,15 +1,15 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.josistack.internal.acse.asn1; -import com.beanit.jasn1.ber.BerLength; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerAny; -import com.beanit.jasn1.ber.types.BerBitString; -import com.beanit.jasn1.ber.types.BerInteger; -import com.beanit.jasn1.ber.types.BerObjectIdentifier; -import com.beanit.jasn1.ber.types.BerOctetString; -import com.beanit.jasn1.ber.types.BerType; +import com.beanit.asn1bean.ber.BerLength; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerAny; +import com.beanit.asn1bean.ber.types.BerBitString; +import com.beanit.asn1bean.ber.types.BerInteger; +import com.beanit.asn1bean.ber.types.BerObjectIdentifier; +import com.beanit.asn1bean.ber.types.BerOctetString; +import com.beanit.asn1bean.ber.types.BerType; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -19,11 +19,10 @@ public class Myexternal implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 8); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private BerObjectIdentifier directReference = null; private BerInteger indirectReference = null; private Encoding encoding = null; - public Myexternal() {} public Myexternal(byte[] code) { @@ -54,6 +53,7 @@ public class Myexternal implements BerType, Serializable { this.encoding = encoding; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -61,9 +61,7 @@ public class Myexternal implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -90,48 +88,59 @@ public class Myexternal implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; + int numDecodedBytes; BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); - - int totalLength = length.val; - codeLength += totalLength; + tlByteCount += length.decode(is); + int lengthVal = length.val; + vByteCount += berTag.decode(is); - subCodeLength += berTag.decode(is); if (berTag.equals(BerObjectIdentifier.tag)) { directReference = new BerObjectIdentifier(); - subCodeLength += directReference.decode(is, false); - subCodeLength += berTag.decode(is); + vByteCount += directReference.decode(is, false); + vByteCount += berTag.decode(is); } if (berTag.equals(BerInteger.tag)) { indirectReference = new BerInteger(); - subCodeLength += indirectReference.decode(is, false); - subCodeLength += berTag.decode(is); + vByteCount += indirectReference.decode(is, false); + vByteCount += berTag.decode(is); } encoding = new Encoding(); - subCodeLength += encoding.decode(is, berTag); - if (subCodeLength == totalLength) { - return codeLength; + numDecodedBytes = encoding.decode(is, berTag); + if (numDecodedBytes != 0) { + vByteCount += numDecodedBytes; + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; + } + vByteCount += berTag.decode(is); + } else { + throw new IOException("Tag does not match mandatory sequence component."); } + if (lengthVal < 0) { + if (!berTag.equals(0, 0, 0)) { + throw new IOException("Decoded sequence has wrong end of contents octets"); + } + vByteCount += BerLength.readEocByte(is); + return tlByteCount + vByteCount; + } + throw new IOException( - "Unexpected end of sequence, length tag: " - + totalLength - + ", actual sequence length: " - + subCodeLength); + "Unexpected end of sequence, length tag: " + lengthVal + ", bytes decoded: " + vByteCount); } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -140,6 +149,7 @@ public class Myexternal implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); @@ -194,7 +204,7 @@ public class Myexternal implements BerType, Serializable { private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private BerAny singleASN1Type = null; private BerOctetString octetAligned = null; private BerBitString arbitrary = null; @@ -229,12 +239,11 @@ public class Myexternal implements BerType, Serializable { this.arbitrary = arbitrary; } + @Override public int encode(OutputStream reverseOS) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); return code.length; } @@ -270,40 +279,43 @@ public class Myexternal implements BerType, Serializable { throw new IOException("Error encoding CHOICE: No element of CHOICE was selected."); } + @Override public int decode(InputStream is) throws IOException { return decode(is, null); } public int decode(InputStream is, BerTag berTag) throws IOException { - int codeLength = 0; - BerTag passedTag = berTag; + int tlvByteCount = 0; + boolean tagWasPassed = (berTag != null); if (berTag == null) { berTag = new BerTag(); - codeLength += berTag.decode(is); + tlvByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) { - codeLength += BerLength.skip(is); + BerLength explicitTagLength = new BerLength(); + tlvByteCount += explicitTagLength.decode(is); singleASN1Type = new BerAny(); - codeLength += singleASN1Type.decode(is, null); - return codeLength; + tlvByteCount += singleASN1Type.decode(is, null); + tlvByteCount += explicitTagLength.readEocIfIndefinite(is); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) { octetAligned = new BerOctetString(); - codeLength += octetAligned.decode(is, false); - return codeLength; + tlvByteCount += octetAligned.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 2)) { arbitrary = new BerBitString(); - codeLength += arbitrary.decode(is, false); - return codeLength; + tlvByteCount += arbitrary.decode(is, false); + return tlvByteCount; } - if (passedTag != null) { + if (tagWasPassed) { return 0; } @@ -316,6 +328,7 @@ public class Myexternal implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/Myexternal2.java b/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/Myexternal2.java index 98f550b..bd22893 100644 --- a/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/Myexternal2.java +++ b/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/Myexternal2.java @@ -1,15 +1,15 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.josistack.internal.acse.asn1; -import com.beanit.jasn1.ber.BerLength; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerAny; -import com.beanit.jasn1.ber.types.BerBitString; -import com.beanit.jasn1.ber.types.BerInteger; -import com.beanit.jasn1.ber.types.BerObjectIdentifier; -import com.beanit.jasn1.ber.types.BerOctetString; -import com.beanit.jasn1.ber.types.BerType; +import com.beanit.asn1bean.ber.BerLength; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerAny; +import com.beanit.asn1bean.ber.types.BerBitString; +import com.beanit.asn1bean.ber.types.BerInteger; +import com.beanit.asn1bean.ber.types.BerObjectIdentifier; +import com.beanit.asn1bean.ber.types.BerOctetString; +import com.beanit.asn1bean.ber.types.BerType; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -19,11 +19,10 @@ public class Myexternal2 implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 8); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private BerObjectIdentifier directReference = null; private BerInteger indirectReference = null; private Encoding encoding = null; - public Myexternal2() {} public Myexternal2(byte[] code) { @@ -54,6 +53,7 @@ public class Myexternal2 implements BerType, Serializable { this.encoding = encoding; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -61,9 +61,7 @@ public class Myexternal2 implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -90,48 +88,59 @@ public class Myexternal2 implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; + int numDecodedBytes; BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); - - int totalLength = length.val; - codeLength += totalLength; + tlByteCount += length.decode(is); + int lengthVal = length.val; + vByteCount += berTag.decode(is); - subCodeLength += berTag.decode(is); if (berTag.equals(BerObjectIdentifier.tag)) { directReference = new BerObjectIdentifier(); - subCodeLength += directReference.decode(is, false); - subCodeLength += berTag.decode(is); + vByteCount += directReference.decode(is, false); + vByteCount += berTag.decode(is); } if (berTag.equals(BerInteger.tag)) { indirectReference = new BerInteger(); - subCodeLength += indirectReference.decode(is, false); - subCodeLength += berTag.decode(is); + vByteCount += indirectReference.decode(is, false); + vByteCount += berTag.decode(is); } encoding = new Encoding(); - subCodeLength += encoding.decode(is, berTag); - if (subCodeLength == totalLength) { - return codeLength; + numDecodedBytes = encoding.decode(is, berTag); + if (numDecodedBytes != 0) { + vByteCount += numDecodedBytes; + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; + } + vByteCount += berTag.decode(is); + } else { + throw new IOException("Tag does not match mandatory sequence component."); } + if (lengthVal < 0) { + if (!berTag.equals(0, 0, 0)) { + throw new IOException("Decoded sequence has wrong end of contents octets"); + } + vByteCount += BerLength.readEocByte(is); + return tlByteCount + vByteCount; + } + throw new IOException( - "Unexpected end of sequence, length tag: " - + totalLength - + ", actual sequence length: " - + subCodeLength); + "Unexpected end of sequence, length tag: " + lengthVal + ", bytes decoded: " + vByteCount); } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -140,6 +149,7 @@ public class Myexternal2 implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); @@ -194,7 +204,7 @@ public class Myexternal2 implements BerType, Serializable { private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private BerAny singleASN1Type = null; private BerOctetString octetAligned = null; private BerBitString arbitrary = null; @@ -229,12 +239,11 @@ public class Myexternal2 implements BerType, Serializable { this.arbitrary = arbitrary; } + @Override public int encode(OutputStream reverseOS) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); return code.length; } @@ -270,40 +279,43 @@ public class Myexternal2 implements BerType, Serializable { throw new IOException("Error encoding CHOICE: No element of CHOICE was selected."); } + @Override public int decode(InputStream is) throws IOException { return decode(is, null); } public int decode(InputStream is, BerTag berTag) throws IOException { - int codeLength = 0; - BerTag passedTag = berTag; + int tlvByteCount = 0; + boolean tagWasPassed = (berTag != null); if (berTag == null) { berTag = new BerTag(); - codeLength += berTag.decode(is); + tlvByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) { - codeLength += BerLength.skip(is); + BerLength explicitTagLength = new BerLength(); + tlvByteCount += explicitTagLength.decode(is); singleASN1Type = new BerAny(); - codeLength += singleASN1Type.decode(is, null); - return codeLength; + tlvByteCount += singleASN1Type.decode(is, null); + tlvByteCount += explicitTagLength.readEocIfIndefinite(is); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) { octetAligned = new BerOctetString(); - codeLength += octetAligned.decode(is, false); - return codeLength; + tlvByteCount += octetAligned.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 2)) { arbitrary = new BerBitString(); - codeLength += arbitrary.decode(is, false); - return codeLength; + tlvByteCount += arbitrary.decode(is, false); + return tlvByteCount; } - if (passedTag != null) { + if (tagWasPassed) { return 0; } @@ -316,6 +328,7 @@ public class Myexternal2 implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/OidValues.java b/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/OidValues.java index 1c02024..60e1533 100644 --- a/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/OidValues.java +++ b/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/OidValues.java @@ -1,7 +1,7 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.josistack.internal.acse.asn1; -import com.beanit.jasn1.ber.types.BerObjectIdentifier; +import com.beanit.asn1bean.ber.types.BerObjectIdentifier; public final class OidValues { public static final BerObjectIdentifier aCSEId = diff --git a/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/RLREApdu.java b/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/RLREApdu.java index 811f55a..0ce9c8b 100644 --- a/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/RLREApdu.java +++ b/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/RLREApdu.java @@ -1,10 +1,10 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.josistack.internal.acse.asn1; -import com.beanit.jasn1.ber.BerLength; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerType; +import com.beanit.asn1bean.ber.BerLength; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerType; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -14,7 +14,7 @@ public class RLREApdu implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.APPLICATION_CLASS, BerTag.CONSTRUCTED, 3); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private ReleaseResponseReason reason = null; private AssociationInformation userInformation = null; @@ -40,6 +40,7 @@ public class RLREApdu implements BerType, Serializable { this.userInformation = userInformation; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -47,9 +48,7 @@ public class RLREApdu implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -80,50 +79,56 @@ public class RLREApdu implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); - - int totalLength = length.val; - codeLength += totalLength; - - if (totalLength == 0) { - return codeLength; + tlByteCount += length.decode(is); + int lengthVal = length.val; + if (lengthVal == 0) { + return tlByteCount; } - subCodeLength += berTag.decode(is); + vByteCount += berTag.decode(is); + if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) { reason = new ReleaseResponseReason(); - subCodeLength += reason.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += reason.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } - subCodeLength += berTag.decode(is); + vByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 30)) { userInformation = new AssociationInformation(); - subCodeLength += userInformation.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += userInformation.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } + vByteCount += berTag.decode(is); } + + if (lengthVal < 0) { + if (!berTag.equals(0, 0, 0)) { + throw new IOException("Decoded sequence has wrong end of contents octets"); + } + vByteCount += BerLength.readEocByte(is); + return tlByteCount + vByteCount; + } + throw new IOException( - "Unexpected end of sequence, length tag: " - + totalLength - + ", actual sequence length: " - + subCodeLength); + "Unexpected end of sequence, length tag: " + lengthVal + ", bytes decoded: " + vByteCount); } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -132,6 +137,7 @@ public class RLREApdu implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/RLRQApdu.java b/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/RLRQApdu.java index f9bbd14..5d05971 100644 --- a/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/RLRQApdu.java +++ b/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/RLRQApdu.java @@ -1,10 +1,10 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.josistack.internal.acse.asn1; -import com.beanit.jasn1.ber.BerLength; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerType; +import com.beanit.asn1bean.ber.BerLength; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerType; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -14,7 +14,7 @@ public class RLRQApdu implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.APPLICATION_CLASS, BerTag.CONSTRUCTED, 2); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private ReleaseRequestReason reason = null; private AssociationInformation userInformation = null; @@ -40,6 +40,7 @@ public class RLRQApdu implements BerType, Serializable { this.userInformation = userInformation; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -47,9 +48,7 @@ public class RLRQApdu implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -80,50 +79,56 @@ public class RLRQApdu implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); - - int totalLength = length.val; - codeLength += totalLength; - - if (totalLength == 0) { - return codeLength; + tlByteCount += length.decode(is); + int lengthVal = length.val; + if (lengthVal == 0) { + return tlByteCount; } - subCodeLength += berTag.decode(is); + vByteCount += berTag.decode(is); + if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) { reason = new ReleaseRequestReason(); - subCodeLength += reason.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += reason.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } - subCodeLength += berTag.decode(is); + vByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 30)) { userInformation = new AssociationInformation(); - subCodeLength += userInformation.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += userInformation.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } + vByteCount += berTag.decode(is); } + + if (lengthVal < 0) { + if (!berTag.equals(0, 0, 0)) { + throw new IOException("Decoded sequence has wrong end of contents octets"); + } + vByteCount += BerLength.readEocByte(is); + return tlByteCount + vByteCount; + } + throw new IOException( - "Unexpected end of sequence, length tag: " - + totalLength - + ", actual sequence length: " - + subCodeLength); + "Unexpected end of sequence, length tag: " + lengthVal + ", bytes decoded: " + vByteCount); } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -132,6 +137,7 @@ public class RLRQApdu implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/ReleaseRequestReason.java b/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/ReleaseRequestReason.java index 5142b71..b46c223 100644 --- a/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/ReleaseRequestReason.java +++ b/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/ReleaseRequestReason.java @@ -1,7 +1,7 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.josistack.internal.acse.asn1; -import com.beanit.jasn1.ber.types.BerInteger; +import com.beanit.asn1bean.ber.types.BerInteger; import java.math.BigInteger; public class ReleaseRequestReason extends BerInteger { diff --git a/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/ReleaseResponseReason.java b/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/ReleaseResponseReason.java index 673a950..bbc0da3 100644 --- a/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/ReleaseResponseReason.java +++ b/src/main/java-gen/com/beanit/josistack/internal/acse/asn1/ReleaseResponseReason.java @@ -1,7 +1,7 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.josistack.internal.acse.asn1; -import com.beanit.jasn1.ber.types.BerInteger; +import com.beanit.asn1bean.ber.types.BerInteger; import java.math.BigInteger; public class ReleaseResponseReason extends BerInteger { diff --git a/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/AbstractSyntaxName.java b/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/AbstractSyntaxName.java index dbb7d40..7e06aee 100644 --- a/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/AbstractSyntaxName.java +++ b/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/AbstractSyntaxName.java @@ -1,7 +1,7 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.josistack.internal.presentation.asn1; -import com.beanit.jasn1.ber.types.BerObjectIdentifier; +import com.beanit.asn1bean.ber.types.BerObjectIdentifier; public class AbstractSyntaxName extends BerObjectIdentifier { diff --git a/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/CPAPPDU.java b/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/CPAPPDU.java index 7ccf2d5..d39d5c1 100644 --- a/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/CPAPPDU.java +++ b/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/CPAPPDU.java @@ -1,10 +1,10 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.josistack.internal.presentation.asn1; -import com.beanit.jasn1.ber.BerLength; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerType; +import com.beanit.asn1bean.ber.BerLength; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerType; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -14,10 +14,9 @@ public class CPAPPDU implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 17); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private ModeSelector modeSelector = null; private NormalModeParameters normalModeParameters = null; - public CPAPPDU() {} public CPAPPDU(byte[] code) { @@ -40,6 +39,7 @@ public class CPAPPDU implements BerType, Serializable { this.normalModeParameters = normalModeParameters; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -47,9 +47,7 @@ public class CPAPPDU implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -78,43 +76,47 @@ public class CPAPPDU implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); + tlByteCount += length.decode(is); + int lengthVal = length.val; - int totalLength = length.val; - while (subCodeLength < totalLength) { - subCodeLength += berTag.decode(is); + while (vByteCount < lengthVal || lengthVal < 0) { + vByteCount += berTag.decode(is); if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) { modeSelector = new ModeSelector(); - subCodeLength += modeSelector.decode(is, false); + vByteCount += modeSelector.decode(is, false); } else if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 2)) { normalModeParameters = new NormalModeParameters(); - subCodeLength += normalModeParameters.decode(is, false); + vByteCount += normalModeParameters.decode(is, false); + } else if (lengthVal < 0 && berTag.equals(0, 0, 0)) { + vByteCount += BerLength.readEocByte(is); + return tlByteCount + vByteCount; + } else { + throw new IOException("Tag does not match any set component: " + berTag); } } - if (subCodeLength != totalLength) { + if (vByteCount != lengthVal) { throw new IOException( "Length of set does not match length tag, length tag: " - + totalLength + + lengthVal + ", actual set length: " - + subCodeLength); + + vByteCount); } - codeLength += subCodeLength; - - return codeLength; + return tlByteCount + vByteCount; } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -123,6 +125,7 @@ public class CPAPPDU implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); @@ -163,7 +166,7 @@ public class CPAPPDU implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private ProtocolVersion protocolVersion = null; private RespondingPresentationSelector respondingPresentationSelector = null; private PresentationContextDefinitionResultList presentationContextDefinitionResultList = null; @@ -227,6 +230,7 @@ public class CPAPPDU implements BerType, Serializable { this.userData = userData; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -234,9 +238,7 @@ public class CPAPPDU implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -292,85 +294,98 @@ public class CPAPPDU implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; + int numDecodedBytes; BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); - - int totalLength = length.val; - codeLength += totalLength; - - if (totalLength == 0) { - return codeLength; + tlByteCount += length.decode(is); + int lengthVal = length.val; + if (lengthVal == 0) { + return tlByteCount; } - subCodeLength += berTag.decode(is); + vByteCount += berTag.decode(is); + if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) { protocolVersion = new ProtocolVersion(); - subCodeLength += protocolVersion.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += protocolVersion.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } - subCodeLength += berTag.decode(is); + vByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 3)) { respondingPresentationSelector = new RespondingPresentationSelector(); - subCodeLength += respondingPresentationSelector.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += respondingPresentationSelector.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } - subCodeLength += berTag.decode(is); + vByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 5)) { presentationContextDefinitionResultList = new PresentationContextDefinitionResultList(); - subCodeLength += presentationContextDefinitionResultList.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += presentationContextDefinitionResultList.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } - subCodeLength += berTag.decode(is); + vByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 8)) { presentationRequirements = new PresentationRequirements(); - subCodeLength += presentationRequirements.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += presentationRequirements.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } - subCodeLength += berTag.decode(is); + vByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 9)) { userSessionRequirements = new UserSessionRequirements(); - subCodeLength += userSessionRequirements.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += userSessionRequirements.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } - subCodeLength += berTag.decode(is); + vByteCount += berTag.decode(is); } userData = new UserData(); - int choiceDecodeLength = userData.decode(is, berTag); - subCodeLength += choiceDecodeLength; - if (subCodeLength == totalLength) { - return codeLength; + numDecodedBytes = userData.decode(is, berTag); + if (numDecodedBytes != 0) { + vByteCount += numDecodedBytes; + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; + } + vByteCount += berTag.decode(is); + } else { + userData = null; } + if (lengthVal < 0) { + if (!berTag.equals(0, 0, 0)) { + throw new IOException("Decoded sequence has wrong end of contents octets"); + } + vByteCount += BerLength.readEocByte(is); + return tlByteCount + vByteCount; + } + throw new IOException( "Unexpected end of sequence, length tag: " - + totalLength - + ", actual sequence length: " - + subCodeLength); + + lengthVal + + ", bytes decoded: " + + vByteCount); } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -379,6 +394,7 @@ public class CPAPPDU implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/CPType.java b/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/CPType.java index 98362ba..984e170 100644 --- a/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/CPType.java +++ b/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/CPType.java @@ -1,10 +1,10 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.josistack.internal.presentation.asn1; -import com.beanit.jasn1.ber.BerLength; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerType; +import com.beanit.asn1bean.ber.BerLength; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerType; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -14,10 +14,9 @@ public class CPType implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 17); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private ModeSelector modeSelector = null; private NormalModeParameters normalModeParameters = null; - public CPType() {} public CPType(byte[] code) { @@ -40,6 +39,7 @@ public class CPType implements BerType, Serializable { this.normalModeParameters = normalModeParameters; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -47,9 +47,7 @@ public class CPType implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -78,43 +76,47 @@ public class CPType implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); + tlByteCount += length.decode(is); + int lengthVal = length.val; - int totalLength = length.val; - while (subCodeLength < totalLength) { - subCodeLength += berTag.decode(is); + while (vByteCount < lengthVal || lengthVal < 0) { + vByteCount += berTag.decode(is); if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) { modeSelector = new ModeSelector(); - subCodeLength += modeSelector.decode(is, false); + vByteCount += modeSelector.decode(is, false); } else if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 2)) { normalModeParameters = new NormalModeParameters(); - subCodeLength += normalModeParameters.decode(is, false); + vByteCount += normalModeParameters.decode(is, false); + } else if (lengthVal < 0 && berTag.equals(0, 0, 0)) { + vByteCount += BerLength.readEocByte(is); + return tlByteCount + vByteCount; + } else { + throw new IOException("Tag does not match any set component: " + berTag); } } - if (subCodeLength != totalLength) { + if (vByteCount != lengthVal) { throw new IOException( "Length of set does not match length tag, length tag: " - + totalLength + + lengthVal + ", actual set length: " - + subCodeLength); + + vByteCount); } - codeLength += subCodeLength; - - return codeLength; + return tlByteCount + vByteCount; } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -123,6 +125,7 @@ public class CPType implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); @@ -163,7 +166,7 @@ public class CPType implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private ProtocolVersion protocolVersion = null; private CallingPresentationSelector callingPresentationSelector = null; private CalledPresentationSelector calledPresentationSelector = null; @@ -246,6 +249,7 @@ public class CPType implements BerType, Serializable { this.userData = userData; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -253,9 +257,7 @@ public class CPType implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -325,103 +327,116 @@ public class CPType implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; + int numDecodedBytes; BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); - - int totalLength = length.val; - codeLength += totalLength; - - if (totalLength == 0) { - return codeLength; + tlByteCount += length.decode(is); + int lengthVal = length.val; + if (lengthVal == 0) { + return tlByteCount; } - subCodeLength += berTag.decode(is); + vByteCount += berTag.decode(is); + if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) { protocolVersion = new ProtocolVersion(); - subCodeLength += protocolVersion.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += protocolVersion.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } - subCodeLength += berTag.decode(is); + vByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) { callingPresentationSelector = new CallingPresentationSelector(); - subCodeLength += callingPresentationSelector.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += callingPresentationSelector.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } - subCodeLength += berTag.decode(is); + vByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 2)) { calledPresentationSelector = new CalledPresentationSelector(); - subCodeLength += calledPresentationSelector.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += calledPresentationSelector.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } - subCodeLength += berTag.decode(is); + vByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 4)) { presentationContextDefinitionList = new PresentationContextDefinitionList(); - subCodeLength += presentationContextDefinitionList.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += presentationContextDefinitionList.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } - subCodeLength += berTag.decode(is); + vByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 6)) { defaultContextName = new DefaultContextName(); - subCodeLength += defaultContextName.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += defaultContextName.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } - subCodeLength += berTag.decode(is); + vByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 8)) { presentationRequirements = new PresentationRequirements(); - subCodeLength += presentationRequirements.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += presentationRequirements.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } - subCodeLength += berTag.decode(is); + vByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 9)) { userSessionRequirements = new UserSessionRequirements(); - subCodeLength += userSessionRequirements.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += userSessionRequirements.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } - subCodeLength += berTag.decode(is); + vByteCount += berTag.decode(is); } userData = new UserData(); - int choiceDecodeLength = userData.decode(is, berTag); - subCodeLength += choiceDecodeLength; - if (subCodeLength == totalLength) { - return codeLength; + numDecodedBytes = userData.decode(is, berTag); + if (numDecodedBytes != 0) { + vByteCount += numDecodedBytes; + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; + } + vByteCount += berTag.decode(is); + } else { + userData = null; } + if (lengthVal < 0) { + if (!berTag.equals(0, 0, 0)) { + throw new IOException("Decoded sequence has wrong end of contents octets"); + } + vByteCount += BerLength.readEocByte(is); + return tlByteCount + vByteCount; + } + throw new IOException( "Unexpected end of sequence, length tag: " - + totalLength - + ", actual sequence length: " - + subCodeLength); + + lengthVal + + ", bytes decoded: " + + vByteCount); } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -430,6 +445,7 @@ public class CPType implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/CalledPresentationSelector.java b/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/CalledPresentationSelector.java index efe2f0d..c83facc 100644 --- a/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/CalledPresentationSelector.java +++ b/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/CalledPresentationSelector.java @@ -1,4 +1,4 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.josistack.internal.presentation.asn1; public class CalledPresentationSelector extends PresentationSelector { diff --git a/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/CallingPresentationSelector.java b/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/CallingPresentationSelector.java index 7f5e969..ff1e2f8 100644 --- a/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/CallingPresentationSelector.java +++ b/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/CallingPresentationSelector.java @@ -1,4 +1,4 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.josistack.internal.presentation.asn1; public class CallingPresentationSelector extends PresentationSelector { diff --git a/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/ContextList.java b/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/ContextList.java index db2534e..5ba6eb5 100644 --- a/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/ContextList.java +++ b/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/ContextList.java @@ -1,10 +1,10 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.josistack.internal.presentation.asn1; -import com.beanit.jasn1.ber.BerLength; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerType; +import com.beanit.asn1bean.ber.BerLength; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerType; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -17,9 +17,8 @@ public class ContextList implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private List seqOf = null; - public ContextList() { seqOf = new ArrayList(); } @@ -35,6 +34,7 @@ public class ContextList implements BerType, Serializable { return seqOf; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -42,9 +42,7 @@ public class ContextList implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -65,36 +63,46 @@ public class ContextList implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; + BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); - int totalLength = length.val; + tlByteCount += length.decode(is); + int lengthVal = length.val; + + while (vByteCount < lengthVal || lengthVal < 0) { + vByteCount += berTag.decode(is); - while (subCodeLength < totalLength) { + if (lengthVal < 0 && berTag.equals(0, 0, 0)) { + vByteCount += BerLength.readEocByte(is); + break; + } + + if (!berTag.equals(SEQUENCE.tag)) { + throw new IOException("Tag does not match mandatory sequence of/set of component."); + } SEQUENCE element = new SEQUENCE(); - subCodeLength += element.decode(is, true); + vByteCount += element.decode(is, false); seqOf.add(element); } - if (subCodeLength != totalLength) { + if (lengthVal >= 0 && vByteCount != lengthVal) { throw new IOException( "Decoded SequenceOf or SetOf has wrong length. Expected " - + totalLength + + lengthVal + " but has " - + subCodeLength); + + vByteCount); } - codeLength += subCodeLength; - - return codeLength; + return tlByteCount + vByteCount; } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -103,6 +111,7 @@ public class ContextList implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); @@ -142,11 +151,10 @@ public class ContextList implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private PresentationContextIdentifier presentationContextIdentifier = null; private AbstractSyntaxName abstractSyntaxName = null; private TransferSyntaxNameList transferSyntaxNameList = null; - public SEQUENCE() {} public SEQUENCE(byte[] code) { @@ -178,6 +186,7 @@ public class ContextList implements BerType, Serializable { this.transferSyntaxNameList = transferSyntaxNameList; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -185,9 +194,7 @@ public class ContextList implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -210,54 +217,65 @@ public class ContextList implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); - - int totalLength = length.val; - codeLength += totalLength; + tlByteCount += length.decode(is); + int lengthVal = length.val; + vByteCount += berTag.decode(is); - subCodeLength += berTag.decode(is); if (berTag.equals(PresentationContextIdentifier.tag)) { presentationContextIdentifier = new PresentationContextIdentifier(); - subCodeLength += presentationContextIdentifier.decode(is, false); - subCodeLength += berTag.decode(is); + vByteCount += presentationContextIdentifier.decode(is, false); + vByteCount += berTag.decode(is); } else { - throw new IOException("Tag does not match the mandatory sequence element tag."); + throw new IOException("Tag does not match mandatory sequence component."); } if (berTag.equals(AbstractSyntaxName.tag)) { abstractSyntaxName = new AbstractSyntaxName(); - subCodeLength += abstractSyntaxName.decode(is, false); - subCodeLength += berTag.decode(is); + vByteCount += abstractSyntaxName.decode(is, false); + vByteCount += berTag.decode(is); } else { - throw new IOException("Tag does not match the mandatory sequence element tag."); + throw new IOException("Tag does not match mandatory sequence component."); } if (berTag.equals(TransferSyntaxNameList.tag)) { transferSyntaxNameList = new TransferSyntaxNameList(); - subCodeLength += transferSyntaxNameList.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += transferSyntaxNameList.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } + vByteCount += berTag.decode(is); + } else { + throw new IOException("Tag does not match mandatory sequence component."); + } + + if (lengthVal < 0) { + if (!berTag.equals(0, 0, 0)) { + throw new IOException("Decoded sequence has wrong end of contents octets"); + } + vByteCount += BerLength.readEocByte(is); + return tlByteCount + vByteCount; } + throw new IOException( "Unexpected end of sequence, length tag: " - + totalLength - + ", actual sequence length: " - + subCodeLength); + + lengthVal + + ", bytes decoded: " + + vByteCount); } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -266,6 +284,7 @@ public class ContextList implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); @@ -317,7 +336,7 @@ public class ContextList implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private List seqOf = null; public TransferSyntaxNameList() { @@ -335,6 +354,7 @@ public class ContextList implements BerType, Serializable { return seqOf; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -342,9 +362,7 @@ public class ContextList implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -365,36 +383,46 @@ public class ContextList implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; + BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); - int totalLength = length.val; + tlByteCount += length.decode(is); + int lengthVal = length.val; - while (subCodeLength < totalLength) { + while (vByteCount < lengthVal || lengthVal < 0) { + vByteCount += berTag.decode(is); + + if (lengthVal < 0 && berTag.equals(0, 0, 0)) { + vByteCount += BerLength.readEocByte(is); + break; + } + + if (!berTag.equals(TransferSyntaxName.tag)) { + throw new IOException("Tag does not match mandatory sequence of/set of component."); + } TransferSyntaxName element = new TransferSyntaxName(); - subCodeLength += element.decode(is, true); + vByteCount += element.decode(is, false); seqOf.add(element); } - if (subCodeLength != totalLength) { + if (lengthVal >= 0 && vByteCount != lengthVal) { throw new IOException( "Decoded SequenceOf or SetOf has wrong length. Expected " - + totalLength + + lengthVal + " but has " - + subCodeLength); + + vByteCount); } - codeLength += subCodeLength; - - return codeLength; + return tlByteCount + vByteCount; } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -404,6 +432,7 @@ public class ContextList implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/DefaultContextName.java b/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/DefaultContextName.java index 77c1a4d..dbf48c2 100644 --- a/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/DefaultContextName.java +++ b/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/DefaultContextName.java @@ -1,10 +1,10 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.josistack.internal.presentation.asn1; -import com.beanit.jasn1.ber.BerLength; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerType; +import com.beanit.asn1bean.ber.BerLength; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerType; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -14,7 +14,7 @@ public class DefaultContextName implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private AbstractSyntaxName abstractSyntaxName = null; private TransferSyntaxName transferSyntaxName = null; @@ -40,6 +40,7 @@ public class DefaultContextName implements BerType, Serializable { this.transferSyntaxName = transferSyntaxName; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -47,9 +48,7 @@ public class DefaultContextName implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -76,46 +75,54 @@ public class DefaultContextName implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); + tlByteCount += length.decode(is); + int lengthVal = length.val; + vByteCount += berTag.decode(is); - int totalLength = length.val; - codeLength += totalLength; - - subCodeLength += berTag.decode(is); if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) { abstractSyntaxName = new AbstractSyntaxName(); - subCodeLength += abstractSyntaxName.decode(is, false); - subCodeLength += berTag.decode(is); + vByteCount += abstractSyntaxName.decode(is, false); + vByteCount += berTag.decode(is); } else { - throw new IOException("Tag does not match the mandatory sequence element tag."); + throw new IOException("Tag does not match mandatory sequence component."); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) { transferSyntaxName = new TransferSyntaxName(); - subCodeLength += transferSyntaxName.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += transferSyntaxName.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; + } + vByteCount += berTag.decode(is); + } else { + throw new IOException("Tag does not match mandatory sequence component."); + } + + if (lengthVal < 0) { + if (!berTag.equals(0, 0, 0)) { + throw new IOException("Decoded sequence has wrong end of contents octets"); } + vByteCount += BerLength.readEocByte(is); + return tlByteCount + vByteCount; } + throw new IOException( - "Unexpected end of sequence, length tag: " - + totalLength - + ", actual sequence length: " - + subCodeLength); + "Unexpected end of sequence, length tag: " + lengthVal + ", bytes decoded: " + vByteCount); } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -124,6 +131,7 @@ public class DefaultContextName implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/FullyEncodedData.java b/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/FullyEncodedData.java index 4167e2d..0686f69 100644 --- a/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/FullyEncodedData.java +++ b/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/FullyEncodedData.java @@ -1,10 +1,10 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.josistack.internal.presentation.asn1; -import com.beanit.jasn1.ber.BerLength; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerType; +import com.beanit.asn1bean.ber.BerLength; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerType; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -17,7 +17,7 @@ public class FullyEncodedData implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private List seqOf = null; public FullyEncodedData() { @@ -35,6 +35,7 @@ public class FullyEncodedData implements BerType, Serializable { return seqOf; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -42,9 +43,7 @@ public class FullyEncodedData implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -65,36 +64,46 @@ public class FullyEncodedData implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; + BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); - int totalLength = length.val; + tlByteCount += length.decode(is); + int lengthVal = length.val; + + while (vByteCount < lengthVal || lengthVal < 0) { + vByteCount += berTag.decode(is); + + if (lengthVal < 0 && berTag.equals(0, 0, 0)) { + vByteCount += BerLength.readEocByte(is); + break; + } - while (subCodeLength < totalLength) { + if (!berTag.equals(PDVList.tag)) { + throw new IOException("Tag does not match mandatory sequence of/set of component."); + } PDVList element = new PDVList(); - subCodeLength += element.decode(is, true); + vByteCount += element.decode(is, false); seqOf.add(element); } - if (subCodeLength != totalLength) { + if (lengthVal >= 0 && vByteCount != lengthVal) { throw new IOException( "Decoded SequenceOf or SetOf has wrong length. Expected " - + totalLength + + lengthVal + " but has " - + subCodeLength); + + vByteCount); } - codeLength += subCodeLength; - - return codeLength; + return tlByteCount + vByteCount; } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -103,6 +112,7 @@ public class FullyEncodedData implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/ModeSelector.java b/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/ModeSelector.java index daca9d6..1a6f7a9 100644 --- a/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/ModeSelector.java +++ b/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/ModeSelector.java @@ -1,11 +1,11 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.josistack.internal.presentation.asn1; -import com.beanit.jasn1.ber.BerLength; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerInteger; -import com.beanit.jasn1.ber.types.BerType; +import com.beanit.asn1bean.ber.BerLength; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerInteger; +import com.beanit.asn1bean.ber.types.BerType; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -15,7 +15,7 @@ public class ModeSelector implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 17); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private BerInteger modeValue = null; public ModeSelector() {} @@ -32,6 +32,7 @@ public class ModeSelector implements BerType, Serializable { this.modeValue = modeValue; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -39,9 +40,7 @@ public class ModeSelector implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -63,40 +62,44 @@ public class ModeSelector implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); + tlByteCount += length.decode(is); + int lengthVal = length.val; - int totalLength = length.val; - while (subCodeLength < totalLength) { - subCodeLength += berTag.decode(is); + while (vByteCount < lengthVal || lengthVal < 0) { + vByteCount += berTag.decode(is); if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) { modeValue = new BerInteger(); - subCodeLength += modeValue.decode(is, false); + vByteCount += modeValue.decode(is, false); + } else if (lengthVal < 0 && berTag.equals(0, 0, 0)) { + vByteCount += BerLength.readEocByte(is); + return tlByteCount + vByteCount; + } else { + throw new IOException("Tag does not match any set component: " + berTag); } } - if (subCodeLength != totalLength) { + if (vByteCount != lengthVal) { throw new IOException( "Length of set does not match length tag, length tag: " - + totalLength + + lengthVal + ", actual set length: " - + subCodeLength); + + vByteCount); } - codeLength += subCodeLength; - - return codeLength; + return tlByteCount + vByteCount; } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -105,6 +108,7 @@ public class ModeSelector implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/PDVList.java b/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/PDVList.java index 3ec991d..9fc0f19 100644 --- a/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/PDVList.java +++ b/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/PDVList.java @@ -1,13 +1,13 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.josistack.internal.presentation.asn1; -import com.beanit.jasn1.ber.BerLength; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerAny; -import com.beanit.jasn1.ber.types.BerBitString; -import com.beanit.jasn1.ber.types.BerOctetString; -import com.beanit.jasn1.ber.types.BerType; +import com.beanit.asn1bean.ber.BerLength; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerAny; +import com.beanit.asn1bean.ber.types.BerBitString; +import com.beanit.asn1bean.ber.types.BerOctetString; +import com.beanit.asn1bean.ber.types.BerType; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -17,11 +17,10 @@ public class PDVList implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private TransferSyntaxName transferSyntaxName = null; private PresentationContextIdentifier presentationContextIdentifier = null; private PresentationDataValues presentationDataValues = null; - public PDVList() {} public PDVList(byte[] code) { @@ -53,6 +52,7 @@ public class PDVList implements BerType, Serializable { this.presentationDataValues = presentationDataValues; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -60,9 +60,7 @@ public class PDVList implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -87,50 +85,61 @@ public class PDVList implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; + int numDecodedBytes; BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); - - int totalLength = length.val; - codeLength += totalLength; + tlByteCount += length.decode(is); + int lengthVal = length.val; + vByteCount += berTag.decode(is); - subCodeLength += berTag.decode(is); if (berTag.equals(TransferSyntaxName.tag)) { transferSyntaxName = new TransferSyntaxName(); - subCodeLength += transferSyntaxName.decode(is, false); - subCodeLength += berTag.decode(is); + vByteCount += transferSyntaxName.decode(is, false); + vByteCount += berTag.decode(is); } if (berTag.equals(PresentationContextIdentifier.tag)) { presentationContextIdentifier = new PresentationContextIdentifier(); - subCodeLength += presentationContextIdentifier.decode(is, false); - subCodeLength += berTag.decode(is); + vByteCount += presentationContextIdentifier.decode(is, false); + vByteCount += berTag.decode(is); } else { - throw new IOException("Tag does not match the mandatory sequence element tag."); + throw new IOException("Tag does not match mandatory sequence component."); } presentationDataValues = new PresentationDataValues(); - subCodeLength += presentationDataValues.decode(is, berTag); - if (subCodeLength == totalLength) { - return codeLength; + numDecodedBytes = presentationDataValues.decode(is, berTag); + if (numDecodedBytes != 0) { + vByteCount += numDecodedBytes; + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; + } + vByteCount += berTag.decode(is); + } else { + throw new IOException("Tag does not match mandatory sequence component."); } + if (lengthVal < 0) { + if (!berTag.equals(0, 0, 0)) { + throw new IOException("Decoded sequence has wrong end of contents octets"); + } + vByteCount += BerLength.readEocByte(is); + return tlByteCount + vByteCount; + } + throw new IOException( - "Unexpected end of sequence, length tag: " - + totalLength - + ", actual sequence length: " - + subCodeLength); + "Unexpected end of sequence, length tag: " + lengthVal + ", bytes decoded: " + vByteCount); } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -139,6 +148,7 @@ public class PDVList implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); @@ -192,7 +202,7 @@ public class PDVList implements BerType, Serializable { private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private BerAny singleASN1Type = null; private BerOctetString octetAligned = null; private BerBitString arbitrary = null; @@ -227,12 +237,11 @@ public class PDVList implements BerType, Serializable { this.arbitrary = arbitrary; } + @Override public int encode(OutputStream reverseOS) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); return code.length; } @@ -268,40 +277,43 @@ public class PDVList implements BerType, Serializable { throw new IOException("Error encoding CHOICE: No element of CHOICE was selected."); } + @Override public int decode(InputStream is) throws IOException { return decode(is, null); } public int decode(InputStream is, BerTag berTag) throws IOException { - int codeLength = 0; - BerTag passedTag = berTag; + int tlvByteCount = 0; + boolean tagWasPassed = (berTag != null); if (berTag == null) { berTag = new BerTag(); - codeLength += berTag.decode(is); + tlvByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) { - codeLength += BerLength.skip(is); + BerLength explicitTagLength = new BerLength(); + tlvByteCount += explicitTagLength.decode(is); singleASN1Type = new BerAny(); - codeLength += singleASN1Type.decode(is, null); - return codeLength; + tlvByteCount += singleASN1Type.decode(is, null); + tlvByteCount += explicitTagLength.readEocIfIndefinite(is); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) { octetAligned = new BerOctetString(); - codeLength += octetAligned.decode(is, false); - return codeLength; + tlvByteCount += octetAligned.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 2)) { arbitrary = new BerBitString(); - codeLength += arbitrary.decode(is, false); - return codeLength; + tlvByteCount += arbitrary.decode(is, false); + return tlvByteCount; } - if (passedTag != null) { + if (tagWasPassed) { return 0; } @@ -314,6 +326,7 @@ public class PDVList implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/PresentationContextDefinitionList.java b/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/PresentationContextDefinitionList.java index 524f0a9..80775ab 100644 --- a/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/PresentationContextDefinitionList.java +++ b/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/PresentationContextDefinitionList.java @@ -1,4 +1,4 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.josistack.internal.presentation.asn1; public class PresentationContextDefinitionList extends ContextList { diff --git a/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/PresentationContextDefinitionResultList.java b/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/PresentationContextDefinitionResultList.java index 220378f..9a60e94 100644 --- a/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/PresentationContextDefinitionResultList.java +++ b/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/PresentationContextDefinitionResultList.java @@ -1,4 +1,4 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.josistack.internal.presentation.asn1; public class PresentationContextDefinitionResultList extends ResultList { diff --git a/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/PresentationContextIdentifier.java b/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/PresentationContextIdentifier.java index 2ccb204..c5a3248 100644 --- a/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/PresentationContextIdentifier.java +++ b/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/PresentationContextIdentifier.java @@ -1,7 +1,7 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.josistack.internal.presentation.asn1; -import com.beanit.jasn1.ber.types.BerInteger; +import com.beanit.asn1bean.ber.types.BerInteger; import java.math.BigInteger; public class PresentationContextIdentifier extends BerInteger { diff --git a/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/PresentationRequirements.java b/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/PresentationRequirements.java index 9158098..e20bd62 100644 --- a/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/PresentationRequirements.java +++ b/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/PresentationRequirements.java @@ -1,7 +1,7 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.josistack.internal.presentation.asn1; -import com.beanit.jasn1.ber.types.BerBitString; +import com.beanit.asn1bean.ber.types.BerBitString; public class PresentationRequirements extends BerBitString { diff --git a/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/PresentationSelector.java b/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/PresentationSelector.java index 9522776..cd44ff7 100644 --- a/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/PresentationSelector.java +++ b/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/PresentationSelector.java @@ -1,7 +1,7 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.josistack.internal.presentation.asn1; -import com.beanit.jasn1.ber.types.BerOctetString; +import com.beanit.asn1bean.ber.types.BerOctetString; public class PresentationSelector extends BerOctetString { diff --git a/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/ProtocolVersion.java b/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/ProtocolVersion.java index 14723c3..453e6ae 100644 --- a/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/ProtocolVersion.java +++ b/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/ProtocolVersion.java @@ -1,7 +1,7 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.josistack.internal.presentation.asn1; -import com.beanit.jasn1.ber.types.BerBitString; +import com.beanit.asn1bean.ber.types.BerBitString; public class ProtocolVersion extends BerBitString { diff --git a/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/RespondingPresentationSelector.java b/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/RespondingPresentationSelector.java index 1ea4535..55ce6d2 100644 --- a/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/RespondingPresentationSelector.java +++ b/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/RespondingPresentationSelector.java @@ -1,4 +1,4 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.josistack.internal.presentation.asn1; public class RespondingPresentationSelector extends PresentationSelector { diff --git a/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/Result.java b/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/Result.java index 771c5dc..d1e715d 100644 --- a/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/Result.java +++ b/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/Result.java @@ -1,7 +1,7 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.josistack.internal.presentation.asn1; -import com.beanit.jasn1.ber.types.BerInteger; +import com.beanit.asn1bean.ber.types.BerInteger; import java.math.BigInteger; public class Result extends BerInteger { diff --git a/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/ResultList.java b/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/ResultList.java index d4ccbe1..9815745 100644 --- a/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/ResultList.java +++ b/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/ResultList.java @@ -1,11 +1,11 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.josistack.internal.presentation.asn1; -import com.beanit.jasn1.ber.BerLength; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerInteger; -import com.beanit.jasn1.ber.types.BerType; +import com.beanit.asn1bean.ber.BerLength; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerInteger; +import com.beanit.asn1bean.ber.types.BerType; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -18,9 +18,8 @@ public class ResultList implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private List seqOf = null; - public ResultList() { seqOf = new ArrayList(); } @@ -36,6 +35,7 @@ public class ResultList implements BerType, Serializable { return seqOf; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -43,9 +43,7 @@ public class ResultList implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -66,36 +64,46 @@ public class ResultList implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; + BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); - int totalLength = length.val; + tlByteCount += length.decode(is); + int lengthVal = length.val; + + while (vByteCount < lengthVal || lengthVal < 0) { + vByteCount += berTag.decode(is); - while (subCodeLength < totalLength) { + if (lengthVal < 0 && berTag.equals(0, 0, 0)) { + vByteCount += BerLength.readEocByte(is); + break; + } + + if (!berTag.equals(SEQUENCE.tag)) { + throw new IOException("Tag does not match mandatory sequence of/set of component."); + } SEQUENCE element = new SEQUENCE(); - subCodeLength += element.decode(is, true); + vByteCount += element.decode(is, false); seqOf.add(element); } - if (subCodeLength != totalLength) { + if (lengthVal >= 0 && vByteCount != lengthVal) { throw new IOException( "Decoded SequenceOf or SetOf has wrong length. Expected " - + totalLength + + lengthVal + " but has " - + subCodeLength); + + vByteCount); } - codeLength += subCodeLength; - - return codeLength; + return tlByteCount + vByteCount; } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -104,6 +112,7 @@ public class ResultList implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); @@ -143,7 +152,7 @@ public class ResultList implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private Result result = null; private TransferSyntaxName transferSyntaxName = null; private BerInteger providerReason = null; @@ -178,6 +187,7 @@ public class ResultList implements BerType, Serializable { this.providerReason = providerReason; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -185,9 +195,7 @@ public class ResultList implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -223,58 +231,67 @@ public class ResultList implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); - - int totalLength = length.val; - codeLength += totalLength; + tlByteCount += length.decode(is); + int lengthVal = length.val; + vByteCount += berTag.decode(is); - subCodeLength += berTag.decode(is); if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) { result = new Result(); - subCodeLength += result.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += result.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } - subCodeLength += berTag.decode(is); + vByteCount += berTag.decode(is); } else { - throw new IOException("Tag does not match the mandatory sequence element tag."); + throw new IOException("Tag does not match mandatory sequence component."); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) { transferSyntaxName = new TransferSyntaxName(); - subCodeLength += transferSyntaxName.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += transferSyntaxName.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } - subCodeLength += berTag.decode(is); + vByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 2)) { providerReason = new BerInteger(); - subCodeLength += providerReason.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += providerReason.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } + vByteCount += berTag.decode(is); } + + if (lengthVal < 0) { + if (!berTag.equals(0, 0, 0)) { + throw new IOException("Decoded sequence has wrong end of contents octets"); + } + vByteCount += BerLength.readEocByte(is); + return tlByteCount + vByteCount; + } + throw new IOException( "Unexpected end of sequence, length tag: " - + totalLength - + ", actual sequence length: " - + subCodeLength); + + lengthVal + + ", bytes decoded: " + + vByteCount); } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -283,6 +300,7 @@ public class ResultList implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/SimplyEncodedData.java b/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/SimplyEncodedData.java index f4d686b..dce5eb0 100644 --- a/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/SimplyEncodedData.java +++ b/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/SimplyEncodedData.java @@ -1,7 +1,7 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.josistack.internal.presentation.asn1; -import com.beanit.jasn1.ber.types.BerOctetString; +import com.beanit.asn1bean.ber.types.BerOctetString; public class SimplyEncodedData extends BerOctetString { diff --git a/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/TransferSyntaxName.java b/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/TransferSyntaxName.java index fc6656d..97d727f 100644 --- a/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/TransferSyntaxName.java +++ b/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/TransferSyntaxName.java @@ -1,7 +1,7 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.josistack.internal.presentation.asn1; -import com.beanit.jasn1.ber.types.BerObjectIdentifier; +import com.beanit.asn1bean.ber.types.BerObjectIdentifier; public class TransferSyntaxName extends BerObjectIdentifier { diff --git a/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/UserData.java b/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/UserData.java index b300af9..c93f44a 100644 --- a/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/UserData.java +++ b/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/UserData.java @@ -1,9 +1,9 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.josistack.internal.presentation.asn1; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerType; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerType; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -13,7 +13,7 @@ public class UserData implements BerType, Serializable { private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private SimplyEncodedData simplyEncodedData = null; private FullyEncodedData fullyEncodedData = null; @@ -39,12 +39,11 @@ public class UserData implements BerType, Serializable { this.fullyEncodedData = fullyEncodedData; } + @Override public int encode(OutputStream reverseOS) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); return code.length; } @@ -68,33 +67,34 @@ public class UserData implements BerType, Serializable { throw new IOException("Error encoding CHOICE: No element of CHOICE was selected."); } + @Override public int decode(InputStream is) throws IOException { return decode(is, null); } public int decode(InputStream is, BerTag berTag) throws IOException { - int codeLength = 0; - BerTag passedTag = berTag; + int tlvByteCount = 0; + boolean tagWasPassed = (berTag != null); if (berTag == null) { berTag = new BerTag(); - codeLength += berTag.decode(is); + tlvByteCount += berTag.decode(is); } if (berTag.equals(BerTag.APPLICATION_CLASS, BerTag.PRIMITIVE, 0)) { simplyEncodedData = new SimplyEncodedData(); - codeLength += simplyEncodedData.decode(is, false); - return codeLength; + tlvByteCount += simplyEncodedData.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.APPLICATION_CLASS, BerTag.CONSTRUCTED, 1)) { fullyEncodedData = new FullyEncodedData(); - codeLength += fullyEncodedData.decode(is, false); - return codeLength; + tlvByteCount += fullyEncodedData.decode(is, false); + return tlvByteCount; } - if (passedTag != null) { + if (tagWasPassed) { return 0; } @@ -107,6 +107,7 @@ public class UserData implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/UserSessionRequirements.java b/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/UserSessionRequirements.java index 0068aae..a39f8b9 100644 --- a/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/UserSessionRequirements.java +++ b/src/main/java-gen/com/beanit/josistack/internal/presentation/asn1/UserSessionRequirements.java @@ -1,7 +1,7 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.josistack.internal.presentation.asn1; -import com.beanit.jasn1.ber.types.BerBitString; +import com.beanit.asn1bean.ber.types.BerBitString; public class UserSessionRequirements extends BerBitString { diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/AccessResult.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/AccessResult.java index f299b44..99fdf51 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/AccessResult.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/AccessResult.java @@ -1,9 +1,9 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerType; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerType; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -13,7 +13,7 @@ public class AccessResult implements BerType, Serializable { private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private DataAccessError failure = null; private Data success = null; @@ -39,12 +39,11 @@ public class AccessResult implements BerType, Serializable { this.success = success; } + @Override public int encode(OutputStream reverseOS) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); return code.length; } @@ -65,35 +64,38 @@ public class AccessResult implements BerType, Serializable { throw new IOException("Error encoding CHOICE: No element of CHOICE was selected."); } + @Override public int decode(InputStream is) throws IOException { return decode(is, null); } public int decode(InputStream is, BerTag berTag) throws IOException { - int codeLength = 0; - BerTag passedTag = berTag; + int tlvByteCount = 0; + boolean tagWasPassed = (berTag != null); if (berTag == null) { berTag = new BerTag(); - codeLength += berTag.decode(is); + tlvByteCount += berTag.decode(is); } + int numDecodedBytes; + if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) { failure = new DataAccessError(); - codeLength += failure.decode(is, false); - return codeLength; + tlvByteCount += failure.decode(is, false); + return tlvByteCount; } success = new Data(); - int choiceDecodeLength = success.decode(is, berTag); - if (choiceDecodeLength != 0) { - return codeLength + choiceDecodeLength; + numDecodedBytes = success.decode(is, berTag); + if (numDecodedBytes != 0) { + return tlvByteCount + numDecodedBytes; } else { success = null; } - if (passedTag != null) { + if (tagWasPassed) { return 0; } @@ -106,6 +108,7 @@ public class AccessResult implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/AlternateAccess.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/AlternateAccess.java index 0127765..78a8170 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/AlternateAccess.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/AlternateAccess.java @@ -1,10 +1,10 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; -import com.beanit.jasn1.ber.BerLength; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerType; +import com.beanit.asn1bean.ber.BerLength; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerType; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -17,9 +17,8 @@ public class AlternateAccess implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private List seqOf = null; - public AlternateAccess() { seqOf = new ArrayList(); } @@ -35,6 +34,7 @@ public class AlternateAccess implements BerType, Serializable { return seqOf; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -42,9 +42,7 @@ public class AlternateAccess implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -65,36 +63,48 @@ public class AlternateAccess implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; + int numDecodedBytes; + BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); - int totalLength = length.val; + tlByteCount += length.decode(is); + int lengthVal = length.val; + + while (vByteCount < lengthVal || lengthVal < 0) { + vByteCount += berTag.decode(is); + + if (lengthVal < 0 && berTag.equals(0, 0, 0)) { + vByteCount += BerLength.readEocByte(is); + break; + } - while (subCodeLength < totalLength) { CHOICE element = new CHOICE(); - subCodeLength += element.decode(is, null); + numDecodedBytes = element.decode(is, berTag); + if (numDecodedBytes == 0) { + throw new IOException("Tag did not match"); + } + vByteCount += numDecodedBytes; seqOf.add(element); } - if (subCodeLength != totalLength) { + if (lengthVal >= 0 && vByteCount != lengthVal) { throw new IOException( "Decoded SequenceOf or SetOf has wrong length. Expected " - + totalLength + + lengthVal + " but has " - + subCodeLength); + + vByteCount); } - codeLength += subCodeLength; - - return codeLength; + return tlByteCount + vByteCount; } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -103,6 +113,7 @@ public class AlternateAccess implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); @@ -142,7 +153,7 @@ public class AlternateAccess implements BerType, Serializable { private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private AlternateAccessSelection unnamed = null; public CHOICE() {} @@ -159,12 +170,11 @@ public class AlternateAccess implements BerType, Serializable { this.unnamed = unnamed; } + @Override public int encode(OutputStream reverseOS) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); return code.length; } @@ -177,29 +187,32 @@ public class AlternateAccess implements BerType, Serializable { throw new IOException("Error encoding CHOICE: No element of CHOICE was selected."); } + @Override public int decode(InputStream is) throws IOException { return decode(is, null); } public int decode(InputStream is, BerTag berTag) throws IOException { - int codeLength = 0; - BerTag passedTag = berTag; + int tlvByteCount = 0; + boolean tagWasPassed = (berTag != null); if (berTag == null) { berTag = new BerTag(); - codeLength += berTag.decode(is); + tlvByteCount += berTag.decode(is); } + int numDecodedBytes; + unnamed = new AlternateAccessSelection(); - int choiceDecodeLength = unnamed.decode(is, berTag); - if (choiceDecodeLength != 0) { - return codeLength + choiceDecodeLength; + numDecodedBytes = unnamed.decode(is, berTag); + if (numDecodedBytes != 0) { + return tlvByteCount + numDecodedBytes; } else { unnamed = null; } - if (passedTag != null) { + if (tagWasPassed) { return 0; } @@ -212,6 +225,7 @@ public class AlternateAccess implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/AlternateAccessSelection.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/AlternateAccessSelection.java index b03dd15..f360e39 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/AlternateAccessSelection.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/AlternateAccessSelection.java @@ -1,11 +1,11 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; -import com.beanit.jasn1.ber.BerLength; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerNull; -import com.beanit.jasn1.ber.types.BerType; +import com.beanit.asn1bean.ber.BerLength; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerNull; +import com.beanit.asn1bean.ber.types.BerType; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -15,12 +15,11 @@ public class AlternateAccessSelection implements BerType, Serializable { private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private SelectAlternateAccess selectAlternateAccess = null; private SelectAccess selectAccess = null; public AlternateAccessSelection() {} - public AlternateAccessSelection(byte[] code) { this.code = code; } @@ -41,12 +40,11 @@ public class AlternateAccessSelection implements BerType, Serializable { this.selectAccess = selectAccess; } + @Override public int encode(OutputStream reverseOS) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); return code.length; } @@ -67,35 +65,38 @@ public class AlternateAccessSelection implements BerType, Serializable { throw new IOException("Error encoding CHOICE: No element of CHOICE was selected."); } + @Override public int decode(InputStream is) throws IOException { return decode(is, null); } public int decode(InputStream is, BerTag berTag) throws IOException { - int codeLength = 0; - BerTag passedTag = berTag; + int tlvByteCount = 0; + boolean tagWasPassed = (berTag != null); if (berTag == null) { berTag = new BerTag(); - codeLength += berTag.decode(is); + tlvByteCount += berTag.decode(is); } + int numDecodedBytes; + if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) { selectAlternateAccess = new SelectAlternateAccess(); - codeLength += selectAlternateAccess.decode(is, false); - return codeLength; + tlvByteCount += selectAlternateAccess.decode(is, false); + return tlvByteCount; } selectAccess = new SelectAccess(); - int choiceDecodeLength = selectAccess.decode(is, berTag); - if (choiceDecodeLength != 0) { - return codeLength + choiceDecodeLength; + numDecodedBytes = selectAccess.decode(is, berTag); + if (numDecodedBytes != 0) { + return tlvByteCount + numDecodedBytes; } else { selectAccess = null; } - if (passedTag != null) { + if (tagWasPassed) { return 0; } @@ -108,6 +109,7 @@ public class AlternateAccessSelection implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); @@ -135,10 +137,9 @@ public class AlternateAccessSelection implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private AccessSelection accessSelection = null; private AlternateAccess alternateAccess = null; - public SelectAlternateAccess() {} public SelectAlternateAccess(byte[] code) { @@ -161,6 +162,7 @@ public class AlternateAccessSelection implements BerType, Serializable { this.alternateAccess = alternateAccess; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -168,9 +170,7 @@ public class AlternateAccessSelection implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -191,42 +191,58 @@ public class AlternateAccessSelection implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; + int numDecodedBytes; BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); + tlByteCount += length.decode(is); + int lengthVal = length.val; + vByteCount += berTag.decode(is); - int totalLength = length.val; - codeLength += totalLength; - - subCodeLength += berTag.decode(is); accessSelection = new AccessSelection(); - subCodeLength += accessSelection.decode(is, berTag); - subCodeLength += berTag.decode(is); - + numDecodedBytes = accessSelection.decode(is, berTag); + if (numDecodedBytes != 0) { + vByteCount += numDecodedBytes; + vByteCount += berTag.decode(is); + } else { + throw new IOException("Tag does not match mandatory sequence component."); + } if (berTag.equals(AlternateAccess.tag)) { alternateAccess = new AlternateAccess(); - subCodeLength += alternateAccess.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += alternateAccess.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } + vByteCount += berTag.decode(is); + } else { + throw new IOException("Tag does not match mandatory sequence component."); } + + if (lengthVal < 0) { + if (!berTag.equals(0, 0, 0)) { + throw new IOException("Decoded sequence has wrong end of contents octets"); + } + vByteCount += BerLength.readEocByte(is); + return tlByteCount + vByteCount; + } + throw new IOException( "Unexpected end of sequence, length tag: " - + totalLength - + ", actual sequence length: " - + subCodeLength); + + lengthVal + + ", bytes decoded: " + + vByteCount); } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -235,6 +251,7 @@ public class AlternateAccessSelection implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); @@ -277,14 +294,12 @@ public class AlternateAccessSelection implements BerType, Serializable { private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private Component component = null; private Unsigned32 index = null; private IndexRange indexRange = null; private BerNull allElements = null; - public AccessSelection() {} - public AccessSelection(byte[] code) { this.code = code; } @@ -321,12 +336,11 @@ public class AlternateAccessSelection implements BerType, Serializable { this.allElements = allElements; } + @Override public int encode(OutputStream reverseOS) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); return code.length; } @@ -370,46 +384,49 @@ public class AlternateAccessSelection implements BerType, Serializable { throw new IOException("Error encoding CHOICE: No element of CHOICE was selected."); } + @Override public int decode(InputStream is) throws IOException { return decode(is, null); } public int decode(InputStream is, BerTag berTag) throws IOException { - int codeLength = 0; - BerTag passedTag = berTag; + int tlvByteCount = 0; + boolean tagWasPassed = (berTag != null); if (berTag == null) { berTag = new BerTag(); - codeLength += berTag.decode(is); + tlvByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) { - codeLength += BerLength.skip(is); + BerLength explicitTagLength = new BerLength(); + tlvByteCount += explicitTagLength.decode(is); component = new Component(); - codeLength += component.decode(is, null); - return codeLength; + tlvByteCount += component.decode(is, null); + tlvByteCount += explicitTagLength.readEocIfIndefinite(is); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) { index = new Unsigned32(); - codeLength += index.decode(is, false); - return codeLength; + tlvByteCount += index.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 2)) { indexRange = new IndexRange(); - codeLength += indexRange.decode(is, false); - return codeLength; + tlvByteCount += indexRange.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 3)) { allElements = new BerNull(); - codeLength += allElements.decode(is, false); - return codeLength; + tlvByteCount += allElements.decode(is, false); + return tlvByteCount; } - if (passedTag != null) { + if (tagWasPassed) { return 0; } @@ -423,6 +440,7 @@ public class AlternateAccessSelection implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); @@ -460,7 +478,7 @@ public class AlternateAccessSelection implements BerType, Serializable { private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private BasicIdentifier basic = null; public Component() {} @@ -477,12 +495,11 @@ public class AlternateAccessSelection implements BerType, Serializable { this.basic = basic; } + @Override public int encode(OutputStream reverseOS) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); return code.length; } @@ -495,27 +512,28 @@ public class AlternateAccessSelection implements BerType, Serializable { throw new IOException("Error encoding CHOICE: No element of CHOICE was selected."); } + @Override public int decode(InputStream is) throws IOException { return decode(is, null); } public int decode(InputStream is, BerTag berTag) throws IOException { - int codeLength = 0; - BerTag passedTag = berTag; + int tlvByteCount = 0; + boolean tagWasPassed = (berTag != null); if (berTag == null) { berTag = new BerTag(); - codeLength += berTag.decode(is); + tlvByteCount += berTag.decode(is); } if (berTag.equals(BasicIdentifier.tag)) { basic = new BasicIdentifier(); - codeLength += basic.decode(is, false); - return codeLength; + tlvByteCount += basic.decode(is, false); + return tlvByteCount; } - if (passedTag != null) { + if (tagWasPassed) { return 0; } @@ -529,6 +547,7 @@ public class AlternateAccessSelection implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); @@ -550,7 +569,7 @@ public class AlternateAccessSelection implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private Unsigned32 lowIndex = null; private Unsigned32 numberOfElements = null; @@ -576,6 +595,7 @@ public class AlternateAccessSelection implements BerType, Serializable { this.numberOfElements = numberOfElements; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -583,9 +603,7 @@ public class AlternateAccessSelection implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -612,46 +630,57 @@ public class AlternateAccessSelection implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); + tlByteCount += length.decode(is); + int lengthVal = length.val; + vByteCount += berTag.decode(is); - int totalLength = length.val; - codeLength += totalLength; - - subCodeLength += berTag.decode(is); if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) { lowIndex = new Unsigned32(); - subCodeLength += lowIndex.decode(is, false); - subCodeLength += berTag.decode(is); + vByteCount += lowIndex.decode(is, false); + vByteCount += berTag.decode(is); } else { - throw new IOException("Tag does not match the mandatory sequence element tag."); + throw new IOException("Tag does not match mandatory sequence component."); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) { numberOfElements = new Unsigned32(); - subCodeLength += numberOfElements.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += numberOfElements.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; + } + vByteCount += berTag.decode(is); + } else { + throw new IOException("Tag does not match mandatory sequence component."); + } + + if (lengthVal < 0) { + if (!berTag.equals(0, 0, 0)) { + throw new IOException("Decoded sequence has wrong end of contents octets"); } + vByteCount += BerLength.readEocByte(is); + return tlByteCount + vByteCount; } + throw new IOException( "Unexpected end of sequence, length tag: " - + totalLength - + ", actual sequence length: " - + subCodeLength); + + lengthVal + + ", bytes decoded: " + + vByteCount); } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -661,6 +690,7 @@ public class AlternateAccessSelection implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); @@ -704,14 +734,12 @@ public class AlternateAccessSelection implements BerType, Serializable { private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private Component component = null; private Unsigned32 index = null; private IndexRange indexRange = null; private BerNull allElements = null; - public SelectAccess() {} - public SelectAccess(byte[] code) { this.code = code; } @@ -748,12 +776,11 @@ public class AlternateAccessSelection implements BerType, Serializable { this.allElements = allElements; } + @Override public int encode(OutputStream reverseOS) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); return code.length; } @@ -797,46 +824,49 @@ public class AlternateAccessSelection implements BerType, Serializable { throw new IOException("Error encoding CHOICE: No element of CHOICE was selected."); } + @Override public int decode(InputStream is) throws IOException { return decode(is, null); } public int decode(InputStream is, BerTag berTag) throws IOException { - int codeLength = 0; - BerTag passedTag = berTag; + int tlvByteCount = 0; + boolean tagWasPassed = (berTag != null); if (berTag == null) { berTag = new BerTag(); - codeLength += berTag.decode(is); + tlvByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) { - codeLength += BerLength.skip(is); + BerLength explicitTagLength = new BerLength(); + tlvByteCount += explicitTagLength.decode(is); component = new Component(); - codeLength += component.decode(is, null); - return codeLength; + tlvByteCount += component.decode(is, null); + tlvByteCount += explicitTagLength.readEocIfIndefinite(is); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 2)) { index = new Unsigned32(); - codeLength += index.decode(is, false); - return codeLength; + tlvByteCount += index.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 3)) { indexRange = new IndexRange(); - codeLength += indexRange.decode(is, false); - return codeLength; + tlvByteCount += indexRange.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 4)) { allElements = new BerNull(); - codeLength += allElements.decode(is, false); - return codeLength; + tlvByteCount += allElements.decode(is, false); + return tlvByteCount; } - if (passedTag != null) { + if (tagWasPassed) { return 0; } @@ -849,6 +879,7 @@ public class AlternateAccessSelection implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); @@ -886,7 +917,7 @@ public class AlternateAccessSelection implements BerType, Serializable { private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private BasicIdentifier basic = null; public Component() {} @@ -903,12 +934,11 @@ public class AlternateAccessSelection implements BerType, Serializable { this.basic = basic; } + @Override public int encode(OutputStream reverseOS) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); return code.length; } @@ -921,27 +951,28 @@ public class AlternateAccessSelection implements BerType, Serializable { throw new IOException("Error encoding CHOICE: No element of CHOICE was selected."); } + @Override public int decode(InputStream is) throws IOException { return decode(is, null); } public int decode(InputStream is, BerTag berTag) throws IOException { - int codeLength = 0; - BerTag passedTag = berTag; + int tlvByteCount = 0; + boolean tagWasPassed = (berTag != null); if (berTag == null) { berTag = new BerTag(); - codeLength += berTag.decode(is); + tlvByteCount += berTag.decode(is); } if (berTag.equals(BasicIdentifier.tag)) { basic = new BasicIdentifier(); - codeLength += basic.decode(is, false); - return codeLength; + tlvByteCount += basic.decode(is, false); + return tlvByteCount; } - if (passedTag != null) { + if (tagWasPassed) { return 0; } @@ -955,6 +986,7 @@ public class AlternateAccessSelection implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); @@ -976,7 +1008,7 @@ public class AlternateAccessSelection implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private Unsigned32 lowIndex = null; private Unsigned32 numberOfElements = null; @@ -1002,6 +1034,7 @@ public class AlternateAccessSelection implements BerType, Serializable { this.numberOfElements = numberOfElements; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -1009,9 +1042,7 @@ public class AlternateAccessSelection implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -1038,46 +1069,57 @@ public class AlternateAccessSelection implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); + tlByteCount += length.decode(is); + int lengthVal = length.val; + vByteCount += berTag.decode(is); - int totalLength = length.val; - codeLength += totalLength; - - subCodeLength += berTag.decode(is); if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) { lowIndex = new Unsigned32(); - subCodeLength += lowIndex.decode(is, false); - subCodeLength += berTag.decode(is); + vByteCount += lowIndex.decode(is, false); + vByteCount += berTag.decode(is); } else { - throw new IOException("Tag does not match the mandatory sequence element tag."); + throw new IOException("Tag does not match mandatory sequence component."); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) { numberOfElements = new Unsigned32(); - subCodeLength += numberOfElements.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += numberOfElements.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } + vByteCount += berTag.decode(is); + } else { + throw new IOException("Tag does not match mandatory sequence component."); } + + if (lengthVal < 0) { + if (!berTag.equals(0, 0, 0)) { + throw new IOException("Decoded sequence has wrong end of contents octets"); + } + vByteCount += BerLength.readEocByte(is); + return tlByteCount + vByteCount; + } + throw new IOException( "Unexpected end of sequence, length tag: " - + totalLength - + ", actual sequence length: " - + subCodeLength); + + lengthVal + + ", bytes decoded: " + + vByteCount); } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -1087,6 +1129,7 @@ public class AlternateAccessSelection implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/BasicIdentifier.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/BasicIdentifier.java index cd450f0..c45f6d8 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/BasicIdentifier.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/BasicIdentifier.java @@ -1,7 +1,7 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; -import com.beanit.jasn1.ber.types.string.BerVisibleString; +import com.beanit.asn1bean.ber.types.string.BerVisibleString; public class BasicIdentifier extends BerVisibleString { diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/ConcludeRequestPDU.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/ConcludeRequestPDU.java index e4fada0..69ea911 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/ConcludeRequestPDU.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/ConcludeRequestPDU.java @@ -1,7 +1,7 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; -import com.beanit.jasn1.ber.types.BerNull; +import com.beanit.asn1bean.ber.types.BerNull; public class ConcludeRequestPDU extends BerNull { diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/ConfirmedErrorPDU.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/ConfirmedErrorPDU.java index 8917cb4..914dae0 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/ConfirmedErrorPDU.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/ConfirmedErrorPDU.java @@ -1,10 +1,10 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; -import com.beanit.jasn1.ber.BerLength; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerType; +import com.beanit.asn1bean.ber.BerLength; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerType; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -14,7 +14,7 @@ public class ConfirmedErrorPDU implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private Unsigned32 invokeID = null; private Unsigned32 modifierPosition = null; private ServiceError serviceError = null; @@ -49,6 +49,7 @@ public class ConfirmedErrorPDU implements BerType, Serializable { this.serviceError = serviceError; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -56,9 +57,7 @@ public class ConfirmedErrorPDU implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -92,52 +91,60 @@ public class ConfirmedErrorPDU implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); + tlByteCount += length.decode(is); + int lengthVal = length.val; + vByteCount += berTag.decode(is); - int totalLength = length.val; - codeLength += totalLength; - - subCodeLength += berTag.decode(is); if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) { invokeID = new Unsigned32(); - subCodeLength += invokeID.decode(is, false); - subCodeLength += berTag.decode(is); + vByteCount += invokeID.decode(is, false); + vByteCount += berTag.decode(is); } else { - throw new IOException("Tag does not match the mandatory sequence element tag."); + throw new IOException("Tag does not match mandatory sequence component."); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) { modifierPosition = new Unsigned32(); - subCodeLength += modifierPosition.decode(is, false); - subCodeLength += berTag.decode(is); + vByteCount += modifierPosition.decode(is, false); + vByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 2)) { serviceError = new ServiceError(); - subCodeLength += serviceError.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += serviceError.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; + } + vByteCount += berTag.decode(is); + } else { + throw new IOException("Tag does not match mandatory sequence component."); + } + + if (lengthVal < 0) { + if (!berTag.equals(0, 0, 0)) { + throw new IOException("Decoded sequence has wrong end of contents octets"); } + vByteCount += BerLength.readEocByte(is); + return tlByteCount + vByteCount; } + throw new IOException( - "Unexpected end of sequence, length tag: " - + totalLength - + ", actual sequence length: " - + subCodeLength); + "Unexpected end of sequence, length tag: " + lengthVal + ", bytes decoded: " + vByteCount); } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -146,6 +153,7 @@ public class ConfirmedErrorPDU implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/ConfirmedRequestPDU.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/ConfirmedRequestPDU.java index 5288186..139d4e7 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/ConfirmedRequestPDU.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/ConfirmedRequestPDU.java @@ -1,10 +1,10 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; -import com.beanit.jasn1.ber.BerLength; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerType; +import com.beanit.asn1bean.ber.BerLength; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerType; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -14,7 +14,7 @@ public class ConfirmedRequestPDU implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private Unsigned32 invokeID = null; private ConfirmedServiceRequest service = null; @@ -40,6 +40,7 @@ public class ConfirmedRequestPDU implements BerType, Serializable { this.service = service; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -47,9 +48,7 @@ public class ConfirmedRequestPDU implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -70,44 +69,55 @@ public class ConfirmedRequestPDU implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; + int numDecodedBytes; BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); + tlByteCount += length.decode(is); + int lengthVal = length.val; + vByteCount += berTag.decode(is); - int totalLength = length.val; - codeLength += totalLength; - - subCodeLength += berTag.decode(is); if (berTag.equals(Unsigned32.tag)) { invokeID = new Unsigned32(); - subCodeLength += invokeID.decode(is, false); - subCodeLength += berTag.decode(is); + vByteCount += invokeID.decode(is, false); + vByteCount += berTag.decode(is); } else { - throw new IOException("Tag does not match the mandatory sequence element tag."); + throw new IOException("Tag does not match mandatory sequence component."); } service = new ConfirmedServiceRequest(); - subCodeLength += service.decode(is, berTag); - if (subCodeLength == totalLength) { - return codeLength; + numDecodedBytes = service.decode(is, berTag); + if (numDecodedBytes != 0) { + vByteCount += numDecodedBytes; + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; + } + vByteCount += berTag.decode(is); + } else { + throw new IOException("Tag does not match mandatory sequence component."); + } + if (lengthVal < 0) { + if (!berTag.equals(0, 0, 0)) { + throw new IOException("Decoded sequence has wrong end of contents octets"); + } + vByteCount += BerLength.readEocByte(is); + return tlByteCount + vByteCount; } + throw new IOException( - "Unexpected end of sequence, length tag: " - + totalLength - + ", actual sequence length: " - + subCodeLength); + "Unexpected end of sequence, length tag: " + lengthVal + ", bytes decoded: " + vByteCount); } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -116,6 +126,7 @@ public class ConfirmedRequestPDU implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/ConfirmedResponsePDU.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/ConfirmedResponsePDU.java index 65925bf..9d968f2 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/ConfirmedResponsePDU.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/ConfirmedResponsePDU.java @@ -1,10 +1,10 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; -import com.beanit.jasn1.ber.BerLength; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerType; +import com.beanit.asn1bean.ber.BerLength; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerType; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -14,7 +14,7 @@ public class ConfirmedResponsePDU implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private Unsigned32 invokeID = null; private ConfirmedServiceResponse service = null; @@ -40,6 +40,7 @@ public class ConfirmedResponsePDU implements BerType, Serializable { this.service = service; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -47,9 +48,7 @@ public class ConfirmedResponsePDU implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -70,44 +69,55 @@ public class ConfirmedResponsePDU implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; + int numDecodedBytes; BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); + tlByteCount += length.decode(is); + int lengthVal = length.val; + vByteCount += berTag.decode(is); - int totalLength = length.val; - codeLength += totalLength; - - subCodeLength += berTag.decode(is); if (berTag.equals(Unsigned32.tag)) { invokeID = new Unsigned32(); - subCodeLength += invokeID.decode(is, false); - subCodeLength += berTag.decode(is); + vByteCount += invokeID.decode(is, false); + vByteCount += berTag.decode(is); } else { - throw new IOException("Tag does not match the mandatory sequence element tag."); + throw new IOException("Tag does not match mandatory sequence component."); } service = new ConfirmedServiceResponse(); - subCodeLength += service.decode(is, berTag); - if (subCodeLength == totalLength) { - return codeLength; + numDecodedBytes = service.decode(is, berTag); + if (numDecodedBytes != 0) { + vByteCount += numDecodedBytes; + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; + } + vByteCount += berTag.decode(is); + } else { + throw new IOException("Tag does not match mandatory sequence component."); + } + if (lengthVal < 0) { + if (!berTag.equals(0, 0, 0)) { + throw new IOException("Decoded sequence has wrong end of contents octets"); + } + vByteCount += BerLength.readEocByte(is); + return tlByteCount + vByteCount; } + throw new IOException( - "Unexpected end of sequence, length tag: " - + totalLength - + ", actual sequence length: " - + subCodeLength); + "Unexpected end of sequence, length tag: " + lengthVal + ", bytes decoded: " + vByteCount); } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -116,6 +126,7 @@ public class ConfirmedResponsePDU implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/ConfirmedServiceRequest.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/ConfirmedServiceRequest.java index 8dcd5d8..f57e2db 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/ConfirmedServiceRequest.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/ConfirmedServiceRequest.java @@ -1,10 +1,10 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; -import com.beanit.jasn1.ber.BerLength; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerType; +import com.beanit.asn1bean.ber.BerLength; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerType; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -14,7 +14,7 @@ public class ConfirmedServiceRequest implements BerType, Serializable { private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private GetNameListRequest getNameList = null; private ReadRequest read = null; private WriteRequest write = null; @@ -132,12 +132,11 @@ public class ConfirmedServiceRequest implements BerType, Serializable { this.fileDirectory = fileDirectory; } + @Override public int encode(OutputStream reverseOS) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); return code.length; } @@ -252,95 +251,100 @@ public class ConfirmedServiceRequest implements BerType, Serializable { throw new IOException("Error encoding CHOICE: No element of CHOICE was selected."); } + @Override public int decode(InputStream is) throws IOException { return decode(is, null); } public int decode(InputStream is, BerTag berTag) throws IOException { - int codeLength = 0; - BerTag passedTag = berTag; + int tlvByteCount = 0; + boolean tagWasPassed = (berTag != null); if (berTag == null) { berTag = new BerTag(); - codeLength += berTag.decode(is); + tlvByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) { getNameList = new GetNameListRequest(); - codeLength += getNameList.decode(is, false); - return codeLength; + tlvByteCount += getNameList.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 4)) { read = new ReadRequest(); - codeLength += read.decode(is, false); - return codeLength; + tlvByteCount += read.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 5)) { write = new WriteRequest(); - codeLength += write.decode(is, false); - return codeLength; + tlvByteCount += write.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 6)) { - codeLength += BerLength.skip(is); + BerLength explicitTagLength = new BerLength(); + tlvByteCount += explicitTagLength.decode(is); getVariableAccessAttributes = new GetVariableAccessAttributesRequest(); - codeLength += getVariableAccessAttributes.decode(is, null); - return codeLength; + tlvByteCount += getVariableAccessAttributes.decode(is, null); + tlvByteCount += explicitTagLength.readEocIfIndefinite(is); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 11)) { defineNamedVariableList = new DefineNamedVariableListRequest(); - codeLength += defineNamedVariableList.decode(is, false); - return codeLength; + tlvByteCount += defineNamedVariableList.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 12)) { - codeLength += BerLength.skip(is); + BerLength explicitTagLength = new BerLength(); + tlvByteCount += explicitTagLength.decode(is); getNamedVariableListAttributes = new GetNamedVariableListAttributesRequest(); - codeLength += getNamedVariableListAttributes.decode(is, null); - return codeLength; + tlvByteCount += getNamedVariableListAttributes.decode(is, null); + tlvByteCount += explicitTagLength.readEocIfIndefinite(is); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 13)) { deleteNamedVariableList = new DeleteNamedVariableListRequest(); - codeLength += deleteNamedVariableList.decode(is, false); - return codeLength; + tlvByteCount += deleteNamedVariableList.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 72)) { fileOpen = new FileOpenRequest(); - codeLength += fileOpen.decode(is, false); - return codeLength; + tlvByteCount += fileOpen.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 73)) { fileRead = new FileReadRequest(); - codeLength += fileRead.decode(is, false); - return codeLength; + tlvByteCount += fileRead.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 74)) { fileClose = new FileCloseRequest(); - codeLength += fileClose.decode(is, false); - return codeLength; + tlvByteCount += fileClose.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 76)) { fileDelete = new FileDeleteRequest(); - codeLength += fileDelete.decode(is, false); - return codeLength; + tlvByteCount += fileDelete.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 77)) { fileDirectory = new FileDirectoryRequest(); - codeLength += fileDirectory.decode(is, false); - return codeLength; + tlvByteCount += fileDirectory.decode(is, false); + return tlvByteCount; } - if (passedTag != null) { + if (tagWasPassed) { return 0; } @@ -353,6 +357,7 @@ public class ConfirmedServiceRequest implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/ConfirmedServiceResponse.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/ConfirmedServiceResponse.java index 086583f..d6937b9 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/ConfirmedServiceResponse.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/ConfirmedServiceResponse.java @@ -1,9 +1,9 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerType; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerType; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -13,7 +13,7 @@ public class ConfirmedServiceResponse implements BerType, Serializable { private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private GetNameListResponse getNameList = null; private ReadResponse read = null; private WriteResponse write = null; @@ -131,12 +131,11 @@ public class ConfirmedServiceResponse implements BerType, Serializable { this.fileDirectory = fileDirectory; } + @Override public int encode(OutputStream reverseOS) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); return code.length; } @@ -245,93 +244,94 @@ public class ConfirmedServiceResponse implements BerType, Serializable { throw new IOException("Error encoding CHOICE: No element of CHOICE was selected."); } + @Override public int decode(InputStream is) throws IOException { return decode(is, null); } public int decode(InputStream is, BerTag berTag) throws IOException { - int codeLength = 0; - BerTag passedTag = berTag; + int tlvByteCount = 0; + boolean tagWasPassed = (berTag != null); if (berTag == null) { berTag = new BerTag(); - codeLength += berTag.decode(is); + tlvByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) { getNameList = new GetNameListResponse(); - codeLength += getNameList.decode(is, false); - return codeLength; + tlvByteCount += getNameList.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 4)) { read = new ReadResponse(); - codeLength += read.decode(is, false); - return codeLength; + tlvByteCount += read.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 5)) { write = new WriteResponse(); - codeLength += write.decode(is, false); - return codeLength; + tlvByteCount += write.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 6)) { getVariableAccessAttributes = new GetVariableAccessAttributesResponse(); - codeLength += getVariableAccessAttributes.decode(is, false); - return codeLength; + tlvByteCount += getVariableAccessAttributes.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 11)) { defineNamedVariableList = new DefineNamedVariableListResponse(); - codeLength += defineNamedVariableList.decode(is, false); - return codeLength; + tlvByteCount += defineNamedVariableList.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 12)) { getNamedVariableListAttributes = new GetNamedVariableListAttributesResponse(); - codeLength += getNamedVariableListAttributes.decode(is, false); - return codeLength; + tlvByteCount += getNamedVariableListAttributes.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 13)) { deleteNamedVariableList = new DeleteNamedVariableListResponse(); - codeLength += deleteNamedVariableList.decode(is, false); - return codeLength; + tlvByteCount += deleteNamedVariableList.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 72)) { fileOpen = new FileOpenResponse(); - codeLength += fileOpen.decode(is, false); - return codeLength; + tlvByteCount += fileOpen.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 73)) { fileRead = new FileReadResponse(); - codeLength += fileRead.decode(is, false); - return codeLength; + tlvByteCount += fileRead.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 74)) { fileClose = new FileCloseResponse(); - codeLength += fileClose.decode(is, false); - return codeLength; + tlvByteCount += fileClose.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 76)) { fileDelete = new FileDeleteResponse(); - codeLength += fileDelete.decode(is, false); - return codeLength; + tlvByteCount += fileDelete.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 77)) { fileDirectory = new FileDirectoryResponse(); - codeLength += fileDirectory.decode(is, false); - return codeLength; + tlvByteCount += fileDirectory.decode(is, false); + return tlvByteCount; } - if (passedTag != null) { + if (tagWasPassed) { return 0; } @@ -344,6 +344,7 @@ public class ConfirmedServiceResponse implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/Data.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/Data.java index 2a734bf..eb007c4 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/Data.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/Data.java @@ -1,14 +1,14 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; -import com.beanit.jasn1.ber.BerLength; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerBitString; -import com.beanit.jasn1.ber.types.BerInteger; -import com.beanit.jasn1.ber.types.BerOctetString; -import com.beanit.jasn1.ber.types.BerType; -import com.beanit.jasn1.ber.types.string.BerVisibleString; +import com.beanit.asn1bean.ber.BerLength; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerBitString; +import com.beanit.asn1bean.ber.types.BerInteger; +import com.beanit.asn1bean.ber.types.BerOctetString; +import com.beanit.asn1bean.ber.types.BerType; +import com.beanit.asn1bean.ber.types.string.BerVisibleString; import com.beanit.openiec61850.internal.BerBoolean; import java.io.IOException; import java.io.InputStream; @@ -22,7 +22,7 @@ public class Data implements BerType, Serializable { private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private Array array = null; private Structure structure = null; private BerBoolean bool = null; @@ -35,9 +35,7 @@ public class Data implements BerType, Serializable { private TimeOfDay binaryTime = null; private MMSString mMSString = null; private UtcTime utcTime = null; - public Data() {} - public Data(byte[] code) { this.code = code; } @@ -138,12 +136,11 @@ public class Data implements BerType, Serializable { this.utcTime = utcTime; } + @Override public int encode(OutputStream reverseOS) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); return code.length; } @@ -247,93 +244,94 @@ public class Data implements BerType, Serializable { throw new IOException("Error encoding CHOICE: No element of CHOICE was selected."); } + @Override public int decode(InputStream is) throws IOException { return decode(is, null); } public int decode(InputStream is, BerTag berTag) throws IOException { - int codeLength = 0; - BerTag passedTag = berTag; + int tlvByteCount = 0; + boolean tagWasPassed = (berTag != null); if (berTag == null) { berTag = new BerTag(); - codeLength += berTag.decode(is); + tlvByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) { array = new Array(); - codeLength += array.decode(is, false); - return codeLength; + tlvByteCount += array.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 2)) { structure = new Structure(); - codeLength += structure.decode(is, false); - return codeLength; + tlvByteCount += structure.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 3)) { bool = new BerBoolean(); - codeLength += bool.decode(is, false); - return codeLength; + tlvByteCount += bool.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 4)) { bitString = new BerBitString(); - codeLength += bitString.decode(is, false); - return codeLength; + tlvByteCount += bitString.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 5)) { integer = new BerInteger(); - codeLength += integer.decode(is, false); - return codeLength; + tlvByteCount += integer.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 6)) { unsigned = new BerInteger(); - codeLength += unsigned.decode(is, false); - return codeLength; + tlvByteCount += unsigned.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 7)) { floatingPoint = new FloatingPoint(); - codeLength += floatingPoint.decode(is, false); - return codeLength; + tlvByteCount += floatingPoint.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 9)) { octetString = new BerOctetString(); - codeLength += octetString.decode(is, false); - return codeLength; + tlvByteCount += octetString.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 10)) { visibleString = new BerVisibleString(); - codeLength += visibleString.decode(is, false); - return codeLength; + tlvByteCount += visibleString.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 12)) { binaryTime = new TimeOfDay(); - codeLength += binaryTime.decode(is, false); - return codeLength; + tlvByteCount += binaryTime.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 16)) { mMSString = new MMSString(); - codeLength += mMSString.decode(is, false); - return codeLength; + tlvByteCount += mMSString.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 17)) { utcTime = new UtcTime(); - codeLength += utcTime.decode(is, false); - return codeLength; + tlvByteCount += utcTime.decode(is, false); + return tlvByteCount; } - if (passedTag != null) { + if (tagWasPassed) { return 0; } @@ -346,6 +344,7 @@ public class Data implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); @@ -423,7 +422,7 @@ public class Data implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private List seqOf = null; public Array() { @@ -441,6 +440,7 @@ public class Data implements BerType, Serializable { return seqOf; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -448,9 +448,7 @@ public class Data implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -471,36 +469,48 @@ public class Data implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; + int numDecodedBytes; + BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); - int totalLength = length.val; + tlByteCount += length.decode(is); + int lengthVal = length.val; + + while (vByteCount < lengthVal || lengthVal < 0) { + vByteCount += berTag.decode(is); + + if (lengthVal < 0 && berTag.equals(0, 0, 0)) { + vByteCount += BerLength.readEocByte(is); + break; + } - while (subCodeLength < totalLength) { Data element = new Data(); - subCodeLength += element.decode(is, null); + numDecodedBytes = element.decode(is, berTag); + if (numDecodedBytes == 0) { + throw new IOException("Tag did not match"); + } + vByteCount += numDecodedBytes; seqOf.add(element); } - if (subCodeLength != totalLength) { + if (lengthVal >= 0 && vByteCount != lengthVal) { throw new IOException( "Decoded SequenceOf or SetOf has wrong length. Expected " - + totalLength + + lengthVal + " but has " - + subCodeLength); + + vByteCount); } - codeLength += subCodeLength; - - return codeLength; + return tlByteCount + vByteCount; } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -509,6 +519,7 @@ public class Data implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); @@ -549,7 +560,7 @@ public class Data implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private List seqOf = null; public Structure() { @@ -567,6 +578,7 @@ public class Data implements BerType, Serializable { return seqOf; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -574,9 +586,7 @@ public class Data implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -597,36 +607,48 @@ public class Data implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; + int numDecodedBytes; + BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); - int totalLength = length.val; + tlByteCount += length.decode(is); + int lengthVal = length.val; + + while (vByteCount < lengthVal || lengthVal < 0) { + vByteCount += berTag.decode(is); + + if (lengthVal < 0 && berTag.equals(0, 0, 0)) { + vByteCount += BerLength.readEocByte(is); + break; + } - while (subCodeLength < totalLength) { Data element = new Data(); - subCodeLength += element.decode(is, null); + numDecodedBytes = element.decode(is, berTag); + if (numDecodedBytes == 0) { + throw new IOException("Tag did not match"); + } + vByteCount += numDecodedBytes; seqOf.add(element); } - if (subCodeLength != totalLength) { + if (lengthVal >= 0 && vByteCount != lengthVal) { throw new IOException( "Decoded SequenceOf or SetOf has wrong length. Expected " - + totalLength + + lengthVal + " but has " - + subCodeLength); + + vByteCount); } - codeLength += subCodeLength; - - return codeLength; + return tlByteCount + vByteCount; } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -635,6 +657,7 @@ public class Data implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/DataAccessError.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/DataAccessError.java index 30a751b..83eab32 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/DataAccessError.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/DataAccessError.java @@ -1,7 +1,7 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; -import com.beanit.jasn1.ber.types.BerInteger; +import com.beanit.asn1bean.ber.types.BerInteger; import java.math.BigInteger; public class DataAccessError extends BerInteger { diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/DefineNamedVariableListRequest.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/DefineNamedVariableListRequest.java index c41610c..d86c759 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/DefineNamedVariableListRequest.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/DefineNamedVariableListRequest.java @@ -1,10 +1,10 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; -import com.beanit.jasn1.ber.BerLength; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerType; +import com.beanit.asn1bean.ber.BerLength; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerType; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -14,7 +14,7 @@ public class DefineNamedVariableListRequest implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private ObjectName variableListName = null; private VariableDefs listOfVariable = null; @@ -40,6 +40,7 @@ public class DefineNamedVariableListRequest implements BerType, Serializable { this.listOfVariable = listOfVariable; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -47,9 +48,7 @@ public class DefineNamedVariableListRequest implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -73,42 +72,55 @@ public class DefineNamedVariableListRequest implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; + int numDecodedBytes; BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); - - int totalLength = length.val; - codeLength += totalLength; + tlByteCount += length.decode(is); + int lengthVal = length.val; + vByteCount += berTag.decode(is); - subCodeLength += berTag.decode(is); variableListName = new ObjectName(); - subCodeLength += variableListName.decode(is, berTag); - subCodeLength += berTag.decode(is); - + numDecodedBytes = variableListName.decode(is, berTag); + if (numDecodedBytes != 0) { + vByteCount += numDecodedBytes; + vByteCount += berTag.decode(is); + } else { + throw new IOException("Tag does not match mandatory sequence component."); + } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) { listOfVariable = new VariableDefs(); - subCodeLength += listOfVariable.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += listOfVariable.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } + vByteCount += berTag.decode(is); + } else { + throw new IOException("Tag does not match mandatory sequence component."); } + + if (lengthVal < 0) { + if (!berTag.equals(0, 0, 0)) { + throw new IOException("Decoded sequence has wrong end of contents octets"); + } + vByteCount += BerLength.readEocByte(is); + return tlByteCount + vByteCount; + } + throw new IOException( - "Unexpected end of sequence, length tag: " - + totalLength - + ", actual sequence length: " - + subCodeLength); + "Unexpected end of sequence, length tag: " + lengthVal + ", bytes decoded: " + vByteCount); } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -117,6 +129,7 @@ public class DefineNamedVariableListRequest implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/DefineNamedVariableListResponse.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/DefineNamedVariableListResponse.java index b93f3cb..2c7bf64 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/DefineNamedVariableListResponse.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/DefineNamedVariableListResponse.java @@ -1,7 +1,7 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; -import com.beanit.jasn1.ber.types.BerNull; +import com.beanit.asn1bean.ber.types.BerNull; public class DefineNamedVariableListResponse extends BerNull { diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/DeleteNamedVariableListRequest.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/DeleteNamedVariableListRequest.java index 96cc695..9d653c6 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/DeleteNamedVariableListRequest.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/DeleteNamedVariableListRequest.java @@ -1,11 +1,11 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; -import com.beanit.jasn1.ber.BerLength; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerInteger; -import com.beanit.jasn1.ber.types.BerType; +import com.beanit.asn1bean.ber.BerLength; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerInteger; +import com.beanit.asn1bean.ber.types.BerType; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -18,13 +18,11 @@ public class DeleteNamedVariableListRequest implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private BerInteger scopeOfDelete = null; private ListOfVariableListName listOfVariableListName = null; private DomainName domainName = null; - public DeleteNamedVariableListRequest() {} - public DeleteNamedVariableListRequest(byte[] code) { this.code = code; } @@ -53,6 +51,7 @@ public class DeleteNamedVariableListRequest implements BerType, Serializable { this.domainName = domainName; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -60,9 +59,7 @@ public class DeleteNamedVariableListRequest implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -104,60 +101,67 @@ public class DeleteNamedVariableListRequest implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); - - int totalLength = length.val; - codeLength += totalLength; - - if (totalLength == 0) { - return codeLength; + tlByteCount += length.decode(is); + int lengthVal = length.val; + if (lengthVal == 0) { + return tlByteCount; } - subCodeLength += berTag.decode(is); + vByteCount += berTag.decode(is); + if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) { scopeOfDelete = new BerInteger(); - subCodeLength += scopeOfDelete.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += scopeOfDelete.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } - subCodeLength += berTag.decode(is); + vByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) { listOfVariableListName = new ListOfVariableListName(); - subCodeLength += listOfVariableListName.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += listOfVariableListName.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } - subCodeLength += berTag.decode(is); + vByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 2)) { - subCodeLength += length.decode(is); + vByteCount += length.decode(is); domainName = new DomainName(); - subCodeLength += domainName.decode(is, null); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += domainName.decode(is, null); + vByteCount += length.readEocIfIndefinite(is); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; + } + vByteCount += berTag.decode(is); + } + + if (lengthVal < 0) { + if (!berTag.equals(0, 0, 0)) { + throw new IOException("Decoded sequence has wrong end of contents octets"); } + vByteCount += BerLength.readEocByte(is); + return tlByteCount + vByteCount; } + throw new IOException( - "Unexpected end of sequence, length tag: " - + totalLength - + ", actual sequence length: " - + subCodeLength); + "Unexpected end of sequence, length tag: " + lengthVal + ", bytes decoded: " + vByteCount); } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -166,6 +170,7 @@ public class DeleteNamedVariableListRequest implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); @@ -220,7 +225,7 @@ public class DeleteNamedVariableListRequest implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private List seqOf = null; public ListOfVariableListName() { @@ -238,6 +243,7 @@ public class DeleteNamedVariableListRequest implements BerType, Serializable { return seqOf; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -245,9 +251,7 @@ public class DeleteNamedVariableListRequest implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -268,36 +272,48 @@ public class DeleteNamedVariableListRequest implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; + int numDecodedBytes; + BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); - int totalLength = length.val; + tlByteCount += length.decode(is); + int lengthVal = length.val; + + while (vByteCount < lengthVal || lengthVal < 0) { + vByteCount += berTag.decode(is); + + if (lengthVal < 0 && berTag.equals(0, 0, 0)) { + vByteCount += BerLength.readEocByte(is); + break; + } - while (subCodeLength < totalLength) { ObjectName element = new ObjectName(); - subCodeLength += element.decode(is, null); + numDecodedBytes = element.decode(is, berTag); + if (numDecodedBytes == 0) { + throw new IOException("Tag did not match"); + } + vByteCount += numDecodedBytes; seqOf.add(element); } - if (subCodeLength != totalLength) { + if (lengthVal >= 0 && vByteCount != lengthVal) { throw new IOException( "Decoded SequenceOf or SetOf has wrong length. Expected " - + totalLength + + lengthVal + " but has " - + subCodeLength); + + vByteCount); } - codeLength += subCodeLength; - - return codeLength; + return tlByteCount + vByteCount; } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -306,6 +322,7 @@ public class DeleteNamedVariableListRequest implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); @@ -346,7 +363,7 @@ public class DeleteNamedVariableListRequest implements BerType, Serializable { private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private BasicIdentifier basic = null; public DomainName() {} @@ -363,12 +380,11 @@ public class DeleteNamedVariableListRequest implements BerType, Serializable { this.basic = basic; } + @Override public int encode(OutputStream reverseOS) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); return code.length; } @@ -381,27 +397,28 @@ public class DeleteNamedVariableListRequest implements BerType, Serializable { throw new IOException("Error encoding CHOICE: No element of CHOICE was selected."); } + @Override public int decode(InputStream is) throws IOException { return decode(is, null); } public int decode(InputStream is, BerTag berTag) throws IOException { - int codeLength = 0; - BerTag passedTag = berTag; + int tlvByteCount = 0; + boolean tagWasPassed = (berTag != null); if (berTag == null) { berTag = new BerTag(); - codeLength += berTag.decode(is); + tlvByteCount += berTag.decode(is); } if (berTag.equals(BasicIdentifier.tag)) { basic = new BasicIdentifier(); - codeLength += basic.decode(is, false); - return codeLength; + tlvByteCount += basic.decode(is, false); + return tlvByteCount; } - if (passedTag != null) { + if (tagWasPassed) { return 0; } @@ -414,6 +431,7 @@ public class DeleteNamedVariableListRequest implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/DeleteNamedVariableListResponse.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/DeleteNamedVariableListResponse.java index 2588038..e8cbb32 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/DeleteNamedVariableListResponse.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/DeleteNamedVariableListResponse.java @@ -1,10 +1,10 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; -import com.beanit.jasn1.ber.BerLength; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerType; +import com.beanit.asn1bean.ber.BerLength; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerType; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -14,7 +14,7 @@ public class DeleteNamedVariableListResponse implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private Unsigned32 numberMatched = null; private Unsigned32 numberDeleted = null; @@ -40,6 +40,7 @@ public class DeleteNamedVariableListResponse implements BerType, Serializable { this.numberDeleted = numberDeleted; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -47,9 +48,7 @@ public class DeleteNamedVariableListResponse implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -76,46 +75,54 @@ public class DeleteNamedVariableListResponse implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); + tlByteCount += length.decode(is); + int lengthVal = length.val; + vByteCount += berTag.decode(is); - int totalLength = length.val; - codeLength += totalLength; - - subCodeLength += berTag.decode(is); if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) { numberMatched = new Unsigned32(); - subCodeLength += numberMatched.decode(is, false); - subCodeLength += berTag.decode(is); + vByteCount += numberMatched.decode(is, false); + vByteCount += berTag.decode(is); } else { - throw new IOException("Tag does not match the mandatory sequence element tag."); + throw new IOException("Tag does not match mandatory sequence component."); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) { numberDeleted = new Unsigned32(); - subCodeLength += numberDeleted.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += numberDeleted.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; + } + vByteCount += berTag.decode(is); + } else { + throw new IOException("Tag does not match mandatory sequence component."); + } + + if (lengthVal < 0) { + if (!berTag.equals(0, 0, 0)) { + throw new IOException("Decoded sequence has wrong end of contents octets"); } + vByteCount += BerLength.readEocByte(is); + return tlByteCount + vByteCount; } + throw new IOException( - "Unexpected end of sequence, length tag: " - + totalLength - + ", actual sequence length: " - + subCodeLength); + "Unexpected end of sequence, length tag: " + lengthVal + ", bytes decoded: " + vByteCount); } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -124,6 +131,7 @@ public class DeleteNamedVariableListResponse implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/DirectoryEntry.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/DirectoryEntry.java index be1d26c..042bb20 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/DirectoryEntry.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/DirectoryEntry.java @@ -1,10 +1,10 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; -import com.beanit.jasn1.ber.BerLength; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerType; +import com.beanit.asn1bean.ber.BerLength; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerType; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -14,7 +14,7 @@ public class DirectoryEntry implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private FileName fileName = null; private FileAttributes fileAttributes = null; @@ -40,6 +40,7 @@ public class DirectoryEntry implements BerType, Serializable { this.fileAttributes = fileAttributes; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -47,9 +48,7 @@ public class DirectoryEntry implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -76,46 +75,54 @@ public class DirectoryEntry implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); + tlByteCount += length.decode(is); + int lengthVal = length.val; + vByteCount += berTag.decode(is); - int totalLength = length.val; - codeLength += totalLength; - - subCodeLength += berTag.decode(is); if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) { fileName = new FileName(); - subCodeLength += fileName.decode(is, false); - subCodeLength += berTag.decode(is); + vByteCount += fileName.decode(is, false); + vByteCount += berTag.decode(is); } else { - throw new IOException("Tag does not match the mandatory sequence element tag."); + throw new IOException("Tag does not match mandatory sequence component."); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) { fileAttributes = new FileAttributes(); - subCodeLength += fileAttributes.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += fileAttributes.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; + } + vByteCount += berTag.decode(is); + } else { + throw new IOException("Tag does not match mandatory sequence component."); + } + + if (lengthVal < 0) { + if (!berTag.equals(0, 0, 0)) { + throw new IOException("Decoded sequence has wrong end of contents octets"); } + vByteCount += BerLength.readEocByte(is); + return tlByteCount + vByteCount; } + throw new IOException( - "Unexpected end of sequence, length tag: " - + totalLength - + ", actual sequence length: " - + subCodeLength); + "Unexpected end of sequence, length tag: " + lengthVal + ", bytes decoded: " + vByteCount); } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -124,6 +131,7 @@ public class DirectoryEntry implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/FileAttributes.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/FileAttributes.java index 705ed96..7798ee4 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/FileAttributes.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/FileAttributes.java @@ -1,11 +1,11 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; -import com.beanit.jasn1.ber.BerLength; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerGeneralizedTime; -import com.beanit.jasn1.ber.types.BerType; +import com.beanit.asn1bean.ber.BerLength; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerGeneralizedTime; +import com.beanit.asn1bean.ber.types.BerType; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -15,7 +15,7 @@ public class FileAttributes implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private Unsigned32 sizeOfFile = null; private BerGeneralizedTime lastModified = null; @@ -41,6 +41,7 @@ public class FileAttributes implements BerType, Serializable { this.lastModified = lastModified; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -48,9 +49,7 @@ public class FileAttributes implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -79,49 +78,55 @@ public class FileAttributes implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); + tlByteCount += length.decode(is); + int lengthVal = length.val; + vByteCount += berTag.decode(is); - int totalLength = length.val; - codeLength += totalLength; - - subCodeLength += berTag.decode(is); if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) { sizeOfFile = new Unsigned32(); - subCodeLength += sizeOfFile.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += sizeOfFile.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } - subCodeLength += berTag.decode(is); + vByteCount += berTag.decode(is); } else { - throw new IOException("Tag does not match the mandatory sequence element tag."); + throw new IOException("Tag does not match mandatory sequence component."); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) { lastModified = new BerGeneralizedTime(); - subCodeLength += lastModified.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += lastModified.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } + vByteCount += berTag.decode(is); } + + if (lengthVal < 0) { + if (!berTag.equals(0, 0, 0)) { + throw new IOException("Decoded sequence has wrong end of contents octets"); + } + vByteCount += BerLength.readEocByte(is); + return tlByteCount + vByteCount; + } + throw new IOException( - "Unexpected end of sequence, length tag: " - + totalLength - + ", actual sequence length: " - + subCodeLength); + "Unexpected end of sequence, length tag: " + lengthVal + ", bytes decoded: " + vByteCount); } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -130,6 +135,7 @@ public class FileAttributes implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/FileCloseRequest.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/FileCloseRequest.java index 25d2635..3e18e7d 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/FileCloseRequest.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/FileCloseRequest.java @@ -1,4 +1,4 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; import java.math.BigInteger; diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/FileCloseResponse.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/FileCloseResponse.java index 84c68b2..46bed99 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/FileCloseResponse.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/FileCloseResponse.java @@ -1,7 +1,7 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; -import com.beanit.jasn1.ber.types.BerNull; +import com.beanit.asn1bean.ber.types.BerNull; public class FileCloseResponse extends BerNull { diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/FileDeleteRequest.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/FileDeleteRequest.java index 8096600..303028f 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/FileDeleteRequest.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/FileDeleteRequest.java @@ -1,4 +1,4 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; public class FileDeleteRequest extends FileName { diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/FileDeleteResponse.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/FileDeleteResponse.java index 76a9792..034c888 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/FileDeleteResponse.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/FileDeleteResponse.java @@ -1,7 +1,7 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; -import com.beanit.jasn1.ber.types.BerNull; +import com.beanit.asn1bean.ber.types.BerNull; public class FileDeleteResponse extends BerNull { diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/FileDirectoryRequest.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/FileDirectoryRequest.java index a77a228..252fd5f 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/FileDirectoryRequest.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/FileDirectoryRequest.java @@ -1,10 +1,10 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; -import com.beanit.jasn1.ber.BerLength; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerType; +import com.beanit.asn1bean.ber.BerLength; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerType; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -14,7 +14,7 @@ public class FileDirectoryRequest implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private FileName fileSpecification = null; private FileName continueAfter = null; @@ -40,6 +40,7 @@ public class FileDirectoryRequest implements BerType, Serializable { this.continueAfter = continueAfter; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -47,9 +48,7 @@ public class FileDirectoryRequest implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -80,50 +79,56 @@ public class FileDirectoryRequest implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); - - int totalLength = length.val; - codeLength += totalLength; - - if (totalLength == 0) { - return codeLength; + tlByteCount += length.decode(is); + int lengthVal = length.val; + if (lengthVal == 0) { + return tlByteCount; } - subCodeLength += berTag.decode(is); + vByteCount += berTag.decode(is); + if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) { fileSpecification = new FileName(); - subCodeLength += fileSpecification.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += fileSpecification.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } - subCodeLength += berTag.decode(is); + vByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) { continueAfter = new FileName(); - subCodeLength += continueAfter.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += continueAfter.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } + vByteCount += berTag.decode(is); } + + if (lengthVal < 0) { + if (!berTag.equals(0, 0, 0)) { + throw new IOException("Decoded sequence has wrong end of contents octets"); + } + vByteCount += BerLength.readEocByte(is); + return tlByteCount + vByteCount; + } + throw new IOException( - "Unexpected end of sequence, length tag: " - + totalLength - + ", actual sequence length: " - + subCodeLength); + "Unexpected end of sequence, length tag: " + lengthVal + ", bytes decoded: " + vByteCount); } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -132,6 +137,7 @@ public class FileDirectoryRequest implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/FileDirectoryResponse.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/FileDirectoryResponse.java index 439fa58..f8d2df0 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/FileDirectoryResponse.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/FileDirectoryResponse.java @@ -1,10 +1,10 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; -import com.beanit.jasn1.ber.BerLength; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerType; +import com.beanit.asn1bean.ber.BerLength; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerType; import com.beanit.openiec61850.internal.BerBoolean; import java.io.IOException; import java.io.InputStream; @@ -18,10 +18,9 @@ public class FileDirectoryResponse implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private ListOfDirectoryEntry listOfDirectoryEntry = null; private BerBoolean moreFollows = null; - public FileDirectoryResponse() {} public FileDirectoryResponse(byte[] code) { @@ -44,6 +43,7 @@ public class FileDirectoryResponse implements BerType, Serializable { this.moreFollows = moreFollows; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -51,9 +51,7 @@ public class FileDirectoryResponse implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -86,50 +84,57 @@ public class FileDirectoryResponse implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); - - int totalLength = length.val; - codeLength += totalLength; + tlByteCount += length.decode(is); + int lengthVal = length.val; + vByteCount += berTag.decode(is); - subCodeLength += berTag.decode(is); if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) { - subCodeLength += length.decode(is); + vByteCount += length.decode(is); listOfDirectoryEntry = new ListOfDirectoryEntry(); - subCodeLength += listOfDirectoryEntry.decode(is, true); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += listOfDirectoryEntry.decode(is, true); + vByteCount += length.readEocIfIndefinite(is); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } - subCodeLength += berTag.decode(is); + vByteCount += berTag.decode(is); } else { - throw new IOException("Tag does not match the mandatory sequence element tag."); + throw new IOException("Tag does not match mandatory sequence component."); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) { moreFollows = new BerBoolean(); - subCodeLength += moreFollows.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += moreFollows.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } + vByteCount += berTag.decode(is); } + + if (lengthVal < 0) { + if (!berTag.equals(0, 0, 0)) { + throw new IOException("Decoded sequence has wrong end of contents octets"); + } + vByteCount += BerLength.readEocByte(is); + return tlByteCount + vByteCount; + } + throw new IOException( - "Unexpected end of sequence, length tag: " - + totalLength - + ", actual sequence length: " - + subCodeLength); + "Unexpected end of sequence, length tag: " + lengthVal + ", bytes decoded: " + vByteCount); } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -138,6 +143,7 @@ public class FileDirectoryResponse implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); @@ -177,7 +183,7 @@ public class FileDirectoryResponse implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private List seqOf = null; public ListOfDirectoryEntry() { @@ -195,6 +201,7 @@ public class FileDirectoryResponse implements BerType, Serializable { return seqOf; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -202,9 +209,7 @@ public class FileDirectoryResponse implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -225,36 +230,46 @@ public class FileDirectoryResponse implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; + BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); - int totalLength = length.val; + tlByteCount += length.decode(is); + int lengthVal = length.val; + + while (vByteCount < lengthVal || lengthVal < 0) { + vByteCount += berTag.decode(is); + + if (lengthVal < 0 && berTag.equals(0, 0, 0)) { + vByteCount += BerLength.readEocByte(is); + break; + } - while (subCodeLength < totalLength) { + if (!berTag.equals(DirectoryEntry.tag)) { + throw new IOException("Tag does not match mandatory sequence of/set of component."); + } DirectoryEntry element = new DirectoryEntry(); - subCodeLength += element.decode(is, true); + vByteCount += element.decode(is, false); seqOf.add(element); } - if (subCodeLength != totalLength) { + if (lengthVal >= 0 && vByteCount != lengthVal) { throw new IOException( "Decoded SequenceOf or SetOf has wrong length. Expected " - + totalLength + + lengthVal + " but has " - + subCodeLength); + + vByteCount); } - codeLength += subCodeLength; - - return codeLength; + return tlByteCount + vByteCount; } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -263,6 +278,7 @@ public class FileDirectoryResponse implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/FileName.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/FileName.java index 1911389..eadd30e 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/FileName.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/FileName.java @@ -1,11 +1,11 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; -import com.beanit.jasn1.ber.BerLength; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerType; -import com.beanit.jasn1.ber.types.string.BerGraphicString; +import com.beanit.asn1bean.ber.BerLength; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerType; +import com.beanit.asn1bean.ber.types.string.BerGraphicString; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -18,7 +18,7 @@ public class FileName implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private List seqOf = null; public FileName() { @@ -36,6 +36,7 @@ public class FileName implements BerType, Serializable { return seqOf; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -43,9 +44,7 @@ public class FileName implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -66,36 +65,46 @@ public class FileName implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; + BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); - int totalLength = length.val; + tlByteCount += length.decode(is); + int lengthVal = length.val; + + while (vByteCount < lengthVal || lengthVal < 0) { + vByteCount += berTag.decode(is); + + if (lengthVal < 0 && berTag.equals(0, 0, 0)) { + vByteCount += BerLength.readEocByte(is); + break; + } - while (subCodeLength < totalLength) { + if (!berTag.equals(BerGraphicString.tag)) { + throw new IOException("Tag does not match mandatory sequence of/set of component."); + } BerGraphicString element = new BerGraphicString(); - subCodeLength += element.decode(is, true); + vByteCount += element.decode(is, false); seqOf.add(element); } - if (subCodeLength != totalLength) { + if (lengthVal >= 0 && vByteCount != lengthVal) { throw new IOException( "Decoded SequenceOf or SetOf has wrong length. Expected " - + totalLength + + lengthVal + " but has " - + subCodeLength); + + vByteCount); } - codeLength += subCodeLength; - - return codeLength; + return tlByteCount + vByteCount; } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -104,6 +113,7 @@ public class FileName implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/FileOpenRequest.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/FileOpenRequest.java index 203a56e..bb7eec8 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/FileOpenRequest.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/FileOpenRequest.java @@ -1,10 +1,10 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; -import com.beanit.jasn1.ber.BerLength; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerType; +import com.beanit.asn1bean.ber.BerLength; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerType; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -14,7 +14,7 @@ public class FileOpenRequest implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private FileName fileName = null; private Unsigned32 initialPosition = null; @@ -40,6 +40,7 @@ public class FileOpenRequest implements BerType, Serializable { this.initialPosition = initialPosition; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -47,9 +48,7 @@ public class FileOpenRequest implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -76,46 +75,54 @@ public class FileOpenRequest implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); + tlByteCount += length.decode(is); + int lengthVal = length.val; + vByteCount += berTag.decode(is); - int totalLength = length.val; - codeLength += totalLength; - - subCodeLength += berTag.decode(is); if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) { fileName = new FileName(); - subCodeLength += fileName.decode(is, false); - subCodeLength += berTag.decode(is); + vByteCount += fileName.decode(is, false); + vByteCount += berTag.decode(is); } else { - throw new IOException("Tag does not match the mandatory sequence element tag."); + throw new IOException("Tag does not match mandatory sequence component."); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) { initialPosition = new Unsigned32(); - subCodeLength += initialPosition.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += initialPosition.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; + } + vByteCount += berTag.decode(is); + } else { + throw new IOException("Tag does not match mandatory sequence component."); + } + + if (lengthVal < 0) { + if (!berTag.equals(0, 0, 0)) { + throw new IOException("Decoded sequence has wrong end of contents octets"); } + vByteCount += BerLength.readEocByte(is); + return tlByteCount + vByteCount; } + throw new IOException( - "Unexpected end of sequence, length tag: " - + totalLength - + ", actual sequence length: " - + subCodeLength); + "Unexpected end of sequence, length tag: " + lengthVal + ", bytes decoded: " + vByteCount); } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -124,6 +131,7 @@ public class FileOpenRequest implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/FileOpenResponse.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/FileOpenResponse.java index c6cb851..08d67fb 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/FileOpenResponse.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/FileOpenResponse.java @@ -1,10 +1,10 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; -import com.beanit.jasn1.ber.BerLength; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerType; +import com.beanit.asn1bean.ber.BerLength; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerType; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -14,7 +14,7 @@ public class FileOpenResponse implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private Integer32 frsmID = null; private FileAttributes fileAttributes = null; @@ -40,6 +40,7 @@ public class FileOpenResponse implements BerType, Serializable { this.fileAttributes = fileAttributes; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -47,9 +48,7 @@ public class FileOpenResponse implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -76,46 +75,54 @@ public class FileOpenResponse implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); + tlByteCount += length.decode(is); + int lengthVal = length.val; + vByteCount += berTag.decode(is); - int totalLength = length.val; - codeLength += totalLength; - - subCodeLength += berTag.decode(is); if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) { frsmID = new Integer32(); - subCodeLength += frsmID.decode(is, false); - subCodeLength += berTag.decode(is); + vByteCount += frsmID.decode(is, false); + vByteCount += berTag.decode(is); } else { - throw new IOException("Tag does not match the mandatory sequence element tag."); + throw new IOException("Tag does not match mandatory sequence component."); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) { fileAttributes = new FileAttributes(); - subCodeLength += fileAttributes.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += fileAttributes.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; + } + vByteCount += berTag.decode(is); + } else { + throw new IOException("Tag does not match mandatory sequence component."); + } + + if (lengthVal < 0) { + if (!berTag.equals(0, 0, 0)) { + throw new IOException("Decoded sequence has wrong end of contents octets"); } + vByteCount += BerLength.readEocByte(is); + return tlByteCount + vByteCount; } + throw new IOException( - "Unexpected end of sequence, length tag: " - + totalLength - + ", actual sequence length: " - + subCodeLength); + "Unexpected end of sequence, length tag: " + lengthVal + ", bytes decoded: " + vByteCount); } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -124,6 +131,7 @@ public class FileOpenResponse implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/FileReadRequest.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/FileReadRequest.java index e3bdb23..87c455c 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/FileReadRequest.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/FileReadRequest.java @@ -1,4 +1,4 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; import java.math.BigInteger; diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/FileReadResponse.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/FileReadResponse.java index 514cf1f..6fae517 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/FileReadResponse.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/FileReadResponse.java @@ -1,11 +1,11 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; -import com.beanit.jasn1.ber.BerLength; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerOctetString; -import com.beanit.jasn1.ber.types.BerType; +import com.beanit.asn1bean.ber.BerLength; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerOctetString; +import com.beanit.asn1bean.ber.types.BerType; import com.beanit.openiec61850.internal.BerBoolean; import java.io.IOException; import java.io.InputStream; @@ -16,7 +16,7 @@ public class FileReadResponse implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private BerOctetString fileData = null; private BerBoolean moreFollows = null; @@ -42,6 +42,7 @@ public class FileReadResponse implements BerType, Serializable { this.moreFollows = moreFollows; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -49,9 +50,7 @@ public class FileReadResponse implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -80,49 +79,55 @@ public class FileReadResponse implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); + tlByteCount += length.decode(is); + int lengthVal = length.val; + vByteCount += berTag.decode(is); - int totalLength = length.val; - codeLength += totalLength; - - subCodeLength += berTag.decode(is); if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) { fileData = new BerOctetString(); - subCodeLength += fileData.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += fileData.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } - subCodeLength += berTag.decode(is); + vByteCount += berTag.decode(is); } else { - throw new IOException("Tag does not match the mandatory sequence element tag."); + throw new IOException("Tag does not match mandatory sequence component."); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) { moreFollows = new BerBoolean(); - subCodeLength += moreFollows.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += moreFollows.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } + vByteCount += berTag.decode(is); } + + if (lengthVal < 0) { + if (!berTag.equals(0, 0, 0)) { + throw new IOException("Decoded sequence has wrong end of contents octets"); + } + vByteCount += BerLength.readEocByte(is); + return tlByteCount + vByteCount; + } + throw new IOException( - "Unexpected end of sequence, length tag: " - + totalLength - + ", actual sequence length: " - + subCodeLength); + "Unexpected end of sequence, length tag: " + lengthVal + ", bytes decoded: " + vByteCount); } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -131,6 +136,7 @@ public class FileReadResponse implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/FloatingPoint.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/FloatingPoint.java index e83289c..ab6baf9 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/FloatingPoint.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/FloatingPoint.java @@ -1,7 +1,7 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; -import com.beanit.jasn1.ber.types.BerOctetString; +import com.beanit.asn1bean.ber.types.BerOctetString; public class FloatingPoint extends BerOctetString { diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/GetNameListRequest.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/GetNameListRequest.java index b0b48ef..4addee5 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/GetNameListRequest.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/GetNameListRequest.java @@ -1,11 +1,11 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; -import com.beanit.jasn1.ber.BerLength; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerNull; -import com.beanit.jasn1.ber.types.BerType; +import com.beanit.asn1bean.ber.BerLength; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerNull; +import com.beanit.asn1bean.ber.types.BerType; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -15,11 +15,10 @@ public class GetNameListRequest implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private ObjectClass objectClass = null; private ObjectScope objectScope = null; private Identifier continueAfter = null; - public GetNameListRequest() {} public GetNameListRequest(byte[] code) { @@ -50,6 +49,7 @@ public class GetNameListRequest implements BerType, Serializable { this.continueAfter = continueAfter; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -57,9 +57,7 @@ public class GetNameListRequest implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -99,59 +97,67 @@ public class GetNameListRequest implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); - - int totalLength = length.val; - codeLength += totalLength; + tlByteCount += length.decode(is); + int lengthVal = length.val; + vByteCount += berTag.decode(is); - subCodeLength += berTag.decode(is); if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) { - subCodeLength += length.decode(is); + vByteCount += length.decode(is); objectClass = new ObjectClass(); - subCodeLength += objectClass.decode(is, null); - subCodeLength += berTag.decode(is); + vByteCount += objectClass.decode(is, null); + vByteCount += length.readEocIfIndefinite(is); + vByteCount += berTag.decode(is); } else { - throw new IOException("Tag does not match the mandatory sequence element tag."); + throw new IOException("Tag does not match mandatory sequence component."); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) { - subCodeLength += length.decode(is); + vByteCount += length.decode(is); objectScope = new ObjectScope(); - subCodeLength += objectScope.decode(is, null); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += objectScope.decode(is, null); + vByteCount += length.readEocIfIndefinite(is); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } - subCodeLength += berTag.decode(is); + vByteCount += berTag.decode(is); } else { - throw new IOException("Tag does not match the mandatory sequence element tag."); + throw new IOException("Tag does not match mandatory sequence component."); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 2)) { continueAfter = new Identifier(); - subCodeLength += continueAfter.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += continueAfter.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; + } + vByteCount += berTag.decode(is); + } + + if (lengthVal < 0) { + if (!berTag.equals(0, 0, 0)) { + throw new IOException("Decoded sequence has wrong end of contents octets"); } + vByteCount += BerLength.readEocByte(is); + return tlByteCount + vByteCount; } + throw new IOException( - "Unexpected end of sequence, length tag: " - + totalLength - + ", actual sequence length: " - + subCodeLength); + "Unexpected end of sequence, length tag: " + lengthVal + ", bytes decoded: " + vByteCount); } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -160,6 +166,7 @@ public class GetNameListRequest implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); @@ -210,7 +217,7 @@ public class GetNameListRequest implements BerType, Serializable { private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private BerNull vmdSpecific = null; private Identifier domainSpecific = null; private BerNull aaSpecific = null; @@ -245,12 +252,11 @@ public class GetNameListRequest implements BerType, Serializable { this.aaSpecific = aaSpecific; } + @Override public int encode(OutputStream reverseOS) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); return code.length; } @@ -282,39 +288,40 @@ public class GetNameListRequest implements BerType, Serializable { throw new IOException("Error encoding CHOICE: No element of CHOICE was selected."); } + @Override public int decode(InputStream is) throws IOException { return decode(is, null); } public int decode(InputStream is, BerTag berTag) throws IOException { - int codeLength = 0; - BerTag passedTag = berTag; + int tlvByteCount = 0; + boolean tagWasPassed = (berTag != null); if (berTag == null) { berTag = new BerTag(); - codeLength += berTag.decode(is); + tlvByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) { vmdSpecific = new BerNull(); - codeLength += vmdSpecific.decode(is, false); - return codeLength; + tlvByteCount += vmdSpecific.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) { domainSpecific = new Identifier(); - codeLength += domainSpecific.decode(is, false); - return codeLength; + tlvByteCount += domainSpecific.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 2)) { aaSpecific = new BerNull(); - codeLength += aaSpecific.decode(is, false); - return codeLength; + tlvByteCount += aaSpecific.decode(is, false); + return tlvByteCount; } - if (passedTag != null) { + if (tagWasPassed) { return 0; } @@ -327,6 +334,7 @@ public class GetNameListRequest implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/GetNameListResponse.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/GetNameListResponse.java index 6769f1e..95de079 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/GetNameListResponse.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/GetNameListResponse.java @@ -1,10 +1,10 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; -import com.beanit.jasn1.ber.BerLength; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerType; +import com.beanit.asn1bean.ber.BerLength; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerType; import com.beanit.openiec61850.internal.BerBoolean; import java.io.IOException; import java.io.InputStream; @@ -18,10 +18,9 @@ public class GetNameListResponse implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private ListOfIdentifier listOfIdentifier = null; private BerBoolean moreFollows = null; - public GetNameListResponse() {} public GetNameListResponse(byte[] code) { @@ -44,6 +43,7 @@ public class GetNameListResponse implements BerType, Serializable { this.moreFollows = moreFollows; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -51,9 +51,7 @@ public class GetNameListResponse implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -82,49 +80,55 @@ public class GetNameListResponse implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); - - int totalLength = length.val; - codeLength += totalLength; + tlByteCount += length.decode(is); + int lengthVal = length.val; + vByteCount += berTag.decode(is); - subCodeLength += berTag.decode(is); if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) { listOfIdentifier = new ListOfIdentifier(); - subCodeLength += listOfIdentifier.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += listOfIdentifier.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } - subCodeLength += berTag.decode(is); + vByteCount += berTag.decode(is); } else { - throw new IOException("Tag does not match the mandatory sequence element tag."); + throw new IOException("Tag does not match mandatory sequence component."); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) { moreFollows = new BerBoolean(); - subCodeLength += moreFollows.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += moreFollows.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } + vByteCount += berTag.decode(is); } + + if (lengthVal < 0) { + if (!berTag.equals(0, 0, 0)) { + throw new IOException("Decoded sequence has wrong end of contents octets"); + } + vByteCount += BerLength.readEocByte(is); + return tlByteCount + vByteCount; + } + throw new IOException( - "Unexpected end of sequence, length tag: " - + totalLength - + ", actual sequence length: " - + subCodeLength); + "Unexpected end of sequence, length tag: " + lengthVal + ", bytes decoded: " + vByteCount); } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -133,6 +137,7 @@ public class GetNameListResponse implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); @@ -172,7 +177,7 @@ public class GetNameListResponse implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private List seqOf = null; public ListOfIdentifier() { @@ -190,6 +195,7 @@ public class GetNameListResponse implements BerType, Serializable { return seqOf; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -197,9 +203,7 @@ public class GetNameListResponse implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -220,36 +224,46 @@ public class GetNameListResponse implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; + BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); - int totalLength = length.val; + tlByteCount += length.decode(is); + int lengthVal = length.val; + + while (vByteCount < lengthVal || lengthVal < 0) { + vByteCount += berTag.decode(is); + + if (lengthVal < 0 && berTag.equals(0, 0, 0)) { + vByteCount += BerLength.readEocByte(is); + break; + } - while (subCodeLength < totalLength) { + if (!berTag.equals(Identifier.tag)) { + throw new IOException("Tag does not match mandatory sequence of/set of component."); + } Identifier element = new Identifier(); - subCodeLength += element.decode(is, true); + vByteCount += element.decode(is, false); seqOf.add(element); } - if (subCodeLength != totalLength) { + if (lengthVal >= 0 && vByteCount != lengthVal) { throw new IOException( "Decoded SequenceOf or SetOf has wrong length. Expected " - + totalLength + + lengthVal + " but has " - + subCodeLength); + + vByteCount); } - codeLength += subCodeLength; - - return codeLength; + return tlByteCount + vByteCount; } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -258,6 +272,7 @@ public class GetNameListResponse implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/GetNamedVariableListAttributesRequest.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/GetNamedVariableListAttributesRequest.java index fc386db..5720fa9 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/GetNamedVariableListAttributesRequest.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/GetNamedVariableListAttributesRequest.java @@ -1,4 +1,4 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; public class GetNamedVariableListAttributesRequest extends ObjectName { diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/GetNamedVariableListAttributesResponse.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/GetNamedVariableListAttributesResponse.java index f97f6d0..203bd37 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/GetNamedVariableListAttributesResponse.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/GetNamedVariableListAttributesResponse.java @@ -1,10 +1,10 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; -import com.beanit.jasn1.ber.BerLength; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerType; +import com.beanit.asn1bean.ber.BerLength; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerType; import com.beanit.openiec61850.internal.BerBoolean; import java.io.IOException; import java.io.InputStream; @@ -15,7 +15,7 @@ public class GetNamedVariableListAttributesResponse implements BerType, Serializ public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private BerBoolean mmsDeletable = null; private VariableDefs listOfVariable = null; @@ -41,6 +41,7 @@ public class GetNamedVariableListAttributesResponse implements BerType, Serializ this.listOfVariable = listOfVariable; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -48,9 +49,7 @@ public class GetNamedVariableListAttributesResponse implements BerType, Serializ public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -77,46 +76,54 @@ public class GetNamedVariableListAttributesResponse implements BerType, Serializ return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); + tlByteCount += length.decode(is); + int lengthVal = length.val; + vByteCount += berTag.decode(is); - int totalLength = length.val; - codeLength += totalLength; - - subCodeLength += berTag.decode(is); if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) { mmsDeletable = new BerBoolean(); - subCodeLength += mmsDeletable.decode(is, false); - subCodeLength += berTag.decode(is); + vByteCount += mmsDeletable.decode(is, false); + vByteCount += berTag.decode(is); } else { - throw new IOException("Tag does not match the mandatory sequence element tag."); + throw new IOException("Tag does not match mandatory sequence component."); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) { listOfVariable = new VariableDefs(); - subCodeLength += listOfVariable.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += listOfVariable.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; + } + vByteCount += berTag.decode(is); + } else { + throw new IOException("Tag does not match mandatory sequence component."); + } + + if (lengthVal < 0) { + if (!berTag.equals(0, 0, 0)) { + throw new IOException("Decoded sequence has wrong end of contents octets"); } + vByteCount += BerLength.readEocByte(is); + return tlByteCount + vByteCount; } + throw new IOException( - "Unexpected end of sequence, length tag: " - + totalLength - + ", actual sequence length: " - + subCodeLength); + "Unexpected end of sequence, length tag: " + lengthVal + ", bytes decoded: " + vByteCount); } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -125,6 +132,7 @@ public class GetNamedVariableListAttributesResponse implements BerType, Serializ code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/GetVariableAccessAttributesRequest.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/GetVariableAccessAttributesRequest.java index 3af6c9f..b152c1c 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/GetVariableAccessAttributesRequest.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/GetVariableAccessAttributesRequest.java @@ -1,10 +1,10 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; -import com.beanit.jasn1.ber.BerLength; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerType; +import com.beanit.asn1bean.ber.BerLength; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerType; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -14,7 +14,7 @@ public class GetVariableAccessAttributesRequest implements BerType, Serializable private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private ObjectName name = null; public GetVariableAccessAttributesRequest() {} @@ -31,12 +31,11 @@ public class GetVariableAccessAttributesRequest implements BerType, Serializable this.name = name; } + @Override public int encode(OutputStream reverseOS) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); return code.length; } @@ -56,28 +55,31 @@ public class GetVariableAccessAttributesRequest implements BerType, Serializable throw new IOException("Error encoding CHOICE: No element of CHOICE was selected."); } + @Override public int decode(InputStream is) throws IOException { return decode(is, null); } public int decode(InputStream is, BerTag berTag) throws IOException { - int codeLength = 0; - BerTag passedTag = berTag; + int tlvByteCount = 0; + boolean tagWasPassed = (berTag != null); if (berTag == null) { berTag = new BerTag(); - codeLength += berTag.decode(is); + tlvByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) { - codeLength += BerLength.skip(is); + BerLength explicitTagLength = new BerLength(); + tlvByteCount += explicitTagLength.decode(is); name = new ObjectName(); - codeLength += name.decode(is, null); - return codeLength; + tlvByteCount += name.decode(is, null); + tlvByteCount += explicitTagLength.readEocIfIndefinite(is); + return tlvByteCount; } - if (passedTag != null) { + if (tagWasPassed) { return 0; } @@ -90,6 +92,7 @@ public class GetVariableAccessAttributesRequest implements BerType, Serializable code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/GetVariableAccessAttributesResponse.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/GetVariableAccessAttributesResponse.java index be66df8..0ec1de6 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/GetVariableAccessAttributesResponse.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/GetVariableAccessAttributesResponse.java @@ -1,10 +1,10 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; -import com.beanit.jasn1.ber.BerLength; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerType; +import com.beanit.asn1bean.ber.BerLength; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerType; import com.beanit.openiec61850.internal.BerBoolean; import java.io.IOException; import java.io.InputStream; @@ -15,7 +15,7 @@ public class GetVariableAccessAttributesResponse implements BerType, Serializabl public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private BerBoolean mmsDeletable = null; private TypeDescription typeDescription = null; @@ -41,6 +41,7 @@ public class GetVariableAccessAttributesResponse implements BerType, Serializabl this.typeDescription = typeDescription; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -48,9 +49,7 @@ public class GetVariableAccessAttributesResponse implements BerType, Serializabl public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -81,47 +80,56 @@ public class GetVariableAccessAttributesResponse implements BerType, Serializabl return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); + tlByteCount += length.decode(is); + int lengthVal = length.val; + vByteCount += berTag.decode(is); - int totalLength = length.val; - codeLength += totalLength; - - subCodeLength += berTag.decode(is); if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) { mmsDeletable = new BerBoolean(); - subCodeLength += mmsDeletable.decode(is, false); - subCodeLength += berTag.decode(is); + vByteCount += mmsDeletable.decode(is, false); + vByteCount += berTag.decode(is); } else { - throw new IOException("Tag does not match the mandatory sequence element tag."); + throw new IOException("Tag does not match mandatory sequence component."); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 2)) { - subCodeLength += length.decode(is); + vByteCount += length.decode(is); typeDescription = new TypeDescription(); - subCodeLength += typeDescription.decode(is, null); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += typeDescription.decode(is, null); + vByteCount += length.readEocIfIndefinite(is); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; + } + vByteCount += berTag.decode(is); + } else { + throw new IOException("Tag does not match mandatory sequence component."); + } + + if (lengthVal < 0) { + if (!berTag.equals(0, 0, 0)) { + throw new IOException("Decoded sequence has wrong end of contents octets"); } + vByteCount += BerLength.readEocByte(is); + return tlByteCount + vByteCount; } + throw new IOException( - "Unexpected end of sequence, length tag: " - + totalLength - + ", actual sequence length: " - + subCodeLength); + "Unexpected end of sequence, length tag: " + lengthVal + ", bytes decoded: " + vByteCount); } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -130,6 +138,7 @@ public class GetVariableAccessAttributesResponse implements BerType, Serializabl code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/Identifier.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/Identifier.java index 72be23a..bdbcf19 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/Identifier.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/Identifier.java @@ -1,7 +1,7 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; -import com.beanit.jasn1.ber.types.string.BerVisibleString; +import com.beanit.asn1bean.ber.types.string.BerVisibleString; public class Identifier extends BerVisibleString { diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/InformationReport.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/InformationReport.java index e852b90..c37ea2a 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/InformationReport.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/InformationReport.java @@ -1,10 +1,10 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; -import com.beanit.jasn1.ber.BerLength; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerType; +import com.beanit.asn1bean.ber.BerLength; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerType; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -17,10 +17,9 @@ public class InformationReport implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private VariableAccessSpecification variableAccessSpecification = null; private ListOfAccessResult listOfAccessResult = null; - public InformationReport() {} public InformationReport(byte[] code) { @@ -44,6 +43,7 @@ public class InformationReport implements BerType, Serializable { this.listOfAccessResult = listOfAccessResult; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -51,9 +51,7 @@ public class InformationReport implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -77,42 +75,55 @@ public class InformationReport implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; + int numDecodedBytes; BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); + tlByteCount += length.decode(is); + int lengthVal = length.val; + vByteCount += berTag.decode(is); - int totalLength = length.val; - codeLength += totalLength; - - subCodeLength += berTag.decode(is); variableAccessSpecification = new VariableAccessSpecification(); - subCodeLength += variableAccessSpecification.decode(is, berTag); - subCodeLength += berTag.decode(is); - + numDecodedBytes = variableAccessSpecification.decode(is, berTag); + if (numDecodedBytes != 0) { + vByteCount += numDecodedBytes; + vByteCount += berTag.decode(is); + } else { + throw new IOException("Tag does not match mandatory sequence component."); + } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) { listOfAccessResult = new ListOfAccessResult(); - subCodeLength += listOfAccessResult.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += listOfAccessResult.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; + } + vByteCount += berTag.decode(is); + } else { + throw new IOException("Tag does not match mandatory sequence component."); + } + + if (lengthVal < 0) { + if (!berTag.equals(0, 0, 0)) { + throw new IOException("Decoded sequence has wrong end of contents octets"); } + vByteCount += BerLength.readEocByte(is); + return tlByteCount + vByteCount; } + throw new IOException( - "Unexpected end of sequence, length tag: " - + totalLength - + ", actual sequence length: " - + subCodeLength); + "Unexpected end of sequence, length tag: " + lengthVal + ", bytes decoded: " + vByteCount); } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -121,6 +132,7 @@ public class InformationReport implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); @@ -163,7 +175,7 @@ public class InformationReport implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private List seqOf = null; public ListOfAccessResult() { @@ -181,6 +193,7 @@ public class InformationReport implements BerType, Serializable { return seqOf; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -188,9 +201,7 @@ public class InformationReport implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -211,36 +222,48 @@ public class InformationReport implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; + int numDecodedBytes; + BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); - int totalLength = length.val; + tlByteCount += length.decode(is); + int lengthVal = length.val; + + while (vByteCount < lengthVal || lengthVal < 0) { + vByteCount += berTag.decode(is); + + if (lengthVal < 0 && berTag.equals(0, 0, 0)) { + vByteCount += BerLength.readEocByte(is); + break; + } - while (subCodeLength < totalLength) { AccessResult element = new AccessResult(); - subCodeLength += element.decode(is, null); + numDecodedBytes = element.decode(is, berTag); + if (numDecodedBytes == 0) { + throw new IOException("Tag did not match"); + } + vByteCount += numDecodedBytes; seqOf.add(element); } - if (subCodeLength != totalLength) { + if (lengthVal >= 0 && vByteCount != lengthVal) { throw new IOException( "Decoded SequenceOf or SetOf has wrong length. Expected " - + totalLength + + lengthVal + " but has " - + subCodeLength); + + vByteCount); } - codeLength += subCodeLength; - - return codeLength; + return tlByteCount + vByteCount; } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -249,6 +272,7 @@ public class InformationReport implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/InitiateErrorPDU.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/InitiateErrorPDU.java index b5680be..875bcc4 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/InitiateErrorPDU.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/InitiateErrorPDU.java @@ -1,4 +1,4 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; public class InitiateErrorPDU extends ServiceError { diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/InitiateRequestPDU.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/InitiateRequestPDU.java index c8249b8..8589d20 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/InitiateRequestPDU.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/InitiateRequestPDU.java @@ -1,10 +1,10 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; -import com.beanit.jasn1.ber.BerLength; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerType; +import com.beanit.asn1bean.ber.BerLength; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerType; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -14,13 +14,12 @@ public class InitiateRequestPDU implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private Integer32 localDetailCalling = null; private Integer16 proposedMaxServOutstandingCalling = null; private Integer16 proposedMaxServOutstandingCalled = null; private Integer8 proposedDataStructureNestingLevel = null; private InitRequestDetail initRequestDetail = null; - public InitiateRequestPDU() {} public InitiateRequestPDU(byte[] code) { @@ -67,6 +66,7 @@ public class InitiateRequestPDU implements BerType, Serializable { this.initRequestDetail = initRequestDetail; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -74,9 +74,7 @@ public class InitiateRequestPDU implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -122,66 +120,74 @@ public class InitiateRequestPDU implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); + tlByteCount += length.decode(is); + int lengthVal = length.val; + vByteCount += berTag.decode(is); - int totalLength = length.val; - codeLength += totalLength; - - subCodeLength += berTag.decode(is); if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) { localDetailCalling = new Integer32(); - subCodeLength += localDetailCalling.decode(is, false); - subCodeLength += berTag.decode(is); + vByteCount += localDetailCalling.decode(is, false); + vByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) { proposedMaxServOutstandingCalling = new Integer16(); - subCodeLength += proposedMaxServOutstandingCalling.decode(is, false); - subCodeLength += berTag.decode(is); + vByteCount += proposedMaxServOutstandingCalling.decode(is, false); + vByteCount += berTag.decode(is); } else { - throw new IOException("Tag does not match the mandatory sequence element tag."); + throw new IOException("Tag does not match mandatory sequence component."); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 2)) { proposedMaxServOutstandingCalled = new Integer16(); - subCodeLength += proposedMaxServOutstandingCalled.decode(is, false); - subCodeLength += berTag.decode(is); + vByteCount += proposedMaxServOutstandingCalled.decode(is, false); + vByteCount += berTag.decode(is); } else { - throw new IOException("Tag does not match the mandatory sequence element tag."); + throw new IOException("Tag does not match mandatory sequence component."); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 3)) { proposedDataStructureNestingLevel = new Integer8(); - subCodeLength += proposedDataStructureNestingLevel.decode(is, false); - subCodeLength += berTag.decode(is); + vByteCount += proposedDataStructureNestingLevel.decode(is, false); + vByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 4)) { initRequestDetail = new InitRequestDetail(); - subCodeLength += initRequestDetail.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += initRequestDetail.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } + vByteCount += berTag.decode(is); + } else { + throw new IOException("Tag does not match mandatory sequence component."); } + + if (lengthVal < 0) { + if (!berTag.equals(0, 0, 0)) { + throw new IOException("Decoded sequence has wrong end of contents octets"); + } + vByteCount += BerLength.readEocByte(is); + return tlByteCount + vByteCount; + } + throw new IOException( - "Unexpected end of sequence, length tag: " - + totalLength - + ", actual sequence length: " - + subCodeLength); + "Unexpected end of sequence, length tag: " + lengthVal + ", bytes decoded: " + vByteCount); } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -190,6 +196,7 @@ public class InitiateRequestPDU implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); @@ -261,7 +268,7 @@ public class InitiateRequestPDU implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private Integer16 proposedVersionNumber = null; private ParameterSupportOptions proposedParameterCBB = null; private ServiceSupportOptions servicesSupportedCalling = null; @@ -296,6 +303,7 @@ public class InitiateRequestPDU implements BerType, Serializable { this.servicesSupportedCalling = servicesSupportedCalling; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -303,9 +311,7 @@ public class InitiateRequestPDU implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -337,54 +343,65 @@ public class InitiateRequestPDU implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); + tlByteCount += length.decode(is); + int lengthVal = length.val; + vByteCount += berTag.decode(is); - int totalLength = length.val; - codeLength += totalLength; - - subCodeLength += berTag.decode(is); if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) { proposedVersionNumber = new Integer16(); - subCodeLength += proposedVersionNumber.decode(is, false); - subCodeLength += berTag.decode(is); + vByteCount += proposedVersionNumber.decode(is, false); + vByteCount += berTag.decode(is); } else { - throw new IOException("Tag does not match the mandatory sequence element tag."); + throw new IOException("Tag does not match mandatory sequence component."); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) { proposedParameterCBB = new ParameterSupportOptions(); - subCodeLength += proposedParameterCBB.decode(is, false); - subCodeLength += berTag.decode(is); + vByteCount += proposedParameterCBB.decode(is, false); + vByteCount += berTag.decode(is); } else { - throw new IOException("Tag does not match the mandatory sequence element tag."); + throw new IOException("Tag does not match mandatory sequence component."); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 2)) { servicesSupportedCalling = new ServiceSupportOptions(); - subCodeLength += servicesSupportedCalling.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += servicesSupportedCalling.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; + } + vByteCount += berTag.decode(is); + } else { + throw new IOException("Tag does not match mandatory sequence component."); + } + + if (lengthVal < 0) { + if (!berTag.equals(0, 0, 0)) { + throw new IOException("Decoded sequence has wrong end of contents octets"); } + vByteCount += BerLength.readEocByte(is); + return tlByteCount + vByteCount; } + throw new IOException( "Unexpected end of sequence, length tag: " - + totalLength - + ", actual sequence length: " - + subCodeLength); + + lengthVal + + ", bytes decoded: " + + vByteCount); } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -393,6 +410,7 @@ public class InitiateRequestPDU implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/InitiateResponsePDU.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/InitiateResponsePDU.java index 7286f8e..81a17f7 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/InitiateResponsePDU.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/InitiateResponsePDU.java @@ -1,10 +1,10 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; -import com.beanit.jasn1.ber.BerLength; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerType; +import com.beanit.asn1bean.ber.BerLength; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerType; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -14,13 +14,12 @@ public class InitiateResponsePDU implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private Integer32 localDetailCalled = null; private Integer16 negotiatedMaxServOutstandingCalling = null; private Integer16 negotiatedMaxServOutstandingCalled = null; private Integer8 negotiatedDataStructureNestingLevel = null; private InitResponseDetail initResponseDetail = null; - public InitiateResponsePDU() {} public InitiateResponsePDU(byte[] code) { @@ -68,6 +67,7 @@ public class InitiateResponsePDU implements BerType, Serializable { this.initResponseDetail = initResponseDetail; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -75,9 +75,7 @@ public class InitiateResponsePDU implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -123,66 +121,74 @@ public class InitiateResponsePDU implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); + tlByteCount += length.decode(is); + int lengthVal = length.val; + vByteCount += berTag.decode(is); - int totalLength = length.val; - codeLength += totalLength; - - subCodeLength += berTag.decode(is); if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) { localDetailCalled = new Integer32(); - subCodeLength += localDetailCalled.decode(is, false); - subCodeLength += berTag.decode(is); + vByteCount += localDetailCalled.decode(is, false); + vByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) { negotiatedMaxServOutstandingCalling = new Integer16(); - subCodeLength += negotiatedMaxServOutstandingCalling.decode(is, false); - subCodeLength += berTag.decode(is); + vByteCount += negotiatedMaxServOutstandingCalling.decode(is, false); + vByteCount += berTag.decode(is); } else { - throw new IOException("Tag does not match the mandatory sequence element tag."); + throw new IOException("Tag does not match mandatory sequence component."); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 2)) { negotiatedMaxServOutstandingCalled = new Integer16(); - subCodeLength += negotiatedMaxServOutstandingCalled.decode(is, false); - subCodeLength += berTag.decode(is); + vByteCount += negotiatedMaxServOutstandingCalled.decode(is, false); + vByteCount += berTag.decode(is); } else { - throw new IOException("Tag does not match the mandatory sequence element tag."); + throw new IOException("Tag does not match mandatory sequence component."); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 3)) { negotiatedDataStructureNestingLevel = new Integer8(); - subCodeLength += negotiatedDataStructureNestingLevel.decode(is, false); - subCodeLength += berTag.decode(is); + vByteCount += negotiatedDataStructureNestingLevel.decode(is, false); + vByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 4)) { initResponseDetail = new InitResponseDetail(); - subCodeLength += initResponseDetail.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += initResponseDetail.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } + vByteCount += berTag.decode(is); + } else { + throw new IOException("Tag does not match mandatory sequence component."); } + + if (lengthVal < 0) { + if (!berTag.equals(0, 0, 0)) { + throw new IOException("Decoded sequence has wrong end of contents octets"); + } + vByteCount += BerLength.readEocByte(is); + return tlByteCount + vByteCount; + } + throw new IOException( - "Unexpected end of sequence, length tag: " - + totalLength - + ", actual sequence length: " - + subCodeLength); + "Unexpected end of sequence, length tag: " + lengthVal + ", bytes decoded: " + vByteCount); } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -191,6 +197,7 @@ public class InitiateResponsePDU implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); @@ -264,7 +271,7 @@ public class InitiateResponsePDU implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private Integer16 negotiatedVersionNumber = null; private ParameterSupportOptions negotiatedParameterCBB = null; private ServiceSupportOptions servicesSupportedCalled = null; @@ -299,6 +306,7 @@ public class InitiateResponsePDU implements BerType, Serializable { this.servicesSupportedCalled = servicesSupportedCalled; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -306,9 +314,7 @@ public class InitiateResponsePDU implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -340,54 +346,65 @@ public class InitiateResponsePDU implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); + tlByteCount += length.decode(is); + int lengthVal = length.val; + vByteCount += berTag.decode(is); - int totalLength = length.val; - codeLength += totalLength; - - subCodeLength += berTag.decode(is); if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) { negotiatedVersionNumber = new Integer16(); - subCodeLength += negotiatedVersionNumber.decode(is, false); - subCodeLength += berTag.decode(is); + vByteCount += negotiatedVersionNumber.decode(is, false); + vByteCount += berTag.decode(is); } else { - throw new IOException("Tag does not match the mandatory sequence element tag."); + throw new IOException("Tag does not match mandatory sequence component."); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) { negotiatedParameterCBB = new ParameterSupportOptions(); - subCodeLength += negotiatedParameterCBB.decode(is, false); - subCodeLength += berTag.decode(is); + vByteCount += negotiatedParameterCBB.decode(is, false); + vByteCount += berTag.decode(is); } else { - throw new IOException("Tag does not match the mandatory sequence element tag."); + throw new IOException("Tag does not match mandatory sequence component."); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 2)) { servicesSupportedCalled = new ServiceSupportOptions(); - subCodeLength += servicesSupportedCalled.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += servicesSupportedCalled.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; + } + vByteCount += berTag.decode(is); + } else { + throw new IOException("Tag does not match mandatory sequence component."); + } + + if (lengthVal < 0) { + if (!berTag.equals(0, 0, 0)) { + throw new IOException("Decoded sequence has wrong end of contents octets"); } + vByteCount += BerLength.readEocByte(is); + return tlByteCount + vByteCount; } + throw new IOException( "Unexpected end of sequence, length tag: " - + totalLength - + ", actual sequence length: " - + subCodeLength); + + lengthVal + + ", bytes decoded: " + + vByteCount); } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -396,6 +413,7 @@ public class InitiateResponsePDU implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/Integer16.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/Integer16.java index 5587cb5..7c8e120 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/Integer16.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/Integer16.java @@ -1,7 +1,7 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; -import com.beanit.jasn1.ber.types.BerInteger; +import com.beanit.asn1bean.ber.types.BerInteger; import java.math.BigInteger; public class Integer16 extends BerInteger { diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/Integer32.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/Integer32.java index e4fef9d..f36dbb4 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/Integer32.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/Integer32.java @@ -1,7 +1,7 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; -import com.beanit.jasn1.ber.types.BerInteger; +import com.beanit.asn1bean.ber.types.BerInteger; import java.math.BigInteger; public class Integer32 extends BerInteger { diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/Integer8.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/Integer8.java index 0a814eb..a1c3d6c 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/Integer8.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/Integer8.java @@ -1,7 +1,7 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; -import com.beanit.jasn1.ber.types.BerInteger; +import com.beanit.asn1bean.ber.types.BerInteger; import java.math.BigInteger; public class Integer8 extends BerInteger { diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/MMSString.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/MMSString.java index 68bcb99..5e9b889 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/MMSString.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/MMSString.java @@ -1,7 +1,7 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; -import com.beanit.jasn1.ber.types.string.BerVisibleString; +import com.beanit.asn1bean.ber.types.string.BerVisibleString; public class MMSString extends BerVisibleString { diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/MMSpdu.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/MMSpdu.java index d5bd224..1dc5913 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/MMSpdu.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/MMSpdu.java @@ -1,9 +1,9 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerType; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerType; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -13,7 +13,7 @@ public class MMSpdu implements BerType, Serializable { private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private ConfirmedRequestPDU confirmedRequestPDU = null; private ConfirmedResponsePDU confirmedResponsePDU = null; private ConfirmedErrorPDU confirmedErrorPDU = null; @@ -102,12 +102,11 @@ public class MMSpdu implements BerType, Serializable { this.concludeRequestPDU = concludeRequestPDU; } + @Override public int encode(OutputStream reverseOS) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); return code.length; } @@ -187,75 +186,76 @@ public class MMSpdu implements BerType, Serializable { throw new IOException("Error encoding CHOICE: No element of CHOICE was selected."); } + @Override public int decode(InputStream is) throws IOException { return decode(is, null); } public int decode(InputStream is, BerTag berTag) throws IOException { - int codeLength = 0; - BerTag passedTag = berTag; + int tlvByteCount = 0; + boolean tagWasPassed = (berTag != null); if (berTag == null) { berTag = new BerTag(); - codeLength += berTag.decode(is); + tlvByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) { confirmedRequestPDU = new ConfirmedRequestPDU(); - codeLength += confirmedRequestPDU.decode(is, false); - return codeLength; + tlvByteCount += confirmedRequestPDU.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) { confirmedResponsePDU = new ConfirmedResponsePDU(); - codeLength += confirmedResponsePDU.decode(is, false); - return codeLength; + tlvByteCount += confirmedResponsePDU.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 2)) { confirmedErrorPDU = new ConfirmedErrorPDU(); - codeLength += confirmedErrorPDU.decode(is, false); - return codeLength; + tlvByteCount += confirmedErrorPDU.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 3)) { unconfirmedPDU = new UnconfirmedPDU(); - codeLength += unconfirmedPDU.decode(is, false); - return codeLength; + tlvByteCount += unconfirmedPDU.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 4)) { rejectPDU = new RejectPDU(); - codeLength += rejectPDU.decode(is, false); - return codeLength; + tlvByteCount += rejectPDU.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 8)) { initiateRequestPDU = new InitiateRequestPDU(); - codeLength += initiateRequestPDU.decode(is, false); - return codeLength; + tlvByteCount += initiateRequestPDU.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 9)) { initiateResponsePDU = new InitiateResponsePDU(); - codeLength += initiateResponsePDU.decode(is, false); - return codeLength; + tlvByteCount += initiateResponsePDU.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 10)) { initiateErrorPDU = new InitiateErrorPDU(); - codeLength += initiateErrorPDU.decode(is, false); - return codeLength; + tlvByteCount += initiateErrorPDU.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 11)) { concludeRequestPDU = new ConcludeRequestPDU(); - codeLength += concludeRequestPDU.decode(is, false); - return codeLength; + tlvByteCount += concludeRequestPDU.decode(is, false); + return tlvByteCount; } - if (passedTag != null) { + if (tagWasPassed) { return 0; } @@ -268,6 +268,7 @@ public class MMSpdu implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/ObjectClass.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/ObjectClass.java index 53d0957..a7c0537 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/ObjectClass.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/ObjectClass.java @@ -1,10 +1,10 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerInteger; -import com.beanit.jasn1.ber.types.BerType; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerInteger; +import com.beanit.asn1bean.ber.types.BerType; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -14,7 +14,7 @@ public class ObjectClass implements BerType, Serializable { private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private BerInteger basicObjectClass = null; public ObjectClass() {} @@ -31,12 +31,11 @@ public class ObjectClass implements BerType, Serializable { this.basicObjectClass = basicObjectClass; } + @Override public int encode(OutputStream reverseOS) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); return code.length; } @@ -52,27 +51,28 @@ public class ObjectClass implements BerType, Serializable { throw new IOException("Error encoding CHOICE: No element of CHOICE was selected."); } + @Override public int decode(InputStream is) throws IOException { return decode(is, null); } public int decode(InputStream is, BerTag berTag) throws IOException { - int codeLength = 0; - BerTag passedTag = berTag; + int tlvByteCount = 0; + boolean tagWasPassed = (berTag != null); if (berTag == null) { berTag = new BerTag(); - codeLength += berTag.decode(is); + tlvByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) { basicObjectClass = new BerInteger(); - codeLength += basicObjectClass.decode(is, false); - return codeLength; + tlvByteCount += basicObjectClass.decode(is, false); + return tlvByteCount; } - if (passedTag != null) { + if (tagWasPassed) { return 0; } @@ -85,6 +85,7 @@ public class ObjectClass implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/ObjectName.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/ObjectName.java index f9f1ee7..3ab0888 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/ObjectName.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/ObjectName.java @@ -1,10 +1,10 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; -import com.beanit.jasn1.ber.BerLength; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerType; +import com.beanit.asn1bean.ber.BerLength; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerType; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -14,11 +14,10 @@ public class ObjectName implements BerType, Serializable { private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private Identifier vmdSpecific = null; private DomainSpecific domainSpecific = null; private Identifier aaSpecific = null; - public ObjectName() {} public ObjectName(byte[] code) { @@ -49,12 +48,11 @@ public class ObjectName implements BerType, Serializable { this.aaSpecific = aaSpecific; } + @Override public int encode(OutputStream reverseOS) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); return code.length; } @@ -86,39 +84,40 @@ public class ObjectName implements BerType, Serializable { throw new IOException("Error encoding CHOICE: No element of CHOICE was selected."); } + @Override public int decode(InputStream is) throws IOException { return decode(is, null); } public int decode(InputStream is, BerTag berTag) throws IOException { - int codeLength = 0; - BerTag passedTag = berTag; + int tlvByteCount = 0; + boolean tagWasPassed = (berTag != null); if (berTag == null) { berTag = new BerTag(); - codeLength += berTag.decode(is); + tlvByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) { vmdSpecific = new Identifier(); - codeLength += vmdSpecific.decode(is, false); - return codeLength; + tlvByteCount += vmdSpecific.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) { domainSpecific = new DomainSpecific(); - codeLength += domainSpecific.decode(is, false); - return codeLength; + tlvByteCount += domainSpecific.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 2)) { aaSpecific = new Identifier(); - codeLength += aaSpecific.decode(is, false); - return codeLength; + tlvByteCount += aaSpecific.decode(is, false); + return tlvByteCount; } - if (passedTag != null) { + if (tagWasPassed) { return 0; } @@ -131,6 +130,7 @@ public class ObjectName implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); @@ -162,7 +162,7 @@ public class ObjectName implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private Identifier domainID = null; private Identifier itemID = null; @@ -188,6 +188,7 @@ public class ObjectName implements BerType, Serializable { this.itemID = itemID; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -195,9 +196,7 @@ public class ObjectName implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -218,46 +217,57 @@ public class ObjectName implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); - - int totalLength = length.val; - codeLength += totalLength; + tlByteCount += length.decode(is); + int lengthVal = length.val; + vByteCount += berTag.decode(is); - subCodeLength += berTag.decode(is); if (berTag.equals(Identifier.tag)) { domainID = new Identifier(); - subCodeLength += domainID.decode(is, false); - subCodeLength += berTag.decode(is); + vByteCount += domainID.decode(is, false); + vByteCount += berTag.decode(is); } else { - throw new IOException("Tag does not match the mandatory sequence element tag."); + throw new IOException("Tag does not match mandatory sequence component."); } if (berTag.equals(Identifier.tag)) { itemID = new Identifier(); - subCodeLength += itemID.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += itemID.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } + vByteCount += berTag.decode(is); + } else { + throw new IOException("Tag does not match mandatory sequence component."); } + + if (lengthVal < 0) { + if (!berTag.equals(0, 0, 0)) { + throw new IOException("Decoded sequence has wrong end of contents octets"); + } + vByteCount += BerLength.readEocByte(is); + return tlByteCount + vByteCount; + } + throw new IOException( "Unexpected end of sequence, length tag: " - + totalLength - + ", actual sequence length: " - + subCodeLength); + + lengthVal + + ", bytes decoded: " + + vByteCount); } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -266,6 +276,7 @@ public class ObjectName implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/ParameterSupportOptions.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/ParameterSupportOptions.java index de8ffa4..8d99862 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/ParameterSupportOptions.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/ParameterSupportOptions.java @@ -1,7 +1,7 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; -import com.beanit.jasn1.ber.types.BerBitString; +import com.beanit.asn1bean.ber.types.BerBitString; public class ParameterSupportOptions extends BerBitString { diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/ReadRequest.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/ReadRequest.java index 1ed6738..eef0f20 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/ReadRequest.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/ReadRequest.java @@ -1,10 +1,10 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; -import com.beanit.jasn1.ber.BerLength; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerType; +import com.beanit.asn1bean.ber.BerLength; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerType; import com.beanit.openiec61850.internal.BerBoolean; import java.io.IOException; import java.io.InputStream; @@ -15,7 +15,7 @@ public class ReadRequest implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private BerBoolean specificationWithResult = null; private VariableAccessSpecification variableAccessSpecification = null; @@ -42,6 +42,7 @@ public class ReadRequest implements BerType, Serializable { this.variableAccessSpecification = variableAccessSpecification; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -49,9 +50,7 @@ public class ReadRequest implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -84,45 +83,54 @@ public class ReadRequest implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); + tlByteCount += length.decode(is); + int lengthVal = length.val; + vByteCount += berTag.decode(is); - int totalLength = length.val; - codeLength += totalLength; - - subCodeLength += berTag.decode(is); if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) { specificationWithResult = new BerBoolean(); - subCodeLength += specificationWithResult.decode(is, false); - subCodeLength += berTag.decode(is); + vByteCount += specificationWithResult.decode(is, false); + vByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) { - subCodeLength += length.decode(is); + vByteCount += length.decode(is); variableAccessSpecification = new VariableAccessSpecification(); - subCodeLength += variableAccessSpecification.decode(is, null); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += variableAccessSpecification.decode(is, null); + vByteCount += length.readEocIfIndefinite(is); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; + } + vByteCount += berTag.decode(is); + } else { + throw new IOException("Tag does not match mandatory sequence component."); + } + + if (lengthVal < 0) { + if (!berTag.equals(0, 0, 0)) { + throw new IOException("Decoded sequence has wrong end of contents octets"); } + vByteCount += BerLength.readEocByte(is); + return tlByteCount + vByteCount; } + throw new IOException( - "Unexpected end of sequence, length tag: " - + totalLength - + ", actual sequence length: " - + subCodeLength); + "Unexpected end of sequence, length tag: " + lengthVal + ", bytes decoded: " + vByteCount); } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -131,6 +139,7 @@ public class ReadRequest implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/ReadResponse.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/ReadResponse.java index d698f5a..3f1b7a3 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/ReadResponse.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/ReadResponse.java @@ -1,10 +1,10 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; -import com.beanit.jasn1.ber.BerLength; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerType; +import com.beanit.asn1bean.ber.BerLength; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerType; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -17,10 +17,9 @@ public class ReadResponse implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private VariableAccessSpecification variableAccessSpecification = null; private ListOfAccessResult listOfAccessResult = null; - public ReadResponse() {} public ReadResponse(byte[] code) { @@ -44,6 +43,7 @@ public class ReadResponse implements BerType, Serializable { this.listOfAccessResult = listOfAccessResult; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -51,9 +51,7 @@ public class ReadResponse implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -86,45 +84,54 @@ public class ReadResponse implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); + tlByteCount += length.decode(is); + int lengthVal = length.val; + vByteCount += berTag.decode(is); - int totalLength = length.val; - codeLength += totalLength; - - subCodeLength += berTag.decode(is); if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) { - subCodeLength += length.decode(is); + vByteCount += length.decode(is); variableAccessSpecification = new VariableAccessSpecification(); - subCodeLength += variableAccessSpecification.decode(is, null); - subCodeLength += berTag.decode(is); + vByteCount += variableAccessSpecification.decode(is, null); + vByteCount += length.readEocIfIndefinite(is); + vByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) { listOfAccessResult = new ListOfAccessResult(); - subCodeLength += listOfAccessResult.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += listOfAccessResult.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } + vByteCount += berTag.decode(is); + } else { + throw new IOException("Tag does not match mandatory sequence component."); } + + if (lengthVal < 0) { + if (!berTag.equals(0, 0, 0)) { + throw new IOException("Decoded sequence has wrong end of contents octets"); + } + vByteCount += BerLength.readEocByte(is); + return tlByteCount + vByteCount; + } + throw new IOException( - "Unexpected end of sequence, length tag: " - + totalLength - + ", actual sequence length: " - + subCodeLength); + "Unexpected end of sequence, length tag: " + lengthVal + ", bytes decoded: " + vByteCount); } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -133,6 +140,7 @@ public class ReadResponse implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); @@ -177,7 +185,7 @@ public class ReadResponse implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private List seqOf = null; public ListOfAccessResult() { @@ -195,6 +203,7 @@ public class ReadResponse implements BerType, Serializable { return seqOf; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -202,9 +211,7 @@ public class ReadResponse implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -225,36 +232,48 @@ public class ReadResponse implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; + int numDecodedBytes; + BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); - int totalLength = length.val; + tlByteCount += length.decode(is); + int lengthVal = length.val; + + while (vByteCount < lengthVal || lengthVal < 0) { + vByteCount += berTag.decode(is); + + if (lengthVal < 0 && berTag.equals(0, 0, 0)) { + vByteCount += BerLength.readEocByte(is); + break; + } - while (subCodeLength < totalLength) { AccessResult element = new AccessResult(); - subCodeLength += element.decode(is, null); + numDecodedBytes = element.decode(is, berTag); + if (numDecodedBytes == 0) { + throw new IOException("Tag did not match"); + } + vByteCount += numDecodedBytes; seqOf.add(element); } - if (subCodeLength != totalLength) { + if (lengthVal >= 0 && vByteCount != lengthVal) { throw new IOException( "Decoded SequenceOf or SetOf has wrong length. Expected " - + totalLength + + lengthVal + " but has " - + subCodeLength); + + vByteCount); } - codeLength += subCodeLength; - - return codeLength; + return tlByteCount + vByteCount; } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -263,6 +282,7 @@ public class ReadResponse implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/RejectPDU.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/RejectPDU.java index 0a636ec..599e9c8 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/RejectPDU.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/RejectPDU.java @@ -1,11 +1,11 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; -import com.beanit.jasn1.ber.BerLength; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerInteger; -import com.beanit.jasn1.ber.types.BerType; +import com.beanit.asn1bean.ber.BerLength; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerInteger; +import com.beanit.asn1bean.ber.types.BerType; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -15,10 +15,9 @@ public class RejectPDU implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private Unsigned32 originalInvokeID = null; private RejectReason rejectReason = null; - public RejectPDU() {} public RejectPDU(byte[] code) { @@ -41,6 +40,7 @@ public class RejectPDU implements BerType, Serializable { this.rejectReason = rejectReason; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -48,9 +48,7 @@ public class RejectPDU implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -76,42 +74,53 @@ public class RejectPDU implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; + int numDecodedBytes; BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); + tlByteCount += length.decode(is); + int lengthVal = length.val; + vByteCount += berTag.decode(is); - int totalLength = length.val; - codeLength += totalLength; - - subCodeLength += berTag.decode(is); if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) { originalInvokeID = new Unsigned32(); - subCodeLength += originalInvokeID.decode(is, false); - subCodeLength += berTag.decode(is); + vByteCount += originalInvokeID.decode(is, false); + vByteCount += berTag.decode(is); } rejectReason = new RejectReason(); - subCodeLength += rejectReason.decode(is, berTag); - if (subCodeLength == totalLength) { - return codeLength; + numDecodedBytes = rejectReason.decode(is, berTag); + if (numDecodedBytes != 0) { + vByteCount += numDecodedBytes; + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; + } + vByteCount += berTag.decode(is); + } else { + throw new IOException("Tag does not match mandatory sequence component."); } + if (lengthVal < 0) { + if (!berTag.equals(0, 0, 0)) { + throw new IOException("Decoded sequence has wrong end of contents octets"); + } + vByteCount += BerLength.readEocByte(is); + return tlByteCount + vByteCount; + } + throw new IOException( - "Unexpected end of sequence, length tag: " - + totalLength - + ", actual sequence length: " - + subCodeLength); + "Unexpected end of sequence, length tag: " + lengthVal + ", bytes decoded: " + vByteCount); } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -120,6 +129,7 @@ public class RejectPDU implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); @@ -163,7 +173,7 @@ public class RejectPDU implements BerType, Serializable { private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private BerInteger confirmedRequestPDU = null; private BerInteger confirmedResponsePDU = null; private BerInteger confirmedErrorPDU = null; @@ -270,12 +280,11 @@ public class RejectPDU implements BerType, Serializable { this.concludeErrorPDU = concludeErrorPDU; } + @Override public int encode(OutputStream reverseOS) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); return code.length; } @@ -371,87 +380,88 @@ public class RejectPDU implements BerType, Serializable { throw new IOException("Error encoding CHOICE: No element of CHOICE was selected."); } + @Override public int decode(InputStream is) throws IOException { return decode(is, null); } public int decode(InputStream is, BerTag berTag) throws IOException { - int codeLength = 0; - BerTag passedTag = berTag; + int tlvByteCount = 0; + boolean tagWasPassed = (berTag != null); if (berTag == null) { berTag = new BerTag(); - codeLength += berTag.decode(is); + tlvByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) { confirmedRequestPDU = new BerInteger(); - codeLength += confirmedRequestPDU.decode(is, false); - return codeLength; + tlvByteCount += confirmedRequestPDU.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 2)) { confirmedResponsePDU = new BerInteger(); - codeLength += confirmedResponsePDU.decode(is, false); - return codeLength; + tlvByteCount += confirmedResponsePDU.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 3)) { confirmedErrorPDU = new BerInteger(); - codeLength += confirmedErrorPDU.decode(is, false); - return codeLength; + tlvByteCount += confirmedErrorPDU.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 4)) { unconfirmedPDU = new BerInteger(); - codeLength += unconfirmedPDU.decode(is, false); - return codeLength; + tlvByteCount += unconfirmedPDU.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 5)) { pduError = new BerInteger(); - codeLength += pduError.decode(is, false); - return codeLength; + tlvByteCount += pduError.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 6)) { cancelRequestPDU = new BerInteger(); - codeLength += cancelRequestPDU.decode(is, false); - return codeLength; + tlvByteCount += cancelRequestPDU.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 7)) { cancelResponsePDU = new BerInteger(); - codeLength += cancelResponsePDU.decode(is, false); - return codeLength; + tlvByteCount += cancelResponsePDU.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 8)) { cancelErrorPDU = new BerInteger(); - codeLength += cancelErrorPDU.decode(is, false); - return codeLength; + tlvByteCount += cancelErrorPDU.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 9)) { concludeRequestPDU = new BerInteger(); - codeLength += concludeRequestPDU.decode(is, false); - return codeLength; + tlvByteCount += concludeRequestPDU.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 10)) { concludeResponsePDU = new BerInteger(); - codeLength += concludeResponsePDU.decode(is, false); - return codeLength; + tlvByteCount += concludeResponsePDU.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 11)) { concludeErrorPDU = new BerInteger(); - codeLength += concludeErrorPDU.decode(is, false); - return codeLength; + tlvByteCount += concludeErrorPDU.decode(is, false); + return tlvByteCount; } - if (passedTag != null) { + if (tagWasPassed) { return 0; } @@ -464,6 +474,7 @@ public class RejectPDU implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/ServiceError.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/ServiceError.java index 4ba70b3..e2da85c 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/ServiceError.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/ServiceError.java @@ -1,12 +1,12 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; -import com.beanit.jasn1.ber.BerLength; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerInteger; -import com.beanit.jasn1.ber.types.BerType; -import com.beanit.jasn1.ber.types.string.BerVisibleString; +import com.beanit.asn1bean.ber.BerLength; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerInteger; +import com.beanit.asn1bean.ber.types.BerType; +import com.beanit.asn1bean.ber.types.string.BerVisibleString; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -16,11 +16,10 @@ public class ServiceError implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private ErrorClass errorClass = null; private BerInteger additionalCode = null; private BerVisibleString additionalDescription = null; - public ServiceError() {} public ServiceError(byte[] code) { @@ -51,6 +50,7 @@ public class ServiceError implements BerType, Serializable { this.additionalDescription = additionalDescription; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -58,9 +58,7 @@ public class ServiceError implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -100,59 +98,66 @@ public class ServiceError implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); - - int totalLength = length.val; - codeLength += totalLength; + tlByteCount += length.decode(is); + int lengthVal = length.val; + vByteCount += berTag.decode(is); - subCodeLength += berTag.decode(is); if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) { - subCodeLength += length.decode(is); + vByteCount += length.decode(is); errorClass = new ErrorClass(); - subCodeLength += errorClass.decode(is, null); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += errorClass.decode(is, null); + vByteCount += length.readEocIfIndefinite(is); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } - subCodeLength += berTag.decode(is); + vByteCount += berTag.decode(is); } else { - throw new IOException("Tag does not match the mandatory sequence element tag."); + throw new IOException("Tag does not match mandatory sequence component."); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) { additionalCode = new BerInteger(); - subCodeLength += additionalCode.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += additionalCode.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } - subCodeLength += berTag.decode(is); + vByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 2)) { additionalDescription = new BerVisibleString(); - subCodeLength += additionalDescription.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += additionalDescription.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } + vByteCount += berTag.decode(is); } + + if (lengthVal < 0) { + if (!berTag.equals(0, 0, 0)) { + throw new IOException("Decoded sequence has wrong end of contents octets"); + } + vByteCount += BerLength.readEocByte(is); + return tlByteCount + vByteCount; + } + throw new IOException( - "Unexpected end of sequence, length tag: " - + totalLength - + ", actual sequence length: " - + subCodeLength); + "Unexpected end of sequence, length tag: " + lengthVal + ", bytes decoded: " + vByteCount); } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -161,6 +166,7 @@ public class ServiceError implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); @@ -208,7 +214,7 @@ public class ServiceError implements BerType, Serializable { private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private BerInteger vmdState = null; private BerInteger applicationReference = null; private BerInteger definition = null; @@ -333,12 +339,11 @@ public class ServiceError implements BerType, Serializable { this.others = others; } + @Override public int encode(OutputStream reverseOS) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); return code.length; } @@ -450,99 +455,100 @@ public class ServiceError implements BerType, Serializable { throw new IOException("Error encoding CHOICE: No element of CHOICE was selected."); } + @Override public int decode(InputStream is) throws IOException { return decode(is, null); } public int decode(InputStream is, BerTag berTag) throws IOException { - int codeLength = 0; - BerTag passedTag = berTag; + int tlvByteCount = 0; + boolean tagWasPassed = (berTag != null); if (berTag == null) { berTag = new BerTag(); - codeLength += berTag.decode(is); + tlvByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) { vmdState = new BerInteger(); - codeLength += vmdState.decode(is, false); - return codeLength; + tlvByteCount += vmdState.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) { applicationReference = new BerInteger(); - codeLength += applicationReference.decode(is, false); - return codeLength; + tlvByteCount += applicationReference.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 2)) { definition = new BerInteger(); - codeLength += definition.decode(is, false); - return codeLength; + tlvByteCount += definition.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 3)) { resource = new BerInteger(); - codeLength += resource.decode(is, false); - return codeLength; + tlvByteCount += resource.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 4)) { service = new BerInteger(); - codeLength += service.decode(is, false); - return codeLength; + tlvByteCount += service.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 5)) { servicePreempt = new BerInteger(); - codeLength += servicePreempt.decode(is, false); - return codeLength; + tlvByteCount += servicePreempt.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 6)) { timeResolution = new BerInteger(); - codeLength += timeResolution.decode(is, false); - return codeLength; + tlvByteCount += timeResolution.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 7)) { access = new BerInteger(); - codeLength += access.decode(is, false); - return codeLength; + tlvByteCount += access.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 8)) { initiate = new BerInteger(); - codeLength += initiate.decode(is, false); - return codeLength; + tlvByteCount += initiate.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 9)) { conclude = new BerInteger(); - codeLength += conclude.decode(is, false); - return codeLength; + tlvByteCount += conclude.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 10)) { cancel = new BerInteger(); - codeLength += cancel.decode(is, false); - return codeLength; + tlvByteCount += cancel.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 11)) { file = new BerInteger(); - codeLength += file.decode(is, false); - return codeLength; + tlvByteCount += file.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 12)) { others = new BerInteger(); - codeLength += others.decode(is, false); - return codeLength; + tlvByteCount += others.decode(is, false); + return tlvByteCount; } - if (passedTag != null) { + if (tagWasPassed) { return 0; } @@ -555,6 +561,7 @@ public class ServiceError implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/ServiceSupportOptions.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/ServiceSupportOptions.java index 504364b..b4f6127 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/ServiceSupportOptions.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/ServiceSupportOptions.java @@ -1,7 +1,7 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; -import com.beanit.jasn1.ber.types.BerBitString; +import com.beanit.asn1bean.ber.types.BerBitString; public class ServiceSupportOptions extends BerBitString { diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/TimeOfDay.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/TimeOfDay.java index e1327f3..c874dcf 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/TimeOfDay.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/TimeOfDay.java @@ -1,7 +1,7 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; -import com.beanit.jasn1.ber.types.BerOctetString; +import com.beanit.asn1bean.ber.types.BerOctetString; public class TimeOfDay extends BerOctetString { diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/TypeDescription.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/TypeDescription.java index fb9520f..4edd830 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/TypeDescription.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/TypeDescription.java @@ -1,11 +1,11 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; -import com.beanit.jasn1.ber.BerLength; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerNull; -import com.beanit.jasn1.ber.types.BerType; +import com.beanit.asn1bean.ber.BerLength; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerNull; +import com.beanit.asn1bean.ber.types.BerType; import com.beanit.openiec61850.internal.BerBoolean; import java.io.IOException; import java.io.InputStream; @@ -19,7 +19,7 @@ public class TypeDescription implements BerType, Serializable { private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private Array array = null; private Structure structure = null; private BerNull bool = null; @@ -32,9 +32,7 @@ public class TypeDescription implements BerType, Serializable { private BerBoolean binaryTime = null; private Integer32 mMSString = null; private BerNull utcTime = null; - public TypeDescription() {} - public TypeDescription(byte[] code) { this.code = code; } @@ -135,12 +133,11 @@ public class TypeDescription implements BerType, Serializable { this.utcTime = utcTime; } + @Override public int encode(OutputStream reverseOS) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); return code.length; } @@ -244,93 +241,94 @@ public class TypeDescription implements BerType, Serializable { throw new IOException("Error encoding CHOICE: No element of CHOICE was selected."); } + @Override public int decode(InputStream is) throws IOException { return decode(is, null); } public int decode(InputStream is, BerTag berTag) throws IOException { - int codeLength = 0; - BerTag passedTag = berTag; + int tlvByteCount = 0; + boolean tagWasPassed = (berTag != null); if (berTag == null) { berTag = new BerTag(); - codeLength += berTag.decode(is); + tlvByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) { array = new Array(); - codeLength += array.decode(is, false); - return codeLength; + tlvByteCount += array.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 2)) { structure = new Structure(); - codeLength += structure.decode(is, false); - return codeLength; + tlvByteCount += structure.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 3)) { bool = new BerNull(); - codeLength += bool.decode(is, false); - return codeLength; + tlvByteCount += bool.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 4)) { bitString = new Integer32(); - codeLength += bitString.decode(is, false); - return codeLength; + tlvByteCount += bitString.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 5)) { integer = new Unsigned8(); - codeLength += integer.decode(is, false); - return codeLength; + tlvByteCount += integer.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 6)) { unsigned = new Unsigned8(); - codeLength += unsigned.decode(is, false); - return codeLength; + tlvByteCount += unsigned.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 7)) { floatingPoint = new FloatingPoint(); - codeLength += floatingPoint.decode(is, false); - return codeLength; + tlvByteCount += floatingPoint.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 9)) { octetString = new Integer32(); - codeLength += octetString.decode(is, false); - return codeLength; + tlvByteCount += octetString.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 10)) { visibleString = new Integer32(); - codeLength += visibleString.decode(is, false); - return codeLength; + tlvByteCount += visibleString.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 12)) { binaryTime = new BerBoolean(); - codeLength += binaryTime.decode(is, false); - return codeLength; + tlvByteCount += binaryTime.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 16)) { mMSString = new Integer32(); - codeLength += mMSString.decode(is, false); - return codeLength; + tlvByteCount += mMSString.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 17)) { utcTime = new BerNull(); - codeLength += utcTime.decode(is, false); - return codeLength; + tlvByteCount += utcTime.decode(is, false); + return tlvByteCount; } - if (passedTag != null) { + if (tagWasPassed) { return 0; } @@ -343,6 +341,7 @@ public class TypeDescription implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); @@ -421,7 +420,7 @@ public class TypeDescription implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private BerBoolean packed = null; private Unsigned32 numberOfElements = null; private TypeSpecification elementType = null; @@ -456,6 +455,7 @@ public class TypeDescription implements BerType, Serializable { this.elementType = elementType; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -463,9 +463,7 @@ public class TypeDescription implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -503,53 +501,65 @@ public class TypeDescription implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); + tlByteCount += length.decode(is); + int lengthVal = length.val; + vByteCount += berTag.decode(is); - int totalLength = length.val; - codeLength += totalLength; - - subCodeLength += berTag.decode(is); if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) { packed = new BerBoolean(); - subCodeLength += packed.decode(is, false); - subCodeLength += berTag.decode(is); + vByteCount += packed.decode(is, false); + vByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) { numberOfElements = new Unsigned32(); - subCodeLength += numberOfElements.decode(is, false); - subCodeLength += berTag.decode(is); + vByteCount += numberOfElements.decode(is, false); + vByteCount += berTag.decode(is); } else { - throw new IOException("Tag does not match the mandatory sequence element tag."); + throw new IOException("Tag does not match mandatory sequence component."); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 2)) { - subCodeLength += length.decode(is); + vByteCount += length.decode(is); elementType = new TypeSpecification(); - subCodeLength += elementType.decode(is, null); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += elementType.decode(is, null); + vByteCount += length.readEocIfIndefinite(is); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; + } + vByteCount += berTag.decode(is); + } else { + throw new IOException("Tag does not match mandatory sequence component."); + } + + if (lengthVal < 0) { + if (!berTag.equals(0, 0, 0)) { + throw new IOException("Decoded sequence has wrong end of contents octets"); } + vByteCount += BerLength.readEocByte(is); + return tlByteCount + vByteCount; } + throw new IOException( "Unexpected end of sequence, length tag: " - + totalLength - + ", actual sequence length: " - + subCodeLength); + + lengthVal + + ", bytes decoded: " + + vByteCount); } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -558,6 +568,7 @@ public class TypeDescription implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); @@ -612,10 +623,9 @@ public class TypeDescription implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private BerBoolean packed = null; private Components components = null; - public Structure() {} public Structure(byte[] code) { @@ -638,6 +648,7 @@ public class TypeDescription implements BerType, Serializable { this.components = components; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -645,9 +656,7 @@ public class TypeDescription implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -676,44 +685,55 @@ public class TypeDescription implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); + tlByteCount += length.decode(is); + int lengthVal = length.val; + vByteCount += berTag.decode(is); - int totalLength = length.val; - codeLength += totalLength; - - subCodeLength += berTag.decode(is); if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) { packed = new BerBoolean(); - subCodeLength += packed.decode(is, false); - subCodeLength += berTag.decode(is); + vByteCount += packed.decode(is, false); + vByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) { components = new Components(); - subCodeLength += components.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += components.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } + vByteCount += berTag.decode(is); + } else { + throw new IOException("Tag does not match mandatory sequence component."); } + + if (lengthVal < 0) { + if (!berTag.equals(0, 0, 0)) { + throw new IOException("Decoded sequence has wrong end of contents octets"); + } + vByteCount += BerLength.readEocByte(is); + return tlByteCount + vByteCount; + } + throw new IOException( "Unexpected end of sequence, length tag: " - + totalLength - + ", actual sequence length: " - + subCodeLength); + + lengthVal + + ", bytes decoded: " + + vByteCount); } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -722,6 +742,7 @@ public class TypeDescription implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); @@ -765,9 +786,8 @@ public class TypeDescription implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private List seqOf = null; - public Components() { seqOf = new ArrayList(); } @@ -783,6 +803,7 @@ public class TypeDescription implements BerType, Serializable { return seqOf; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -790,9 +811,7 @@ public class TypeDescription implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -813,36 +832,46 @@ public class TypeDescription implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; + BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); - int totalLength = length.val; + tlByteCount += length.decode(is); + int lengthVal = length.val; + + while (vByteCount < lengthVal || lengthVal < 0) { + vByteCount += berTag.decode(is); - while (subCodeLength < totalLength) { + if (lengthVal < 0 && berTag.equals(0, 0, 0)) { + vByteCount += BerLength.readEocByte(is); + break; + } + + if (!berTag.equals(SEQUENCE.tag)) { + throw new IOException("Tag does not match mandatory sequence of/set of component."); + } SEQUENCE element = new SEQUENCE(); - subCodeLength += element.decode(is, true); + vByteCount += element.decode(is, false); seqOf.add(element); } - if (subCodeLength != totalLength) { + if (lengthVal >= 0 && vByteCount != lengthVal) { throw new IOException( "Decoded SequenceOf or SetOf has wrong length. Expected " - + totalLength + + lengthVal + " but has " - + subCodeLength); + + vByteCount); } - codeLength += subCodeLength; - - return codeLength; + return tlByteCount + vByteCount; } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -852,6 +881,7 @@ public class TypeDescription implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); @@ -891,7 +921,7 @@ public class TypeDescription implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private Identifier componentName = null; private TypeSpecification componentType = null; @@ -917,6 +947,7 @@ public class TypeDescription implements BerType, Serializable { this.componentType = componentType; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -924,9 +955,7 @@ public class TypeDescription implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -959,45 +988,57 @@ public class TypeDescription implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); + tlByteCount += length.decode(is); + int lengthVal = length.val; + vByteCount += berTag.decode(is); - int totalLength = length.val; - codeLength += totalLength; - - subCodeLength += berTag.decode(is); if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) { componentName = new Identifier(); - subCodeLength += componentName.decode(is, false); - subCodeLength += berTag.decode(is); + vByteCount += componentName.decode(is, false); + vByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) { - subCodeLength += length.decode(is); + vByteCount += length.decode(is); componentType = new TypeSpecification(); - subCodeLength += componentType.decode(is, null); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += componentType.decode(is, null); + vByteCount += length.readEocIfIndefinite(is); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; + } + vByteCount += berTag.decode(is); + } else { + throw new IOException("Tag does not match mandatory sequence component."); + } + + if (lengthVal < 0) { + if (!berTag.equals(0, 0, 0)) { + throw new IOException("Decoded sequence has wrong end of contents octets"); } + vByteCount += BerLength.readEocByte(is); + return tlByteCount + vByteCount; } + throw new IOException( "Unexpected end of sequence, length tag: " - + totalLength - + ", actual sequence length: " - + subCodeLength); + + lengthVal + + ", bytes decoded: " + + vByteCount); } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -1007,6 +1048,7 @@ public class TypeDescription implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); @@ -1053,7 +1095,7 @@ public class TypeDescription implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private Unsigned8 formatWidth = null; private Unsigned8 exponentWidth = null; @@ -1079,6 +1121,7 @@ public class TypeDescription implements BerType, Serializable { this.exponentWidth = exponentWidth; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -1086,9 +1129,7 @@ public class TypeDescription implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -1109,46 +1150,57 @@ public class TypeDescription implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); + tlByteCount += length.decode(is); + int lengthVal = length.val; + vByteCount += berTag.decode(is); - int totalLength = length.val; - codeLength += totalLength; - - subCodeLength += berTag.decode(is); if (berTag.equals(Unsigned8.tag)) { formatWidth = new Unsigned8(); - subCodeLength += formatWidth.decode(is, false); - subCodeLength += berTag.decode(is); + vByteCount += formatWidth.decode(is, false); + vByteCount += berTag.decode(is); } else { - throw new IOException("Tag does not match the mandatory sequence element tag."); + throw new IOException("Tag does not match mandatory sequence component."); } if (berTag.equals(Unsigned8.tag)) { exponentWidth = new Unsigned8(); - subCodeLength += exponentWidth.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += exponentWidth.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } + vByteCount += berTag.decode(is); + } else { + throw new IOException("Tag does not match mandatory sequence component."); } + + if (lengthVal < 0) { + if (!berTag.equals(0, 0, 0)) { + throw new IOException("Decoded sequence has wrong end of contents octets"); + } + vByteCount += BerLength.readEocByte(is); + return tlByteCount + vByteCount; + } + throw new IOException( "Unexpected end of sequence, length tag: " - + totalLength - + ", actual sequence length: " - + subCodeLength); + + lengthVal + + ", bytes decoded: " + + vByteCount); } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -1157,6 +1209,7 @@ public class TypeDescription implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/TypeSpecification.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/TypeSpecification.java index e980dfb..7a0dd69 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/TypeSpecification.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/TypeSpecification.java @@ -1,9 +1,9 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerType; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerType; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -13,7 +13,7 @@ public class TypeSpecification implements BerType, Serializable { private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private TypeDescription typeDescription = null; public TypeSpecification() {} @@ -30,12 +30,11 @@ public class TypeSpecification implements BerType, Serializable { this.typeDescription = typeDescription; } + @Override public int encode(OutputStream reverseOS) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); return code.length; } @@ -48,29 +47,32 @@ public class TypeSpecification implements BerType, Serializable { throw new IOException("Error encoding CHOICE: No element of CHOICE was selected."); } + @Override public int decode(InputStream is) throws IOException { return decode(is, null); } public int decode(InputStream is, BerTag berTag) throws IOException { - int codeLength = 0; - BerTag passedTag = berTag; + int tlvByteCount = 0; + boolean tagWasPassed = (berTag != null); if (berTag == null) { berTag = new BerTag(); - codeLength += berTag.decode(is); + tlvByteCount += berTag.decode(is); } + int numDecodedBytes; + typeDescription = new TypeDescription(); - int choiceDecodeLength = typeDescription.decode(is, berTag); - if (choiceDecodeLength != 0) { - return codeLength + choiceDecodeLength; + numDecodedBytes = typeDescription.decode(is, berTag); + if (numDecodedBytes != 0) { + return tlvByteCount + numDecodedBytes; } else { typeDescription = null; } - if (passedTag != null) { + if (tagWasPassed) { return 0; } @@ -83,6 +85,7 @@ public class TypeSpecification implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/UnconfirmedPDU.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/UnconfirmedPDU.java index 0eeb619..eb38a22 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/UnconfirmedPDU.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/UnconfirmedPDU.java @@ -1,10 +1,10 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; -import com.beanit.jasn1.ber.BerLength; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerType; +import com.beanit.asn1bean.ber.BerLength; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerType; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -14,7 +14,7 @@ public class UnconfirmedPDU implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private UnconfirmedService service = null; public UnconfirmedPDU() {} @@ -31,6 +31,7 @@ public class UnconfirmedPDU implements BerType, Serializable { this.service = service; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -38,9 +39,7 @@ public class UnconfirmedPDU implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -59,36 +58,47 @@ public class UnconfirmedPDU implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; + int numDecodedBytes; BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); + tlByteCount += length.decode(is); + int lengthVal = length.val; + vByteCount += berTag.decode(is); - int totalLength = length.val; - codeLength += totalLength; - - subCodeLength += berTag.decode(is); service = new UnconfirmedService(); - subCodeLength += service.decode(is, berTag); - if (subCodeLength == totalLength) { - return codeLength; + numDecodedBytes = service.decode(is, berTag); + if (numDecodedBytes != 0) { + vByteCount += numDecodedBytes; + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; + } + vByteCount += berTag.decode(is); + } else { + throw new IOException("Tag does not match mandatory sequence component."); + } + if (lengthVal < 0) { + if (!berTag.equals(0, 0, 0)) { + throw new IOException("Decoded sequence has wrong end of contents octets"); + } + vByteCount += BerLength.readEocByte(is); + return tlByteCount + vByteCount; } + throw new IOException( - "Unexpected end of sequence, length tag: " - + totalLength - + ", actual sequence length: " - + subCodeLength); + "Unexpected end of sequence, length tag: " + lengthVal + ", bytes decoded: " + vByteCount); } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -97,6 +107,7 @@ public class UnconfirmedPDU implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/UnconfirmedService.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/UnconfirmedService.java index bac3198..5031a96 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/UnconfirmedService.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/UnconfirmedService.java @@ -1,9 +1,9 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerType; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerType; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -13,7 +13,7 @@ public class UnconfirmedService implements BerType, Serializable { private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private InformationReport informationReport = null; public UnconfirmedService() {} @@ -30,12 +30,11 @@ public class UnconfirmedService implements BerType, Serializable { this.informationReport = informationReport; } + @Override public int encode(OutputStream reverseOS) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); return code.length; } @@ -51,27 +50,28 @@ public class UnconfirmedService implements BerType, Serializable { throw new IOException("Error encoding CHOICE: No element of CHOICE was selected."); } + @Override public int decode(InputStream is) throws IOException { return decode(is, null); } public int decode(InputStream is, BerTag berTag) throws IOException { - int codeLength = 0; - BerTag passedTag = berTag; + int tlvByteCount = 0; + boolean tagWasPassed = (berTag != null); if (berTag == null) { berTag = new BerTag(); - codeLength += berTag.decode(is); + tlvByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) { informationReport = new InformationReport(); - codeLength += informationReport.decode(is, false); - return codeLength; + tlvByteCount += informationReport.decode(is, false); + return tlvByteCount; } - if (passedTag != null) { + if (tagWasPassed) { return 0; } @@ -84,6 +84,7 @@ public class UnconfirmedService implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/Unsigned16.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/Unsigned16.java index a9df134..c076c09 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/Unsigned16.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/Unsigned16.java @@ -1,7 +1,7 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; -import com.beanit.jasn1.ber.types.BerInteger; +import com.beanit.asn1bean.ber.types.BerInteger; import java.math.BigInteger; public class Unsigned16 extends BerInteger { diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/Unsigned32.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/Unsigned32.java index 9ceafb9..fdc7e25 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/Unsigned32.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/Unsigned32.java @@ -1,7 +1,7 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; -import com.beanit.jasn1.ber.types.BerInteger; +import com.beanit.asn1bean.ber.types.BerInteger; import java.math.BigInteger; public class Unsigned32 extends BerInteger { diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/Unsigned8.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/Unsigned8.java index 2bc35c4..ada1d5f 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/Unsigned8.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/Unsigned8.java @@ -1,7 +1,7 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; -import com.beanit.jasn1.ber.types.BerInteger; +import com.beanit.asn1bean.ber.types.BerInteger; import java.math.BigInteger; public class Unsigned8 extends BerInteger { diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/UtcTime.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/UtcTime.java index b572e3e..3db9860 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/UtcTime.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/UtcTime.java @@ -1,7 +1,7 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; -import com.beanit.jasn1.ber.types.BerOctetString; +import com.beanit.asn1bean.ber.types.BerOctetString; public class UtcTime extends BerOctetString { diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/VariableAccessSpecification.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/VariableAccessSpecification.java index 52e0802..ecb4d37 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/VariableAccessSpecification.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/VariableAccessSpecification.java @@ -1,10 +1,10 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; -import com.beanit.jasn1.ber.BerLength; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerType; +import com.beanit.asn1bean.ber.BerLength; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerType; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -14,7 +14,7 @@ public class VariableAccessSpecification implements BerType, Serializable { private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private VariableDefs listOfVariable = null; private ObjectName variableListName = null; @@ -40,12 +40,11 @@ public class VariableAccessSpecification implements BerType, Serializable { this.variableListName = variableListName; } + @Override public int encode(OutputStream reverseOS) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); return code.length; } @@ -73,34 +72,37 @@ public class VariableAccessSpecification implements BerType, Serializable { throw new IOException("Error encoding CHOICE: No element of CHOICE was selected."); } + @Override public int decode(InputStream is) throws IOException { return decode(is, null); } public int decode(InputStream is, BerTag berTag) throws IOException { - int codeLength = 0; - BerTag passedTag = berTag; + int tlvByteCount = 0; + boolean tagWasPassed = (berTag != null); if (berTag == null) { berTag = new BerTag(); - codeLength += berTag.decode(is); + tlvByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) { listOfVariable = new VariableDefs(); - codeLength += listOfVariable.decode(is, false); - return codeLength; + tlvByteCount += listOfVariable.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) { - codeLength += BerLength.skip(is); + BerLength explicitTagLength = new BerLength(); + tlvByteCount += explicitTagLength.decode(is); variableListName = new ObjectName(); - codeLength += variableListName.decode(is, null); - return codeLength; + tlvByteCount += variableListName.decode(is, null); + tlvByteCount += explicitTagLength.readEocIfIndefinite(is); + return tlvByteCount; } - if (passedTag != null) { + if (tagWasPassed) { return 0; } @@ -113,6 +115,7 @@ public class VariableAccessSpecification implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/VariableDefs.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/VariableDefs.java index 143330a..0a420b3 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/VariableDefs.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/VariableDefs.java @@ -1,10 +1,10 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; -import com.beanit.jasn1.ber.BerLength; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerType; +import com.beanit.asn1bean.ber.BerLength; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerType; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -17,9 +17,8 @@ public class VariableDefs implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private List seqOf = null; - public VariableDefs() { seqOf = new ArrayList(); } @@ -35,6 +34,7 @@ public class VariableDefs implements BerType, Serializable { return seqOf; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -42,9 +42,7 @@ public class VariableDefs implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -65,36 +63,46 @@ public class VariableDefs implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; + BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); - int totalLength = length.val; + tlByteCount += length.decode(is); + int lengthVal = length.val; + + while (vByteCount < lengthVal || lengthVal < 0) { + vByteCount += berTag.decode(is); + + if (lengthVal < 0 && berTag.equals(0, 0, 0)) { + vByteCount += BerLength.readEocByte(is); + break; + } - while (subCodeLength < totalLength) { + if (!berTag.equals(SEQUENCE.tag)) { + throw new IOException("Tag does not match mandatory sequence of/set of component."); + } SEQUENCE element = new SEQUENCE(); - subCodeLength += element.decode(is, true); + vByteCount += element.decode(is, false); seqOf.add(element); } - if (subCodeLength != totalLength) { + if (lengthVal >= 0 && vByteCount != lengthVal) { throw new IOException( "Decoded SequenceOf or SetOf has wrong length. Expected " - + totalLength + + lengthVal + " but has " - + subCodeLength); + + vByteCount); } - codeLength += subCodeLength; - - return codeLength; + return tlByteCount + vByteCount; } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -103,6 +111,7 @@ public class VariableDefs implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); @@ -142,7 +151,7 @@ public class VariableDefs implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private VariableSpecification variableSpecification = null; private AlternateAccess alternateAccess = null; @@ -168,6 +177,7 @@ public class VariableDefs implements BerType, Serializable { this.alternateAccess = alternateAccess; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -175,9 +185,7 @@ public class VariableDefs implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -203,45 +211,59 @@ public class VariableDefs implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; + int numDecodedBytes; BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); - - int totalLength = length.val; - codeLength += totalLength; + tlByteCount += length.decode(is); + int lengthVal = length.val; + vByteCount += berTag.decode(is); - subCodeLength += berTag.decode(is); variableSpecification = new VariableSpecification(); - subCodeLength += variableSpecification.decode(is, berTag); - if (subCodeLength == totalLength) { - return codeLength; + numDecodedBytes = variableSpecification.decode(is, berTag); + if (numDecodedBytes != 0) { + vByteCount += numDecodedBytes; + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; + } + vByteCount += berTag.decode(is); + } else { + throw new IOException("Tag does not match mandatory sequence component."); } - subCodeLength += berTag.decode(is); - if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 5)) { alternateAccess = new AlternateAccess(); - subCodeLength += alternateAccess.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += alternateAccess.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; } + vByteCount += berTag.decode(is); } + + if (lengthVal < 0) { + if (!berTag.equals(0, 0, 0)) { + throw new IOException("Decoded sequence has wrong end of contents octets"); + } + vByteCount += BerLength.readEocByte(is); + return tlByteCount + vByteCount; + } + throw new IOException( "Unexpected end of sequence, length tag: " - + totalLength - + ", actual sequence length: " - + subCodeLength); + + lengthVal + + ", bytes decoded: " + + vByteCount); } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -250,6 +272,7 @@ public class VariableDefs implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/VariableSpecification.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/VariableSpecification.java index 74d03bb..54d93a6 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/VariableSpecification.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/VariableSpecification.java @@ -1,10 +1,10 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; -import com.beanit.jasn1.ber.BerLength; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerType; +import com.beanit.asn1bean.ber.BerLength; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerType; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -14,7 +14,7 @@ public class VariableSpecification implements BerType, Serializable { private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private ObjectName name = null; public VariableSpecification() {} @@ -31,12 +31,11 @@ public class VariableSpecification implements BerType, Serializable { this.name = name; } + @Override public int encode(OutputStream reverseOS) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); return code.length; } @@ -56,28 +55,31 @@ public class VariableSpecification implements BerType, Serializable { throw new IOException("Error encoding CHOICE: No element of CHOICE was selected."); } + @Override public int decode(InputStream is) throws IOException { return decode(is, null); } public int decode(InputStream is, BerTag berTag) throws IOException { - int codeLength = 0; - BerTag passedTag = berTag; + int tlvByteCount = 0; + boolean tagWasPassed = (berTag != null); if (berTag == null) { berTag = new BerTag(); - codeLength += berTag.decode(is); + tlvByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) { - codeLength += BerLength.skip(is); + BerLength explicitTagLength = new BerLength(); + tlvByteCount += explicitTagLength.decode(is); name = new ObjectName(); - codeLength += name.decode(is, null); - return codeLength; + tlvByteCount += name.decode(is, null); + tlvByteCount += explicitTagLength.readEocIfIndefinite(is); + return tlvByteCount; } - if (passedTag != null) { + if (tagWasPassed) { return 0; } @@ -90,6 +92,7 @@ public class VariableSpecification implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/WriteRequest.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/WriteRequest.java index 69ddf10..e2e2db8 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/WriteRequest.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/WriteRequest.java @@ -1,10 +1,10 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; -import com.beanit.jasn1.ber.BerLength; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerType; +import com.beanit.asn1bean.ber.BerLength; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerType; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -17,10 +17,9 @@ public class WriteRequest implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private VariableAccessSpecification variableAccessSpecification = null; private ListOfData listOfData = null; - public WriteRequest() {} public WriteRequest(byte[] code) { @@ -44,6 +43,7 @@ public class WriteRequest implements BerType, Serializable { this.listOfData = listOfData; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -51,9 +51,7 @@ public class WriteRequest implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -77,42 +75,55 @@ public class WriteRequest implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; + int numDecodedBytes; BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); + tlByteCount += length.decode(is); + int lengthVal = length.val; + vByteCount += berTag.decode(is); - int totalLength = length.val; - codeLength += totalLength; - - subCodeLength += berTag.decode(is); variableAccessSpecification = new VariableAccessSpecification(); - subCodeLength += variableAccessSpecification.decode(is, berTag); - subCodeLength += berTag.decode(is); - + numDecodedBytes = variableAccessSpecification.decode(is, berTag); + if (numDecodedBytes != 0) { + vByteCount += numDecodedBytes; + vByteCount += berTag.decode(is); + } else { + throw new IOException("Tag does not match mandatory sequence component."); + } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) { listOfData = new ListOfData(); - subCodeLength += listOfData.decode(is, false); - if (subCodeLength == totalLength) { - return codeLength; + vByteCount += listOfData.decode(is, false); + if (lengthVal >= 0 && vByteCount == lengthVal) { + return tlByteCount + vByteCount; + } + vByteCount += berTag.decode(is); + } else { + throw new IOException("Tag does not match mandatory sequence component."); + } + + if (lengthVal < 0) { + if (!berTag.equals(0, 0, 0)) { + throw new IOException("Decoded sequence has wrong end of contents octets"); } + vByteCount += BerLength.readEocByte(is); + return tlByteCount + vByteCount; } + throw new IOException( - "Unexpected end of sequence, length tag: " - + totalLength - + ", actual sequence length: " - + subCodeLength); + "Unexpected end of sequence, length tag: " + lengthVal + ", bytes decoded: " + vByteCount); } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -121,6 +132,7 @@ public class WriteRequest implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); @@ -163,7 +175,7 @@ public class WriteRequest implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private List seqOf = null; public ListOfData() { @@ -181,6 +193,7 @@ public class WriteRequest implements BerType, Serializable { return seqOf; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -188,9 +201,7 @@ public class WriteRequest implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -211,36 +222,48 @@ public class WriteRequest implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; + int numDecodedBytes; + BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); - int totalLength = length.val; + tlByteCount += length.decode(is); + int lengthVal = length.val; + + while (vByteCount < lengthVal || lengthVal < 0) { + vByteCount += berTag.decode(is); + + if (lengthVal < 0 && berTag.equals(0, 0, 0)) { + vByteCount += BerLength.readEocByte(is); + break; + } - while (subCodeLength < totalLength) { Data element = new Data(); - subCodeLength += element.decode(is, null); + numDecodedBytes = element.decode(is, berTag); + if (numDecodedBytes == 0) { + throw new IOException("Tag did not match"); + } + vByteCount += numDecodedBytes; seqOf.add(element); } - if (subCodeLength != totalLength) { + if (lengthVal >= 0 && vByteCount != lengthVal) { throw new IOException( "Decoded SequenceOf or SetOf has wrong length. Expected " - + totalLength + + lengthVal + " but has " - + subCodeLength); + + vByteCount); } - codeLength += subCodeLength; - - return codeLength; + return tlByteCount + vByteCount; } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -249,6 +272,7 @@ public class WriteRequest implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/WriteResponse.java b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/WriteResponse.java index 82ac720..75f8899 100644 --- a/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/WriteResponse.java +++ b/src/main/java-gen/com/beanit/openiec61850/internal/mms/asn1/WriteResponse.java @@ -1,11 +1,11 @@ -/** This class file was automatically generated by jASN1 (http://www.beanit.com) */ +/** This class file was automatically generated by ASN1bean (http://www.beanit.com) */ package com.beanit.openiec61850.internal.mms.asn1; -import com.beanit.jasn1.ber.BerLength; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerNull; -import com.beanit.jasn1.ber.types.BerType; +import com.beanit.asn1bean.ber.BerLength; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerNull; +import com.beanit.asn1bean.ber.types.BerType; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -18,9 +18,8 @@ public class WriteResponse implements BerType, Serializable { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private List seqOf = null; - public WriteResponse() { seqOf = new ArrayList(); } @@ -36,6 +35,7 @@ public class WriteResponse implements BerType, Serializable { return seqOf; } + @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } @@ -43,9 +43,7 @@ public class WriteResponse implements BerType, Serializable { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -66,36 +64,48 @@ public class WriteResponse implements BerType, Serializable { return codeLength; } + @Override public int decode(InputStream is) throws IOException { return decode(is, true); } public int decode(InputStream is, boolean withTag) throws IOException { - int codeLength = 0; - int subCodeLength = 0; + int tlByteCount = 0; + int vByteCount = 0; + int numDecodedBytes; + BerTag berTag = new BerTag(); if (withTag) { - codeLength += tag.decodeAndCheck(is); + tlByteCount += tag.decodeAndCheck(is); } BerLength length = new BerLength(); - codeLength += length.decode(is); - int totalLength = length.val; + tlByteCount += length.decode(is); + int lengthVal = length.val; + + while (vByteCount < lengthVal || lengthVal < 0) { + vByteCount += berTag.decode(is); + + if (lengthVal < 0 && berTag.equals(0, 0, 0)) { + vByteCount += BerLength.readEocByte(is); + break; + } - while (subCodeLength < totalLength) { CHOICE element = new CHOICE(); - subCodeLength += element.decode(is, null); + numDecodedBytes = element.decode(is, berTag); + if (numDecodedBytes == 0) { + throw new IOException("Tag did not match"); + } + vByteCount += numDecodedBytes; seqOf.add(element); } - if (subCodeLength != totalLength) { + if (lengthVal >= 0 && vByteCount != lengthVal) { throw new IOException( "Decoded SequenceOf or SetOf has wrong length. Expected " - + totalLength + + lengthVal + " but has " - + subCodeLength); + + vByteCount); } - codeLength += subCodeLength; - - return codeLength; + return tlByteCount + vByteCount; } public void encodeAndSave(int encodingSizeGuess) throws IOException { @@ -104,6 +114,7 @@ public class WriteResponse implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); @@ -143,7 +154,7 @@ public class WriteResponse implements BerType, Serializable { private static final long serialVersionUID = 1L; - public byte[] code = null; + private byte[] code = null; private DataAccessError failure = null; private BerNull success = null; @@ -169,12 +180,11 @@ public class WriteResponse implements BerType, Serializable { this.success = success; } + @Override public int encode(OutputStream reverseOS) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); return code.length; } @@ -198,33 +208,34 @@ public class WriteResponse implements BerType, Serializable { throw new IOException("Error encoding CHOICE: No element of CHOICE was selected."); } + @Override public int decode(InputStream is) throws IOException { return decode(is, null); } public int decode(InputStream is, BerTag berTag) throws IOException { - int codeLength = 0; - BerTag passedTag = berTag; + int tlvByteCount = 0; + boolean tagWasPassed = (berTag != null); if (berTag == null) { berTag = new BerTag(); - codeLength += berTag.decode(is); + tlvByteCount += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) { failure = new DataAccessError(); - codeLength += failure.decode(is, false); - return codeLength; + tlvByteCount += failure.decode(is, false); + return tlvByteCount; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) { success = new BerNull(); - codeLength += success.decode(is, false); - return codeLength; + tlvByteCount += success.decode(is, false); + return tlvByteCount; } - if (passedTag != null) { + if (tagWasPassed) { return 0; } @@ -237,6 +248,7 @@ public class WriteResponse implements BerType, Serializable { code = reverseOS.getArray(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); appendAsString(sb, 0); diff --git a/src/main/java/com/beanit/josistack/AcseAssociation.java b/src/main/java/com/beanit/josistack/AcseAssociation.java index bcc07db..d7489b5 100644 --- a/src/main/java/com/beanit/josistack/AcseAssociation.java +++ b/src/main/java/com/beanit/josistack/AcseAssociation.java @@ -13,11 +13,11 @@ */ package com.beanit.josistack; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerAny; -import com.beanit.jasn1.ber.types.BerInteger; -import com.beanit.jasn1.ber.types.BerObjectIdentifier; -import com.beanit.jasn1.ber.types.string.BerGraphicString; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerAny; +import com.beanit.asn1bean.ber.types.BerInteger; +import com.beanit.asn1bean.ber.types.BerObjectIdentifier; +import com.beanit.asn1bean.ber.types.string.BerGraphicString; import com.beanit.josistack.internal.acse.asn1.AAREApdu; import com.beanit.josistack.internal.acse.asn1.AARQApdu; import com.beanit.josistack.internal.acse.asn1.ACSEApdu; diff --git a/src/main/java/com/beanit/openiec61850/BdaBitString.java b/src/main/java/com/beanit/openiec61850/BdaBitString.java index c6b7a0e..4b64b17 100644 --- a/src/main/java/com/beanit/openiec61850/BdaBitString.java +++ b/src/main/java/com/beanit/openiec61850/BdaBitString.java @@ -13,7 +13,7 @@ */ package com.beanit.openiec61850; -import com.beanit.jasn1.ber.types.BerBitString; +import com.beanit.asn1bean.ber.types.BerBitString; import com.beanit.openiec61850.internal.HexString; import com.beanit.openiec61850.internal.mms.asn1.Data; import com.beanit.openiec61850.internal.mms.asn1.Integer32; diff --git a/src/main/java/com/beanit/openiec61850/BdaBoolean.java b/src/main/java/com/beanit/openiec61850/BdaBoolean.java index a9b7788..fafe958 100644 --- a/src/main/java/com/beanit/openiec61850/BdaBoolean.java +++ b/src/main/java/com/beanit/openiec61850/BdaBoolean.java @@ -13,7 +13,7 @@ */ package com.beanit.openiec61850; -import com.beanit.jasn1.ber.types.BerNull; +import com.beanit.asn1bean.ber.types.BerNull; import com.beanit.openiec61850.internal.BerBoolean; import com.beanit.openiec61850.internal.mms.asn1.Data; import com.beanit.openiec61850.internal.mms.asn1.TypeDescription; diff --git a/src/main/java/com/beanit/openiec61850/BdaInt128.java b/src/main/java/com/beanit/openiec61850/BdaInt128.java index 14e4472..1e4ccaf 100644 --- a/src/main/java/com/beanit/openiec61850/BdaInt128.java +++ b/src/main/java/com/beanit/openiec61850/BdaInt128.java @@ -13,7 +13,7 @@ */ package com.beanit.openiec61850; -import com.beanit.jasn1.ber.types.BerInteger; +import com.beanit.asn1bean.ber.types.BerInteger; import com.beanit.openiec61850.internal.mms.asn1.Data; import com.beanit.openiec61850.internal.mms.asn1.TypeDescription; import com.beanit.openiec61850.internal.mms.asn1.Unsigned8; diff --git a/src/main/java/com/beanit/openiec61850/BdaInt16.java b/src/main/java/com/beanit/openiec61850/BdaInt16.java index 1ca3856..db4c7f2 100644 --- a/src/main/java/com/beanit/openiec61850/BdaInt16.java +++ b/src/main/java/com/beanit/openiec61850/BdaInt16.java @@ -13,7 +13,7 @@ */ package com.beanit.openiec61850; -import com.beanit.jasn1.ber.types.BerInteger; +import com.beanit.asn1bean.ber.types.BerInteger; import com.beanit.openiec61850.internal.mms.asn1.Data; import com.beanit.openiec61850.internal.mms.asn1.TypeDescription; import com.beanit.openiec61850.internal.mms.asn1.Unsigned8; diff --git a/src/main/java/com/beanit/openiec61850/BdaInt16U.java b/src/main/java/com/beanit/openiec61850/BdaInt16U.java index 8fc07b6..95b278a 100644 --- a/src/main/java/com/beanit/openiec61850/BdaInt16U.java +++ b/src/main/java/com/beanit/openiec61850/BdaInt16U.java @@ -13,7 +13,7 @@ */ package com.beanit.openiec61850; -import com.beanit.jasn1.ber.types.BerInteger; +import com.beanit.asn1bean.ber.types.BerInteger; import com.beanit.openiec61850.internal.mms.asn1.Data; import com.beanit.openiec61850.internal.mms.asn1.TypeDescription; import com.beanit.openiec61850.internal.mms.asn1.Unsigned8; diff --git a/src/main/java/com/beanit/openiec61850/BdaInt32.java b/src/main/java/com/beanit/openiec61850/BdaInt32.java index 6527f84..79c96d1 100644 --- a/src/main/java/com/beanit/openiec61850/BdaInt32.java +++ b/src/main/java/com/beanit/openiec61850/BdaInt32.java @@ -13,7 +13,7 @@ */ package com.beanit.openiec61850; -import com.beanit.jasn1.ber.types.BerInteger; +import com.beanit.asn1bean.ber.types.BerInteger; import com.beanit.openiec61850.internal.mms.asn1.Data; import com.beanit.openiec61850.internal.mms.asn1.TypeDescription; import com.beanit.openiec61850.internal.mms.asn1.Unsigned8; diff --git a/src/main/java/com/beanit/openiec61850/BdaInt32U.java b/src/main/java/com/beanit/openiec61850/BdaInt32U.java index 22b6e1b..1d90dd3 100644 --- a/src/main/java/com/beanit/openiec61850/BdaInt32U.java +++ b/src/main/java/com/beanit/openiec61850/BdaInt32U.java @@ -13,7 +13,7 @@ */ package com.beanit.openiec61850; -import com.beanit.jasn1.ber.types.BerInteger; +import com.beanit.asn1bean.ber.types.BerInteger; import com.beanit.openiec61850.internal.mms.asn1.Data; import com.beanit.openiec61850.internal.mms.asn1.TypeDescription; import com.beanit.openiec61850.internal.mms.asn1.Unsigned8; diff --git a/src/main/java/com/beanit/openiec61850/BdaInt64.java b/src/main/java/com/beanit/openiec61850/BdaInt64.java index 096472a..b784ac0 100644 --- a/src/main/java/com/beanit/openiec61850/BdaInt64.java +++ b/src/main/java/com/beanit/openiec61850/BdaInt64.java @@ -13,7 +13,7 @@ */ package com.beanit.openiec61850; -import com.beanit.jasn1.ber.types.BerInteger; +import com.beanit.asn1bean.ber.types.BerInteger; import com.beanit.openiec61850.internal.mms.asn1.Data; import com.beanit.openiec61850.internal.mms.asn1.TypeDescription; import com.beanit.openiec61850.internal.mms.asn1.Unsigned8; diff --git a/src/main/java/com/beanit/openiec61850/BdaInt8.java b/src/main/java/com/beanit/openiec61850/BdaInt8.java index a01b2c6..524f21f 100644 --- a/src/main/java/com/beanit/openiec61850/BdaInt8.java +++ b/src/main/java/com/beanit/openiec61850/BdaInt8.java @@ -13,7 +13,7 @@ */ package com.beanit.openiec61850; -import com.beanit.jasn1.ber.types.BerInteger; +import com.beanit.asn1bean.ber.types.BerInteger; import com.beanit.openiec61850.internal.mms.asn1.Data; import com.beanit.openiec61850.internal.mms.asn1.TypeDescription; import com.beanit.openiec61850.internal.mms.asn1.Unsigned8; diff --git a/src/main/java/com/beanit/openiec61850/BdaInt8U.java b/src/main/java/com/beanit/openiec61850/BdaInt8U.java index f741f9f..ae729c4 100644 --- a/src/main/java/com/beanit/openiec61850/BdaInt8U.java +++ b/src/main/java/com/beanit/openiec61850/BdaInt8U.java @@ -13,7 +13,7 @@ */ package com.beanit.openiec61850; -import com.beanit.jasn1.ber.types.BerInteger; +import com.beanit.asn1bean.ber.types.BerInteger; import com.beanit.openiec61850.internal.mms.asn1.Data; import com.beanit.openiec61850.internal.mms.asn1.TypeDescription; import com.beanit.openiec61850.internal.mms.asn1.Unsigned8; diff --git a/src/main/java/com/beanit/openiec61850/BdaOctetString.java b/src/main/java/com/beanit/openiec61850/BdaOctetString.java index c226f4b..e9aa2df 100644 --- a/src/main/java/com/beanit/openiec61850/BdaOctetString.java +++ b/src/main/java/com/beanit/openiec61850/BdaOctetString.java @@ -13,7 +13,7 @@ */ package com.beanit.openiec61850; -import com.beanit.jasn1.ber.types.BerOctetString; +import com.beanit.asn1bean.ber.types.BerOctetString; import com.beanit.openiec61850.internal.mms.asn1.Data; import com.beanit.openiec61850.internal.mms.asn1.Integer32; import com.beanit.openiec61850.internal.mms.asn1.TypeDescription; diff --git a/src/main/java/com/beanit/openiec61850/BdaTimestamp.java b/src/main/java/com/beanit/openiec61850/BdaTimestamp.java index b0e9aa9..41ad2fa 100644 --- a/src/main/java/com/beanit/openiec61850/BdaTimestamp.java +++ b/src/main/java/com/beanit/openiec61850/BdaTimestamp.java @@ -13,7 +13,7 @@ */ package com.beanit.openiec61850; -import com.beanit.jasn1.ber.types.BerNull; +import com.beanit.asn1bean.ber.types.BerNull; import com.beanit.openiec61850.internal.mms.asn1.Data; import com.beanit.openiec61850.internal.mms.asn1.TypeDescription; import com.beanit.openiec61850.internal.mms.asn1.UtcTime; diff --git a/src/main/java/com/beanit/openiec61850/BdaVisibleString.java b/src/main/java/com/beanit/openiec61850/BdaVisibleString.java index 351074b..c58fb74 100644 --- a/src/main/java/com/beanit/openiec61850/BdaVisibleString.java +++ b/src/main/java/com/beanit/openiec61850/BdaVisibleString.java @@ -13,7 +13,7 @@ */ package com.beanit.openiec61850; -import com.beanit.jasn1.ber.types.string.BerVisibleString; +import com.beanit.asn1bean.ber.types.string.BerVisibleString; import com.beanit.openiec61850.internal.mms.asn1.Data; import com.beanit.openiec61850.internal.mms.asn1.Integer32; import com.beanit.openiec61850.internal.mms.asn1.TypeDescription; diff --git a/src/main/java/com/beanit/openiec61850/ClientAssociation.java b/src/main/java/com/beanit/openiec61850/ClientAssociation.java index 8ce780d..6781087 100644 --- a/src/main/java/com/beanit/openiec61850/ClientAssociation.java +++ b/src/main/java/com/beanit/openiec61850/ClientAssociation.java @@ -13,11 +13,11 @@ */ package com.beanit.openiec61850; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerInteger; -import com.beanit.jasn1.ber.types.BerNull; -import com.beanit.jasn1.ber.types.string.BerGraphicString; -import com.beanit.jasn1.ber.types.string.BerVisibleString; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerInteger; +import com.beanit.asn1bean.ber.types.BerNull; +import com.beanit.asn1bean.ber.types.string.BerGraphicString; +import com.beanit.asn1bean.ber.types.string.BerVisibleString; import com.beanit.josistack.AcseAssociation; import com.beanit.josistack.ByteBufferInputStream; import com.beanit.josistack.ClientAcseSap; diff --git a/src/main/java/com/beanit/openiec61850/ServerAssociation.java b/src/main/java/com/beanit/openiec61850/ServerAssociation.java index 217edde..a24d276 100644 --- a/src/main/java/com/beanit/openiec61850/ServerAssociation.java +++ b/src/main/java/com/beanit/openiec61850/ServerAssociation.java @@ -13,10 +13,10 @@ */ package com.beanit.openiec61850; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerInteger; -import com.beanit.jasn1.ber.types.BerNull; -import com.beanit.jasn1.ber.types.string.BerVisibleString; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerInteger; +import com.beanit.asn1bean.ber.types.BerNull; +import com.beanit.asn1bean.ber.types.string.BerVisibleString; import com.beanit.josistack.AcseAssociation; import com.beanit.josistack.ByteBufferInputStream; import com.beanit.josistack.DecodingException; diff --git a/src/main/java/com/beanit/openiec61850/Urcb.java b/src/main/java/com/beanit/openiec61850/Urcb.java index a07f5e7..d0d3d16 100644 --- a/src/main/java/com/beanit/openiec61850/Urcb.java +++ b/src/main/java/com/beanit/openiec61850/Urcb.java @@ -13,7 +13,7 @@ */ package com.beanit.openiec61850; -import com.beanit.jasn1.ber.types.BerBitString; +import com.beanit.asn1bean.ber.types.BerBitString; import com.beanit.openiec61850.internal.mms.asn1.AccessResult; import com.beanit.openiec61850.internal.mms.asn1.Data; import com.beanit.openiec61850.internal.mms.asn1.Identifier; diff --git a/src/main/java/com/beanit/openiec61850/internal/BerBoolean.java b/src/main/java/com/beanit/openiec61850/internal/BerBoolean.java index 6e7360d..bfb38c7 100644 --- a/src/main/java/com/beanit/openiec61850/internal/BerBoolean.java +++ b/src/main/java/com/beanit/openiec61850/internal/BerBoolean.java @@ -13,10 +13,10 @@ */ package com.beanit.openiec61850.internal; -import com.beanit.jasn1.ber.BerLength; -import com.beanit.jasn1.ber.BerTag; -import com.beanit.jasn1.ber.ReverseByteArrayOutputStream; -import com.beanit.jasn1.ber.types.BerType; +import com.beanit.asn1bean.ber.BerLength; +import com.beanit.asn1bean.ber.BerTag; +import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream; +import com.beanit.asn1bean.ber.types.BerType; import java.io.EOFException; import java.io.IOException; import java.io.InputStream; @@ -28,9 +28,8 @@ public class BerBoolean implements Serializable, BerType { public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.PRIMITIVE, BerTag.BOOLEAN_TAG); private static final long serialVersionUID = 1L; - public byte[] code = null; - public boolean value; + private byte[] code = null; public BerBoolean() {} @@ -50,9 +49,7 @@ public class BerBoolean implements Serializable, BerType { public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { - for (int i = code.length - 1; i >= 0; i--) { - reverseOS.write(code[i]); - } + reverseOS.write(code); if (withTag) { return tag.encode(reverseOS) + code.length; } @@ -62,7 +59,7 @@ public class BerBoolean implements Serializable, BerType { int codeLength = 1; if (value) { - reverseOS.write(0xff); + reverseOS.write(0x01); } else { reverseOS.write(0); }