From 98a1d26f1ddaf8a3f61fefb86c893a90e8925bd2 Mon Sep 17 00:00:00 2001
From: chubtub <43381989+chubtub@users.noreply.github.com>
Date: Mon, 18 Nov 2024 14:06:10 -0500
Subject: [PATCH] Checkstyle changes to SwidTagGateway

---
 .../main/java/hirs/swid/SwidTagGateway.java   |  10 +-
 .../main/java/hirs/swid/utils/CsvParser.java  | 136 ------------------
 2 files changed, 8 insertions(+), 138 deletions(-)
 delete mode 100644 tools/tcg_rim_tool/src/main/java/hirs/swid/utils/CsvParser.java

diff --git a/tools/tcg_rim_tool/src/main/java/hirs/swid/SwidTagGateway.java b/tools/tcg_rim_tool/src/main/java/hirs/swid/SwidTagGateway.java
index 9ed06075..c449bd3d 100644
--- a/tools/tcg_rim_tool/src/main/java/hirs/swid/SwidTagGateway.java
+++ b/tools/tcg_rim_tool/src/main/java/hirs/swid/SwidTagGateway.java
@@ -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(
diff --git a/tools/tcg_rim_tool/src/main/java/hirs/swid/utils/CsvParser.java b/tools/tcg_rim_tool/src/main/java/hirs/swid/utils/CsvParser.java
deleted file mode 100644
index 0da57b2f..00000000
--- a/tools/tcg_rim_tool/src/main/java/hirs/swid/utils/CsvParser.java
+++ /dev/null
@@ -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);
-    }
-}