Skip to content

Commit

Permalink
Merge pull request #865 from nsacyber/v3_issue_864-revert-checkstyle-…
Browse files Browse the repository at this point in the history
…rule-in-checkstylexml

[#864] Undid Constant Name Rule In Checkstyles XML and Applied Formatting/Changes to HIRS_UTILS
  • Loading branch information
iadgovuser26 authored Nov 8, 2024
2 parents 775ab4a + 09a57f0 commit 0f2a586
Show file tree
Hide file tree
Showing 79 changed files with 1,579 additions and 3,428 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ public BaseReferenceManifest(final byte[] rimBytes) throws UnmarshalException {
* @param rimBytes byte array representation of the RIM
* @throws IOException if unable to unmarshal the string
*/
@SuppressWarnings("checkstyle:AvoidInlineConditionals")
public BaseReferenceManifest(final String fileName, final byte[] rimBytes)
throws UnmarshalException {
super(rimBytes);
Expand All @@ -127,9 +126,11 @@ public BaseReferenceManifest(final String fileName, final byte[] rimBytes)
SwidTagConstants.SWIDTAG_NAMESPACE, SwidTagConstants.META).item(0);
setTagId(softwareIdentity.getAttribute(SwidTagConstants.TAGID));
this.swidName = softwareIdentity.getAttribute(SwidTagConstants.NAME);
this.swidCorpus = Boolean.parseBoolean(softwareIdentity.getAttribute(SwidTagConstants.CORPUS)) ? 1 : 0;
this.swidCorpus =
Boolean.parseBoolean(softwareIdentity.getAttribute(SwidTagConstants.CORPUS)) ? 1 : 0;
this.setSwidPatch(Boolean.parseBoolean(softwareIdentity.getAttribute(SwidTagConstants.PATCH)));
this.setSwidSupplemental(Boolean.parseBoolean(softwareIdentity.getAttribute(SwidTagConstants.SUPPLEMENTAL)));
this.setSwidSupplemental(
Boolean.parseBoolean(softwareIdentity.getAttribute(SwidTagConstants.SUPPLEMENTAL)));
this.setSwidVersion(softwareIdentity.getAttribute(SwidTagConstants.VERSION));
this.setSwidTagVersion(softwareIdentity.getAttribute(SwidTagConstants.TAGVERSION));

Expand All @@ -147,20 +148,22 @@ public BaseReferenceManifest(final String fileName, final byte[] rimBytes)
*/
private void parseSoftwareMeta(final Element softwareMeta) {
if (softwareMeta != null) {
this.colloquialVersion = softwareMeta.getAttribute(SwidTagConstants._COLLOQUIAL_VERSION_STR);
this.product = softwareMeta.getAttribute(SwidTagConstants._PRODUCT_STR);
this.revision = softwareMeta.getAttribute(SwidTagConstants._REVISION_STR);
this.edition = softwareMeta.getAttribute(SwidTagConstants._EDITION_STR);
this.rimLinkHash = softwareMeta.getAttribute(SwidTagConstants._RIM_LINK_HASH_STR);
this.bindingSpec = softwareMeta.getAttribute(SwidTagConstants._BINDING_SPEC_STR);
this.bindingSpecVersion = softwareMeta.getAttribute(SwidTagConstants._BINDING_SPEC_VERSION_STR);
this.setPlatformManufacturerId(softwareMeta.getAttribute(SwidTagConstants._PLATFORM_MANUFACTURER_ID_STR));
this.setPlatformManufacturer(softwareMeta.getAttribute(SwidTagConstants._PLATFORM_MANUFACTURER_STR));
this.setPlatformModel(softwareMeta.getAttribute(SwidTagConstants._PLATFORM_MODEL_STR));
this.platformVersion = softwareMeta.getAttribute(SwidTagConstants._PLATFORM_VERSION_STR);
this.payloadType = softwareMeta.getAttribute(SwidTagConstants._PAYLOAD_TYPE_STR);
this.pcURIGlobal = softwareMeta.getAttribute(SwidTagConstants._PC_URI_GLOBAL_STR);
this.pcURILocal = softwareMeta.getAttribute(SwidTagConstants._PC_URI_LOCAL_STR);
this.colloquialVersion = softwareMeta.getAttribute(SwidTagConstants.COLLOQUIAL_VERSION_STR);
this.product = softwareMeta.getAttribute(SwidTagConstants.PRODUCT_STR);
this.revision = softwareMeta.getAttribute(SwidTagConstants.REVISION_STR);
this.edition = softwareMeta.getAttribute(SwidTagConstants.EDITION_STR);
this.rimLinkHash = softwareMeta.getAttribute(SwidTagConstants.RIM_LINK_HASH_STR);
this.bindingSpec = softwareMeta.getAttribute(SwidTagConstants.BINDING_SPEC_STR);
this.bindingSpecVersion = softwareMeta.getAttribute(SwidTagConstants.BINDING_SPEC_VERSION_STR);
this.setPlatformManufacturerId(
softwareMeta.getAttribute(SwidTagConstants.PLATFORM_MANUFACTURER_ID_STR));
this.setPlatformManufacturer(
softwareMeta.getAttribute(SwidTagConstants.PLATFORM_MANUFACTURER_FULL_STR));
this.setPlatformModel(softwareMeta.getAttribute(SwidTagConstants.PLATFORM_MODEL_STR));
this.platformVersion = softwareMeta.getAttribute(SwidTagConstants.PLATFORM_VERSION_STR);
this.payloadType = softwareMeta.getAttribute(SwidTagConstants.PAYLOAD_TYPE_STR);
this.pcURIGlobal = softwareMeta.getAttribute(SwidTagConstants.PC_URI_GLOBAL_STR);
this.pcURILocal = softwareMeta.getAttribute(SwidTagConstants.PC_URI_LOCAL_STR);
} else {
log.warn("SoftwareMeta Tag not found.");
}
Expand Down Expand Up @@ -202,7 +205,6 @@ private void parseLink(final Element link) {
* This method validates the .swidtag file at the given filepath against the
* schema. A successful validation results in the output of the tag's name
* and tagId attributes, otherwise a generic error message is printed.
*
*/
private Element getDirectoryTag(final byte[] rimBytes) {
if (rimBytes == null || rimBytes.length == 0) {
Expand Down Expand Up @@ -254,7 +256,6 @@ public List<SwidResource> getFileResources() {
* This method iterates over the list of File elements under the directory.
*
* @param rimBytes the bytes to find the files
*
*/
public List<SwidResource> getFileResources(final byte[] rimBytes) {
Element directoryTag = getDirectoryTag(rimBytes);
Expand All @@ -267,8 +268,8 @@ public List<SwidResource> getFileResources(final byte[] rimBytes) {
swidResource = new SwidResource();
swidResource.setName(file.getAttribute(SwidTagConstants.NAME));
swidResource.setSize(file.getAttribute(SwidTagConstants.SIZE));
swidResource.setHashValue(file.getAttribute(SwidTagConstants._SHA256_HASH.getPrefix() + ":"
+ SwidTagConstants._SHA256_HASH.getLocalPart()));
swidResource.setHashValue(file.getAttribute(SwidTagConstants.SHA_256_HASH.getPrefix() + ":"
+ SwidTagConstants.SHA_256_HASH.getLocalPart()));
validHashes.add(swidResource);
}

Expand Down Expand Up @@ -353,9 +354,15 @@ private Document removeXMLWhitespace(final ByteArrayInputStream byteArrayInputSt

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
if (!super.equals(o)) {
return false;
}
BaseReferenceManifest that = (BaseReferenceManifest) o;
return swidCorpus == that.swidCorpus && Objects.equals(swidName, that.swidName)
&& Objects.equals(colloquialVersion, that.colloquialVersion)
Expand Down
8 changes: 4 additions & 4 deletions HIRS_Utils/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ plugins {
id 'checkstyle'
}
// Get version from main project gradle
def packVersion = properties.get("packageVersion");
def jarVersion = properties.get("jarVersion");
def packVersion = properties.get("packageVersion")
def jarVersion = properties.get("jarVersion")
//println "packageVersion is ${projVersion}"


Expand Down Expand Up @@ -66,10 +66,10 @@ configurations.checkstyle {
}
}
checkstyleMain {
source ='src/main/java'
source = 'src/main/java'
}
checkstyleTest {
source ='src/test/java'
source = 'src/test/java'
}
tasks.withType(Checkstyle) {
reports {
Expand Down
6 changes: 3 additions & 3 deletions HIRS_Utils/config/spotbugs/spotbugs-exclude.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
<!-- Docs at http://findbugs.sourceforge.net/manual/filter.html -->
<FindBugsFilter>
<Match>
<Package name="~hirs\.utils.xjc.*" />
<Package name="~hirs\.utils.xjc.*"/>
</Match>
<Match>
<Package name="~hirs\.utils.rim.*" />
<Package name="~hirs\.utils.rim.*"/>
</Match>
<Match>
<!-- https://github.com/spotbugs/spotbugs/pull/2748 -->
<Bug pattern="CT_CONSTRUCTOR_THROW" />
<Bug pattern="CT_CONSTRUCTOR_THROW"/>
</Match>

<!-- <Match>-->
Expand Down
41 changes: 20 additions & 21 deletions HIRS_Utils/src/main/java/hirs/utils/PciIds.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,40 +27,38 @@
@Log4j2
public final class PciIds {

/**
* Track status of pciids file.
*/
@Getter
private static String pciidsFileStatus = UefiConstants.FILESTATUS_NOT_ACCESSIBLE;

/**
* Name of pciids file in code.
*/
private static final String PCIIDS_FILENAME = "/pci.ids";

/**
* This pci ids file can be in different places on different distributions.
* Fedora/RHEL/Rocky/CentOS: /usr/share/hwdata/pci.ids
* Debian/Ubuntu: /usr/share/misc/pci.ids
* Fedora/RHEL/Rocky/CentOS: /usr/share/hwdata/pci.ids
* Debian/Ubuntu: /usr/share/misc/pci.ids
* If the file is not found on the system (such as with Windows systems),
* the file will have to be accessed from code.
*/
public static final List<String> PCI_IDS_PATH =
Collections.unmodifiableList(new ArrayList<>() {
private static final long serialVersionUID = 1L;

{
add("/usr/share/hwdata/pci.ids");
add("/usr/share/misc/pci.ids");
add("/tmp/pci.ids");
}
});

/**
* The PCI IDs Database object.
* This only needs to be loaded one time.
* The pci ids library protects the data inside the object by making it immutable.
*/
public static final PciIdsDatabase DB = new PciIdsDatabase();
/**
* Name of pciids file in code.
*/
private static final String PCIIDS_FILENAME = "/pci.ids";
/**
* Track status of pciids file.
*/
@Getter
private static String pciidsFileStatus = UefiConstants.FILESTATUS_NOT_ACCESSIBLE;

//Configure the PCI IDs Database object.
static {
Expand Down Expand Up @@ -124,7 +122,8 @@ public final class PciIds {
/**
* Default private constructor so checkstyles doesn't complain.
*/
private PciIds() { }
private PciIds() {
}

/**
* Look up the vendor name from the PCI IDs list, if the input string contains an ID.
Expand Down Expand Up @@ -172,7 +171,7 @@ public static String translateVendor(final String refManufacturer) {
* If any part of this fails, return the original model value.
*
* @param refManufacturer ASN1UTF8String, likely from a ComponentIdentifier
* @param refModel ASN1UTF8String, likely from a ComponentIdentifier
* @param refModel ASN1UTF8String, likely from a ComponentIdentifier
* @return ASN1UTF8String with the discovered device name, or the original model value.
*/
public static ASN1UTF8String translateDevice(final ASN1UTF8String refManufacturer,
Expand All @@ -199,7 +198,7 @@ public static ASN1UTF8String translateDevice(final ASN1UTF8String refManufacture
* If any part of this fails, return the original model value.
*
* @param refManufacturer String, likely from a ComponentResult
* @param refModel String, likely from a ComponentResult
* @param refModel String, likely from a ComponentResult
* @return String with the discovered device name, or the original model value.
*/
public static String translateDevice(final String refManufacturer,
Expand All @@ -224,10 +223,10 @@ public static String translateDevice(final String refManufacturer,
* If any part of this fails, return the original manufacturer value.
*
* @param refClassCode String, formatted as 2 characters (1 byte) for each of the 3 categories
* . Example "010802":
* . Class: "01"
* . Subclass: "08"
* . Programming Interface: "02"
* . Example "010802":
* . Class: "01"
* . Subclass: "08"
* . Programming Interface: "02"
* @return List<String> 3-element list with the class code
* . 1st element: human-readable description of Class
* . 2nd element: human-readable description of Subclass
Expand Down
26 changes: 13 additions & 13 deletions HIRS_Utils/src/main/java/hirs/utils/StringValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,20 @@ public final class StringValidator {
private final String fieldName;
private final Logger logger;

private StringValidator(final String value, final String fieldName, final Logger logger) {
this.value = value;
this.fieldName = fieldName;
if (logger == null) {
this.logger = log;
} else {
this.logger = logger;
}
}

/**
* Begins a validation operation.
*
* @param value the value to check
* @param value the value to check
* @param fieldName the name of the field (to be used in error reporting)
* @return a Validation object, upon which validation methods can be called
*/
Expand All @@ -31,26 +41,16 @@ public static StringValidator check(final String value, final String fieldName)
/**
* Begins a validation operation.
*
* @param value the value to check
* @param value the value to check
* @param fieldName the name of the field (to be used in error reporting)
* @param logger a logger to use in lieu of Validation's logger
* @param logger a logger to use in lieu of Validation's logger
* @return a Validation object, upon which validation methods can be called
*/
public static StringValidator check(final String value, final String fieldName,
final Logger logger) {
return new StringValidator(value, fieldName, logger);
}

private StringValidator(final String value, final String fieldName, final Logger logger) {
this.value = value;
this.fieldName = fieldName;
if (logger == null) {
this.logger = log;
} else {
this.logger = logger;
}
}

/**
* Assert that the given field is not null. Throws an IllegalArgumentException if the value
* is indeed null.
Expand Down
36 changes: 18 additions & 18 deletions HIRS_Utils/src/main/java/hirs/utils/digest/Digest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,14 @@ public final class Digest extends AbstractDigest {
DigestAlgorithm.SHA1,
new byte[SHA1_DIGEST_LENGTH]
);

private static final String SHA1_EMPTY_HEX =
"da39a3ee5e6b4b0d3255bfef95601890afd80709";

/**
* A SHA1 digest whose content is the hash of an empty buffer.
*/
public static final Digest SHA1_OF_NO_DATA;

private static final String SHA1_EMPTY_HEX =
"da39a3ee5e6b4b0d3255bfef95601890afd80709";

static {
try {
SHA1_OF_NO_DATA = new Digest(
Expand All @@ -59,17 +58,17 @@ public final class Digest extends AbstractDigest {
columnDefinition = "varbinary(64)")
private final byte[] digest;

@Getter
@XmlElement
@Column(nullable = false)
@Enumerated(EnumType.ORDINAL)
@Getter
private final DigestAlgorithm algorithm;

/**
* Creates a new <code>Digest</code>.
*
* @param algorithm algorithm used to generate the digest
* @param digest digest value
* @param digest digest value
* @throws IllegalArgumentException if digest length does not match that of the algorithm
*/
public Digest(final DigestAlgorithm algorithm, final byte[] digest)
Expand All @@ -81,6 +80,7 @@ public Digest(final DigestAlgorithm algorithm, final byte[] digest)

/**
* Creates a new <code>Digest</code> when an algorithm isn't specified.
*
* @param digest byte array value
*/
public Digest(final byte[] digest) {
Expand All @@ -90,11 +90,22 @@ public Digest(final byte[] digest) {
/**
* Default constructor necessary for Hibernate.
*/
protected Digest() {
private Digest() {
this.algorithm = null;
this.digest = null;
}

/**
* Helper method to reverse the toString method. Returns a Digest given a String
* that was created using an AbstractDigest's toString method.
*
* @param digest String representation of an AbstractDigest
* @return Digest object recreated from the String passed in
*/
public static Digest fromString(final String digest) {
return new Digest(algorithmFromString(digest), digestFromString(digest));
}

/**
* Retrieves the digest.
*
Expand All @@ -113,15 +124,4 @@ public byte[] getDigest() {
public OptionalDigest asOptionalDigest() {
return new OptionalDigest(algorithm, digest);
}

/**
* Helper method to reverse the toString method. Returns a Digest given a String
* that was created using an AbstractDigest's toString method.
*
* @param digest String representation of an AbstractDigest
* @return Digest object recreated from the String passed in
*/
public static Digest fromString(final String digest) {
return new Digest(algorithmFromString(digest), digestFromString(digest));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
/**
* Enumeration identifying the different outcomes of a comparison between
* two {@link Digest} objects.
*
*/
public enum DigestComparisonResultType {
/**
Expand Down
Loading

0 comments on commit 0f2a586

Please sign in to comment.