issue_873: fixed all checkstyle issues

This commit is contained in:
TheSilentCoder 2024-11-08 15:48:21 -05:00
parent 0f2a5864ba
commit 52f5f1bb70
28 changed files with 104 additions and 89 deletions

View File

@ -39,10 +39,10 @@ configurations.checkstyle {
} }
} }
checkstyleMain { checkstyleMain {
source ='src/main/java' source = 'src/main/java'
} }
checkstyleTest { checkstyleTest {
source ='src/test/java' source = 'src/test/java'
} }
tasks.withType(Checkstyle) { tasks.withType(Checkstyle) {
reports { reports {

View File

@ -2,11 +2,11 @@
<!-- Docs at http://findbugs.sourceforge.net/manual/filter.html --> <!-- Docs at http://findbugs.sourceforge.net/manual/filter.html -->
<FindBugsFilter> <FindBugsFilter>
<Match> <Match>
<Package name="~hirs\.structs.*" /> <Package name="~hirs\.structs.*"/>
</Match> </Match>
<Match> <Match>
<!-- https://github.com/spotbugs/spotbugs/pull/2748 --> <!-- https://github.com/spotbugs/spotbugs/pull/2748 -->
<Bug pattern="CT_CONSTRUCTOR_THROW" /> <Bug pattern="CT_CONSTRUCTOR_THROW"/>
</Match> </Match>
<!-- <Match>--> <!-- <Match>-->

View File

@ -2,22 +2,24 @@ package hirs.structs.converters;
import hirs.structs.elements.Struct; import hirs.structs.elements.Struct;
import hirs.structs.elements.StructElementLength; import hirs.structs.elements.StructElementLength;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import org.apache.commons.lang3.reflect.ConstructorUtils; import org.apache.commons.lang3.reflect.ConstructorUtils;
import org.apache.commons.lang3.reflect.FieldUtils; import org.apache.commons.lang3.reflect.FieldUtils;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
/** /**
* StructBuilder implementation. * StructBuilder implementation.
* *
* @param <T> the type of Struct to build * @param <T> the type of Struct to build
*/ */
public class SimpleStructBuilder<T extends Struct> implements StructBuilder { public class SimpleStructBuilder<T extends Struct> implements StructBuilder {
private T struct;
private final Class<T> clazz; private final Class<T> clazz;
private T struct;
/** /**
* Instantiates the builder. * Instantiates the builder.
*
* @param clazz The type of struct to build * @param clazz The type of struct to build
*/ */
public SimpleStructBuilder(final Class<T> clazz) { public SimpleStructBuilder(final Class<T> clazz) {
@ -29,7 +31,7 @@ public class SimpleStructBuilder<T extends Struct> implements StructBuilder {
try { try {
struct = ConstructorUtils.invokeConstructor(clazz); struct = ConstructorUtils.invokeConstructor(clazz);
} catch (InstantiationException | IllegalAccessException } catch (InstantiationException | IllegalAccessException
| NoSuchMethodException | InvocationTargetException e) { | NoSuchMethodException | InvocationTargetException e) {
throw new StructBuilderException( throw new StructBuilderException(
String.format("Unexpected error constructing new instance: %s", String.format("Unexpected error constructing new instance: %s",
clazz.getSimpleName(), e.getMessage()), e); clazz.getSimpleName(), e.getMessage()), e);
@ -59,17 +61,13 @@ public class SimpleStructBuilder<T extends Struct> implements StructBuilder {
public SimpleStructBuilder<T> set(final String field, final Number value) { public SimpleStructBuilder<T> set(final String field, final Number value) {
try { try {
String type = clazz.getDeclaredField(field).getType().getSimpleName(); String type = clazz.getDeclaredField(field).getType().getSimpleName();
switch (clazz.getDeclaredField(field).getType().getSimpleName()) { return switch (clazz.getDeclaredField(field).getType().getSimpleName()) {
case "short": case "short" -> setField(field, value.shortValue());
return setField(field, value.shortValue()); case "int" -> setField(field, value.intValue());
case "int": case "byte" -> setField(field, value.byteValue());
return setField(field, value.intValue()); default -> throw new StructBuilderException(
case "byte": String.format("Unhandled numeric field type: %s", type));
return setField(field, value.byteValue()); };
default:
throw new StructBuilderException(
String.format("Unhandled numeric field type: %s", type));
}
} catch (NoSuchFieldException | SecurityException e) { } catch (NoSuchFieldException | SecurityException e) {
throw new StructBuilderException( throw new StructBuilderException(
String.format("Unexpected error setting field: %s", String.format("Unexpected error setting field: %s",
@ -122,7 +120,7 @@ public class SimpleStructBuilder<T extends Struct> implements StructBuilder {
FieldUtils.writeField(field, struct, value); FieldUtils.writeField(field, struct, value);
field.setAccessible(false); field.setAccessible(false);
} catch (NoSuchFieldException | SecurityException } catch (NoSuchFieldException | SecurityException
| IllegalArgumentException | IllegalAccessException e) { | IllegalArgumentException | IllegalAccessException e) {
throw new StructBuilderException( throw new StructBuilderException(
String.format("Unexpected error setting field: %s", String.format("Unexpected error setting field: %s",
fieldName, e.getMessage()), e); fieldName, e.getMessage()), e);

View File

@ -25,7 +25,7 @@ public class SimpleStructConverter implements StructConverter {
// using output stream resources, serialize the specified struct // using output stream resources, serialize the specified struct
try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream)) { DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream)) {
// obtain the struct elements definition // obtain the struct elements definition
StructElements structElements = struct.getClass().getAnnotation(StructElements.class); StructElements structElements = struct.getClass().getAnnotation(StructElements.class);

View File

@ -20,8 +20,8 @@ public interface StructConverter {
* *
* @param data to be parsed * @param data to be parsed
* @param type type of data being parsed * @param type type of data being parsed
* @param <T> the {@link Struct} type * @param <T> the {@link Struct} type
* @return de-serialized struct * @return de-serialized struct
*/ */
<T extends Struct> T convert(final byte[] data, final Class<T> type); <T extends Struct> T convert(byte[] data, Class<T> type);
} }

View File

@ -14,7 +14,7 @@ import java.lang.annotation.Target;
public @interface StructElementLength { public @interface StructElementLength {
/** /**
* the field that this length represents. * @return the field that this length represents.
*/ */
String fieldName(); String fieldName();
} }

View File

@ -13,7 +13,7 @@ import java.lang.annotation.Target;
public @interface StructElements { public @interface StructElements {
/** /**
* elements in order to be processed by a converter. * @return elements in order to be processed by a converter.
*/ */
String[] elements(); String[] elements();
} }

View File

@ -10,10 +10,10 @@ import java.util.Arrays;
* A container for an encoded {@link hirs.structs.elements.tpm.IdentityRequest}, * A container for an encoded {@link hirs.structs.elements.tpm.IdentityRequest},
* its associated endorsement credential, and its device information. * its associated endorsement credential, and its device information.
*/ */
@StructElements(elements = { "requestLength", "request", @StructElements(elements = {"requestLength", "request",
"endorsementCredentialModulusLength", "endorsementCredentialModulus", "endorsementCredentialModulusLength", "endorsementCredentialModulus",
"endorsementCredentialLength", "endorsementCredential", "endorsementCredentialLength", "endorsementCredential",
"deviceInfoReportLength", "deviceInfoReport" }) "deviceInfoReportLength", "deviceInfoReport"})
public class IdentityRequestEnvelope implements Struct { public class IdentityRequestEnvelope implements Struct {
@StructElementLength(fieldName = "request") @StructElementLength(fieldName = "request")
@ -72,7 +72,6 @@ public class IdentityRequestEnvelope implements Struct {
} }
/** /**
*
* @return the endorsementCredential * @return the endorsementCredential
*/ */
public byte[] getEndorsementCredential() { public byte[] getEndorsementCredential() {
@ -80,7 +79,6 @@ public class IdentityRequestEnvelope implements Struct {
} }
/** /**
*
* @return the length of the device info report * @return the length of the device info report
*/ */
public int getDeviceInfoReportLength() { public int getDeviceInfoReportLength() {
@ -88,7 +86,6 @@ public class IdentityRequestEnvelope implements Struct {
} }
/** /**
*
* @return the device info report * @return the device info report
*/ */
public byte[] getDeviceInfoReport() { public byte[] getDeviceInfoReport() {

View File

@ -9,8 +9,8 @@ import java.util.Arrays;
/** /**
* Data structure used by the ACA to respond back to a client's {@link IdentityRequestEnvelope}. * Data structure used by the ACA to respond back to a client's {@link IdentityRequestEnvelope}.
*/ */
@StructElements(elements = { "asymmetricContentsSize", "asymmetricContents", @StructElements(elements = {"asymmetricContentsSize", "asymmetricContents",
"symmetricAttestation" }) "symmetricAttestation"})
public class IdentityResponseEnvelope implements Struct { public class IdentityResponseEnvelope implements Struct {
@StructElementLength(fieldName = "asymmetricContents") @StructElementLength(fieldName = "asymmetricContents")

View File

@ -12,7 +12,7 @@ import java.util.Arrays;
* the envelope contains the Identity Credential that is signed by the ACA. This along with the key * the envelope contains the Identity Credential that is signed by the ACA. This along with the key
* parameters are typically sent to the TPM to activate an Identity. * parameters are typically sent to the TPM to activate an Identity.
*/ */
@StructElements(elements = { "credentialSize", "algorithm", "credential" }) @StructElements(elements = {"credentialSize", "algorithm", "credential"})
public class SymmetricAttestation implements Struct { public class SymmetricAttestation implements Struct {
@StructElementLength(fieldName = "credential") @StructElementLength(fieldName = "credential")

View File

@ -8,8 +8,8 @@ import hirs.structs.elements.StructElements;
* As defined in TCPA 4.20, the key parameters data structure describes the parameters used to * As defined in TCPA 4.20, the key parameters data structure describes the parameters used to
* generate a key pair and to store the parts of a key. * generate a key pair and to store the parts of a key.
*/ */
@StructElements(elements = { "algorithmId", "encryptionScheme", "signatureScheme", "paramsSize", @StructElements(elements = {"algorithmId", "encryptionScheme", "signatureScheme", "paramsSize",
"params" }) "params"})
public class AsymmetricKeyParams implements Struct { public class AsymmetricKeyParams implements Struct {
private int algorithmId; private int algorithmId;

View File

@ -8,7 +8,7 @@ import hirs.structs.elements.StructElements;
* portion of an asymmetric key pair. It contains all the information necessary for it's unambiguous * portion of an asymmetric key pair. It contains all the information necessary for it's unambiguous
* usage. * usage.
*/ */
@StructElements(elements = { "asymmetricKeyParams", "storePubKey" }) @StructElements(elements = {"asymmetricKeyParams", "storePubKey"})
public class AsymmetricPublicKey implements Struct { public class AsymmetricPublicKey implements Struct {
/** /**

View File

@ -35,11 +35,6 @@ public enum EncryptionScheme {
this.encryptionScheme = encryptionScheme; this.encryptionScheme = encryptionScheme;
} }
@Override
public String toString() {
return this.encryptionScheme;
}
/** /**
* Maps an {@link EncryptionScheme} based upon an integer. If the scheme is unmapped, the * Maps an {@link EncryptionScheme} based upon an integer. If the scheme is unmapped, the
* default, {@link #PKCS1} is returned. * default, {@link #PKCS1} is returned.
@ -48,11 +43,14 @@ public enum EncryptionScheme {
* @return the encryption scheme, or if unknown, the default. * @return the encryption scheme, or if unknown, the default.
*/ */
public static EncryptionScheme fromInt(final int scheme) { public static EncryptionScheme fromInt(final int scheme) {
switch (scheme) { if (scheme == OAEP_VALUE) {
case OAEP_VALUE: return OAEP;
return OAEP;
default:
return PKCS1;
} }
return PKCS1;
}
@Override
public String toString() {
return this.encryptionScheme;
} }
} }

View File

@ -11,9 +11,9 @@ import java.util.Arrays;
* identity process. This structure contains information that is required by the Attestation * identity process. This structure contains information that is required by the Attestation
* Certificate Authority to attest an identity request. * Certificate Authority to attest an identity request.
*/ */
@StructElements(elements = { "version", "labelSize", "identityBindingSize", "endorsementSize", @StructElements(elements = {"version", "labelSize", "identityBindingSize", "endorsementSize",
"platformSize", "conformanceSize", "identityKey", "label", "identityBinding", "platformSize", "conformanceSize", "identityKey", "label", "identityBinding",
"endorsementCredential", "platformCredential", "conformanceCredential" }) "endorsementCredential", "platformCredential", "conformanceCredential"})
public class IdentityProof implements Struct { public class IdentityProof implements Struct {
private Version version; private Version version;

View File

@ -10,8 +10,8 @@ import java.util.Arrays;
* As specified in TCPA 4.30.2 specification. This structure is sent to the Attestation Certificate * As specified in TCPA 4.30.2 specification. This structure is sent to the Attestation Certificate
* Authority to create an Identity Credential. * Authority to create an Identity Credential.
*/ */
@StructElements(elements = { "asymmetricBlobSize", "symmetricBlobSize", "asymmetricAlgorithm", @StructElements(elements = {"asymmetricBlobSize", "symmetricBlobSize", "asymmetricAlgorithm",
"symmetricAlgorithm", "asymmetricBlob", "symmetricBlob" }) "symmetricAlgorithm", "asymmetricBlob", "symmetricBlob"})
public class IdentityRequest implements Struct { public class IdentityRequest implements Struct {
@StructElementLength(fieldName = "asymmetricBlob") @StructElementLength(fieldName = "asymmetricBlob")

View File

@ -8,7 +8,7 @@ import hirs.structs.elements.StructElements;
* portion of an asymmetric key pair. It contains all the information necessary for it's unambiguous * portion of an asymmetric key pair. It contains all the information necessary for it's unambiguous
* usage. * usage.
*/ */
@StructElements(elements = { "asymmetricKeyParams", "storePubKey" }) @StructElements(elements = {"asymmetricKeyParams", "storePubKey"})
public class PublicKey implements Struct { public class PublicKey implements Struct {
private AsymmetricKeyParams asymmetricKeyParams; private AsymmetricKeyParams asymmetricKeyParams;

View File

@ -10,7 +10,7 @@ import java.util.Arrays;
* Parameters that are used to describe a particular {@link AsymmetricKeyParams} as specified by the * Parameters that are used to describe a particular {@link AsymmetricKeyParams} as specified by the
* TCPA 4.20. * TCPA 4.20.
*/ */
@StructElements(elements = { "keyLength", "totalPrimes", "exponentSize", "exponent" }) @StructElements(elements = {"keyLength", "totalPrimes", "exponentSize", "exponent"})
public class RsaSubParams implements Struct { public class RsaSubParams implements Struct {
private int keyLength; private int keyLength;

View File

@ -10,7 +10,7 @@ import java.util.Arrays;
* As specified in TCPA Main Specification section 4.27.2. This structure represents a public key of * As specified in TCPA Main Specification section 4.27.2. This structure represents a public key of
* an asymmetric key pair. * an asymmetric key pair.
*/ */
@StructElements(elements = { "keyLength", "key" }) @StructElements(elements = {"keyLength", "key"})
public class StorePubKey implements Struct { public class StorePubKey implements Struct {
@StructElementLength(fieldName = "key") @StructElementLength(fieldName = "key")

View File

@ -10,7 +10,7 @@ import java.util.Arrays;
* Part of the TPM Identity Request. This Structure is encrypted inside the request and is typically * Part of the TPM Identity Request. This Structure is encrypted inside the request and is typically
* unencrypted by an Attestation Certificate Authority. * unencrypted by an Attestation Certificate Authority.
*/ */
@StructElements(elements = { "algorithmId", "encryptionScheme", "keySize", "key" }) @StructElements(elements = {"algorithmId", "encryptionScheme", "keySize", "key"})
public class SymmetricKey implements Struct { public class SymmetricKey implements Struct {
/** /**

View File

@ -7,8 +7,8 @@ import hirs.structs.elements.StructElements;
/** /**
* Represents a symmetric key as specified in section 4.20 of the TCPA. * Represents a symmetric key as specified in section 4.20 of the TCPA.
*/ */
@StructElements(elements = { "algorithmId", "encryptionScheme", "signatureScheme", "paramsSize", @StructElements(elements = {"algorithmId", "encryptionScheme", "signatureScheme", "paramsSize",
"params" }) "params"})
public class SymmetricKeyParams implements Struct { public class SymmetricKeyParams implements Struct {
/** /**

View File

@ -10,7 +10,7 @@ import java.util.Arrays;
* Represents a dynamic key parameters data structure that is enclosed inside a {@link * Represents a dynamic key parameters data structure that is enclosed inside a {@link
* SymmetricKeyParams}. * SymmetricKeyParams}.
*/ */
@StructElements(elements = { "keyLength", "blockSize", "ivSize", "iv" }) @StructElements(elements = {"keyLength", "blockSize", "ivSize", "iv"})
public class SymmetricSubParams implements Struct { public class SymmetricSubParams implements Struct {
private int keyLength; private int keyLength;

View File

@ -7,7 +7,7 @@ import hirs.structs.elements.StructElements;
* As specified in the TCPA Main Specification section 4.5. This structure represents the version of * As specified in the TCPA Main Specification section 4.5. This structure represents the version of
* the TPM. * the TPM.
*/ */
@StructElements(elements = { "major", "minor", "revisionMajor", "revisionMinor" }) @StructElements(elements = {"major", "minor", "revisionMajor", "revisionMinor"})
public class Version implements Struct { public class Version implements Struct {
private byte major; private byte major;

View File

@ -1,8 +1,9 @@
package hirs.structs.converters; package hirs.structs.converters;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
/** /**
* Tests suite for {@link SimpleStructConverter}. * Tests suite for {@link SimpleStructConverter}.
@ -13,24 +14,25 @@ public class SimpleStructBuilderTest {
/** /**
* Tests {@link SimpleStructBuilder#build()}. * Tests {@link SimpleStructBuilder#build()}.
* @throws NoSuchFieldException sometimes *
* @throws IllegalAccessException sometimes * @throws NoSuchFieldException sometimes
* @throws IllegalAccessException sometimes
* @throws IllegalArgumentException sometimes * @throws IllegalArgumentException sometimes
*/ */
@Test @Test
public final void testBuild() throws NoSuchFieldException, IllegalArgumentException, public final void testBuild() throws NoSuchFieldException, IllegalArgumentException,
IllegalAccessException { IllegalAccessException {
TestStruct struct = new SimpleStructBuilder<>(TestStruct.class) TestStruct struct = new SimpleStructBuilder<>(TestStruct.class)
.set("testShort", NUMBER) .set("testShort", NUMBER)
.set("testByte", NUMBER) .set("testByte", NUMBER)
.set("testEmbeddedStruct", new SimpleStructBuilder<>(TestEmbeddedStruct.class) .set("testEmbeddedStruct", new SimpleStructBuilder<>(TestEmbeddedStruct.class)
.set("embeddedShort", NUMBER) .set("embeddedShort", NUMBER)
.set("embedded", ARRAY) .set("embedded", ARRAY)
.build()) .build())
.set("testVariableStruct", new SimpleStructBuilder<>(TestVariableStruct.class) .set("testVariableStruct", new SimpleStructBuilder<>(TestVariableStruct.class)
.set("testArray", ARRAY) .set("testArray", ARRAY)
.build()) .build())
.build(); .build();
assertEquals(NUMBER, struct.getTestShort()); assertEquals(NUMBER, struct.getTestShort());
assertEquals(NUMBER, struct.getTestByte()); assertEquals(NUMBER, struct.getTestByte());

View File

@ -1,8 +1,9 @@
package hirs.structs.converters; package hirs.structs.converters;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import org.junit.jupiter.api.Test;
/** /**
* Tests suite for {@link SimpleStructConverter}. * Tests suite for {@link SimpleStructConverter}.
@ -10,11 +11,11 @@ import org.junit.jupiter.api.Test;
public class SimpleStructConverterTest { public class SimpleStructConverterTest {
private static final byte[] EXPECTED_BYTES = private static final byte[] EXPECTED_BYTES =
new byte[]{0, 5, 0, 0, 0, 10, 0, 7, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 6, 0, 0, 0, 0}; new byte[] {0, 5, 0, 0, 0, 10, 0, 7, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 6, 0, 0, 0, 0};
private final TestStruct testStruct = new TestStruct(); private final TestStruct testStruct = new TestStruct();
private StructConverter converter = new SimpleStructConverter(); private final StructConverter converter = new SimpleStructConverter();
/** /**
* Tests {@link SimpleStructConverter#convert(hirs.structs.elements.Struct)}. * Tests {@link SimpleStructConverter#convert(hirs.structs.elements.Struct)}.
@ -47,8 +48,9 @@ public class SimpleStructConverterTest {
*/ */
@Test @Test
public final void testNoElementsStructConvertToArray() { public final void testNoElementsStructConvertToArray() {
assertThrows(StructConversionException.class, () -> assertThrows(StructConversionException.class, () -> {
{converter.convert(new TestNoElementsAnnotationStruct());}, ".*@StructElements.*"); converter.convert(new TestNoElementsAnnotationStruct());
}, ".*@StructElements.*");
} }
/** /**
@ -57,8 +59,9 @@ public class SimpleStructConverterTest {
*/ */
@Test @Test
public final void testNoElementsStructConvertToStruct() { public final void testNoElementsStructConvertToStruct() {
assertThrows(StructConversionException.class, () -> assertThrows(StructConversionException.class, () -> {
{converter.convert(new byte[1], TestNoElementsAnnotationStruct.class);}, ".*@StructElements.*"); converter.convert(new byte[1], TestNoElementsAnnotationStruct.class);
}, ".*@StructElements.*");
} }
/** /**
@ -68,8 +71,9 @@ public class SimpleStructConverterTest {
*/ */
@Test @Test
public final void testInvalidDataTypeStructConvertToArray() { public final void testInvalidDataTypeStructConvertToArray() {
assertThrows(StructConversionException.class, () -> assertThrows(StructConversionException.class, () -> {
{converter.convert(new TestInvalidDataTypeStruct());}, "Unsupported field type.*"); converter.convert(new TestInvalidDataTypeStruct());
}, "Unsupported field type.*");
} }
/** /**
@ -79,8 +83,9 @@ public class SimpleStructConverterTest {
*/ */
@Test @Test
public final void testInvalidDataTypeStructConvertToStruct() { public final void testInvalidDataTypeStructConvertToStruct() {
assertThrows(StructConversionException.class, () -> assertThrows(StructConversionException.class, () -> {
{converter.convert(new byte[1], TestInvalidDataTypeStruct.class);}, "Unsupported field type.*"); converter.convert(new byte[1], TestInvalidDataTypeStruct.class);
}, "Unsupported field type.*");
} }

View File

@ -9,7 +9,7 @@ import java.util.Arrays;
/** /**
* A struct to be embedded within TestStruct. * A struct to be embedded within TestStruct.
*/ */
@StructElements(elements = { "embeddedSize", "embeddedShort", "embedded" }) @StructElements(elements = {"embeddedSize", "embeddedShort", "embedded"})
public class TestEmbeddedStruct implements Struct { public class TestEmbeddedStruct implements Struct {
private static final int EMBEDDED_SIZE = 10; private static final int EMBEDDED_SIZE = 10;
@ -18,7 +18,7 @@ public class TestEmbeddedStruct implements Struct {
private static final int HASH_CODE = 31; private static final int HASH_CODE = 31;
private static final byte[] DEFAULT_ARRAY = new byte[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 0}; private static final byte[] DEFAULT_ARRAY = new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 0};
@StructElementLength(fieldName = "embedded") @StructElementLength(fieldName = "embedded")
@ -28,6 +28,12 @@ public class TestEmbeddedStruct implements Struct {
private byte[] embedded = DEFAULT_ARRAY; private byte[] embedded = DEFAULT_ARRAY;
/**
* Returns true if the provided object is equivalent to this class.
*
* @param o object to compare
* @return true if the provided object is equal to this class
*/
@Override @Override
public boolean equals(final Object o) { public boolean equals(final Object o) {
if (this == o) { if (this == o) {
@ -53,6 +59,7 @@ public class TestEmbeddedStruct implements Struct {
/** /**
* Getter. * Getter.
*
* @return value * @return value
*/ */
public byte[] getEmbedded() { public byte[] getEmbedded() {
@ -61,6 +68,7 @@ public class TestEmbeddedStruct implements Struct {
/** /**
* Getter. * Getter.
*
* @return value * @return value
*/ */
public short getEmbeddedShort() { public short getEmbeddedShort() {
@ -69,6 +77,7 @@ public class TestEmbeddedStruct implements Struct {
/** /**
* Getter. * Getter.
*
* @return value * @return value
*/ */
public int getEmbeddedSize() { public int getEmbeddedSize() {

View File

@ -6,7 +6,7 @@ import hirs.structs.elements.StructElements;
/** /**
* Test Struct that has an unsupported data type. * Test Struct that has an unsupported data type.
*/ */
@StructElements(elements = { "testLong" }) @StructElements(elements = {"testLong"})
public class TestInvalidDataTypeStruct implements Struct { public class TestInvalidDataTypeStruct implements Struct {
private static final Long TEST_LONG_VALUE = 1L; private static final Long TEST_LONG_VALUE = 1L;

View File

@ -8,8 +8,8 @@ import hirs.structs.elements.StructElements;
* A Struct class designed to fully test the design of the converter being tested. * A Struct class designed to fully test the design of the converter being tested.
*/ */
@StructElements( @StructElements(
elements = { "testShort", "testEmbeddedStruct", "testByte", "testVariableStructLength", elements = {"testShort", "testEmbeddedStruct", "testByte", "testVariableStructLength",
"testVariableStruct" }) "testVariableStruct"})
public class TestStruct implements Struct { public class TestStruct implements Struct {
private static final short TEST_SHORT = 0x5; private static final short TEST_SHORT = 0x5;
@ -54,6 +54,7 @@ public class TestStruct implements Struct {
/** /**
* Getter. * Getter.
*
* @return value * @return value
*/ */
public byte getTestByte() { public byte getTestByte() {
@ -62,6 +63,7 @@ public class TestStruct implements Struct {
/** /**
* Getter. * Getter.
*
* @return value * @return value
*/ */
public short getTestShort() { public short getTestShort() {
@ -70,6 +72,7 @@ public class TestStruct implements Struct {
/** /**
* Getter. * Getter.
*
* @return value * @return value
*/ */
public TestEmbeddedStruct getTestEmbeddedStruct() { public TestEmbeddedStruct getTestEmbeddedStruct() {
@ -78,6 +81,7 @@ public class TestStruct implements Struct {
/** /**
* Getter. * Getter.
*
* @return value * @return value
*/ */
public TestVariableStruct getTestVariableStruct() { public TestVariableStruct getTestVariableStruct() {
@ -86,6 +90,7 @@ public class TestStruct implements Struct {
/** /**
* Getter. * Getter.
*
* @return value * @return value
*/ */
public int getTestVariableStructLength() { public int getTestVariableStructLength() {

View File

@ -14,6 +14,7 @@ public class TestVariableStruct implements Struct {
/** /**
* Getter. * Getter.
*
* @return value * @return value
*/ */
public byte[] getTestArray() { public byte[] getTestArray() {