Checkstyle changes to SwidTagGateway

This commit is contained in:
chubtub 2024-11-18 14:06:10 -05:00
parent 198d6a54b8
commit 98a1d26f1d
2 changed files with 8 additions and 138 deletions

View File

@ -562,8 +562,11 @@ public class SwidTagGateway {
/**
* This method signs a SoftwareIdentity with an xmldsig in compatibility mode.
* Current assumptions: digest method SHA256, signature method SHA256, enveloped signature
*
* @param doc The document to sign
* @return Document the signed document
*/
private Document signXMLDocument(Document doc) {
private Document signXMLDocument(final Document doc) {
XMLSignatureFactory sigFactory = XMLSignatureFactory.getInstance("DOM");
List xmlObjectList = null;
String signatureId = null;
@ -681,7 +684,7 @@ public class SwidTagGateway {
* @param sigFactory the SignatureFactory object
* @return an XMLObject containing the timestamp element
*/
private XMLObject createXmlTimestamp(Document doc, XMLSignatureFactory sigFactory) {
private XMLObject createXmlTimestamp(final Document doc, final XMLSignatureFactory sigFactory) {
Element timeStampElement = null;
switch (timestampFormat.toUpperCase()) {
case "RFC3852":
@ -716,6 +719,9 @@ public class SwidTagGateway {
timestampArgument);
}
break;
default:
System.out.println("A timestamp format must be specified.");
System.exit(1);
}
DOMStructure timestampObject = new DOMStructure(timeStampElement);
SignatureProperty signatureProperty = sigFactory.newSignatureProperty(

View File

@ -1,136 +0,0 @@
package hirs.swid.utils;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
/**
*
*/
public class CsvParser {
private static final char DEFAULT_SEPARATOR = ',';
private static final char DEFAULT_QUOTE = '"';
private final List<String> content;
public CsvParser(final File file) {
this(file.getAbsolutePath());
}
public CsvParser(final String csvfile) {
content = readerCsv(csvfile);
}
public static List<String> parseLine(String csvLine) {
return parseLine(csvLine, DEFAULT_SEPARATOR, DEFAULT_QUOTE);
}
public static List<String> parseLine(String csvLine, char separators) {
return parseLine(csvLine, separators, DEFAULT_QUOTE);
}
public static List<String> parseLine(String csvLine, char separators, char customQuote) {
List<String> result = new ArrayList<>();
if (csvLine == null || csvLine.isEmpty()) {
return result;
}
if (customQuote == ' ') {
customQuote = DEFAULT_QUOTE;
}
if (separators == ' ') {
separators = DEFAULT_SEPARATOR;
}
StringBuilder currVal = new StringBuilder();
boolean inQuotes = false;
boolean startCollectChar = false;
boolean dbleQuotesInCol = false;
char[] chars = csvLine.toCharArray();
for (char ch : chars) {
if (inQuotes) {
startCollectChar = true;
if (ch == customQuote) {
inQuotes = false;
dbleQuotesInCol = false;
} else {
if (ch == '\"') {
if (!dbleQuotesInCol) {
currVal.append(ch);
dbleQuotesInCol = true;
}
} else {
currVal.append(ch);
}
}
} else {
if (ch == customQuote) {
inQuotes = true;
if (chars[0] != '"' && customQuote == '\"') {
currVal.append('"');
}
if (startCollectChar) {
currVal.append('"');
}
} else if (ch == separators) {
result.add(currVal.toString());
currVal = new StringBuilder();
startCollectChar = false;
} else if (ch == '\r') {
continue;
} else if (ch == '\n') {
break;
} else {
currVal.append(ch);
}
}
}
result.add(currVal.toString());
return result;
}
/**
* This method takes an existing csv file and reads the file by line and
* adds the contents to a list of Strings.
*
* @param file valid path to a csv file
* @return
*/
private List<String> readerCsv(final String file) {
String line = "";
String csvSplitBy = ",";
List<String> tempList = new LinkedList<>();
try (BufferedReader br = new BufferedReader(new FileReader(file))) {
while ((line = br.readLine()) != null) {
if (line.length() > 0
&& line.contains(csvSplitBy)) {
tempList.add(line);
}
}
} catch (IOException ioEx) {
System.out.printf("Error reading in CSV file...(%s)%n", file);
System.exit(1);
}
return tempList;
}
public final List<String> getContent() {
return Collections.unmodifiableList(content);
}
}