aboutsummaryrefslogtreecommitdiff
path: root/src/main/ui
diff options
context:
space:
mode:
authorYuuta Liang <yuutaw@students.cs.ubc.ca>2023-10-14 05:35:17 +0800
committerYuuta Liang <yuutaw@students.cs.ubc.ca>2023-10-14 05:35:17 +0800
commit28fa18278c1f3a87722d5e8b78f581526a30bb38 (patch)
tree2f23f6e2e222a78f40809ec37e8b28a29cba3d3c /src/main/ui
parent0bcc057e741af3fbc108f42b75f9d42f48f6a51e (diff)
downloadjca-28fa18278c1f3a87722d5e8b78f581526a30bb38.tar
jca-28fa18278c1f3a87722d5e8b78f581526a30bb38.tar.gz
jca-28fa18278c1f3a87722d5e8b78f581526a30bb38.tar.bz2
jca-28fa18278c1f3a87722d5e8b78f581526a30bb38.zip
Fix lint
Signed-off-by: Yuuta Liang <yuutaw@students.cs.ubc.ca>
Diffstat (limited to 'src/main/ui')
-rw-r--r--src/main/ui/IssueScreen.java1
-rw-r--r--src/main/ui/JCA.java68
-rw-r--r--src/main/ui/MainScreen.java12
-rw-r--r--src/main/ui/Utils.java8
4 files changed, 44 insertions, 45 deletions
diff --git a/src/main/ui/IssueScreen.java b/src/main/ui/IssueScreen.java
index e152b0d..93e1948 100644
--- a/src/main/ui/IssueScreen.java
+++ b/src/main/ui/IssueScreen.java
@@ -1,7 +1,6 @@
package ui;
import model.asn1.exceptions.ParseException;
-import model.asn1.parsing.BytesReader;
import model.ca.Template;
import model.csr.CertificationRequest;
import model.pki.cert.Certificate;
diff --git a/src/main/ui/JCA.java b/src/main/ui/JCA.java
index f9467ea..7892850 100644
--- a/src/main/ui/JCA.java
+++ b/src/main/ui/JCA.java
@@ -8,18 +8,16 @@ import model.ca.Template;
import java.nio.charset.StandardCharsets;
import java.security.NoSuchAlgorithmException;
import java.time.ZonedDateTime;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+import java.util.Scanner;
/**
* Main program
*/
public class JCA {
/**
- * The current screen.
- */
- private UIHandler screen;
-
- /**
* Instances of the five screens;
*/
private final UIHandler mainScreen;
@@ -27,30 +25,30 @@ public class JCA {
private final UIHandler issueScreen;
private final UIHandler templatesScreen;
private final UIHandler templateSetScreen;
-
/**
* Templates
*/
private final List<Template> templates;
-
/**
* The CA
*/
private final CACertificate ca;
-
/**
* Audit logs
*/
private final List<AuditLogEntry> logs;
-
/**
* Current user
*/
private final String user;
+ /**
+ * The current screen.
+ */
+ private UIHandler screen;
/**
* EFFECTS: Init with main screen, empty templates, logs, user 'yuuta', and generate a private key with no CA cert.
- * Throws {@link NoSuchAlgorithmException} when crypto issue happens.
+ * Throws {@link NoSuchAlgorithmException} when crypto issue happens.
*/
public JCA() throws NoSuchAlgorithmException {
this.mainScreen = new MainScreen(this);
@@ -86,7 +84,7 @@ public class JCA {
/**
* EFFECTS: Read PEM from stdin, matched the given tag.
- * Throws {@link ParseException} if the input is incorrect.
+ * Throws {@link ParseException} if the input is incorrect.
*/
public Byte[] handleInputPEM(String desiredTag) throws ParseException {
final Scanner scanner = new Scanner(System.in);
@@ -144,24 +142,27 @@ public class JCA {
}
private void handleLine(String... args) {
- if (!args[0].isBlank()) {
- switch (args[0]) {
- case "help":
- screen.help();
- break;
- case "show":
- screen.show();
- break;
- case "commit":
- screen.commit();
- break;
- case "exit":
- setScreen(screen.exit());
- break;
- default:
- screen.command(args);
- break;
- }
+ if (args[0].equals("log")) {
+ getLogs().forEach(System.out::println);
+ return;
+ }
+ switch (args[0]) {
+ case "help":
+ screen.help();
+ System.out.println("log\tView audit logs");
+ break;
+ case "show":
+ screen.show();
+ break;
+ case "commit":
+ screen.commit();
+ break;
+ case "exit":
+ setScreen(screen.exit());
+ break;
+ default:
+ screen.command(args);
+ break;
}
printPS1();
}
@@ -185,7 +186,12 @@ public class JCA {
printPS1();
final Scanner scanner = new Scanner(System.in);
while (true) {
- handleLine(scanner.nextLine().split(" "));
+ String[] args = scanner.nextLine().split(" ");
+ if (args.length <= 0 || args[0].isBlank()) {
+ printPS1();
+ continue;
+ }
+ handleLine(args);
}
}
diff --git a/src/main/ui/MainScreen.java b/src/main/ui/MainScreen.java
index 69cb32c..f6abf8b 100644
--- a/src/main/ui/MainScreen.java
+++ b/src/main/ui/MainScreen.java
@@ -10,7 +10,10 @@ import model.pki.cert.Certificate;
import model.pki.crl.Reason;
import model.pki.crl.RevokedCertificate;
-import java.io.*;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Optional;
@@ -156,10 +159,6 @@ public class MainScreen implements UIHandler {
}
}
- private void handleLog() {
- session.getLogs().forEach(System.out::println);
- }
-
@Override
public void command(String... args) {
switch (args[0]) {
@@ -181,9 +180,6 @@ public class MainScreen implements UIHandler {
case "crl":
handleCRL();
return;
- case "log":
- handleLog();
- return;
}
help();
}
diff --git a/src/main/ui/Utils.java b/src/main/ui/Utils.java
index 3ed1300..6841536 100644
--- a/src/main/ui/Utils.java
+++ b/src/main/ui/Utils.java
@@ -4,11 +4,9 @@ import model.asn1.exceptions.ParseException;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
-import java.util.Arrays;
import java.util.Base64;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import java.util.stream.Collectors;
/**
* Useful small methods for the whole program.
@@ -38,7 +36,7 @@ public final class Utils {
/**
* EFFECTS: Pack the big-endian bytes into a 32bit integer.
- * Throws {@link model.asn1.exceptions.ParseException} if the value is too large.
+ * Throws {@link model.asn1.exceptions.ParseException} if the value is too large.
*/
public static int bytesToInt(Byte[] array) throws ParseException {
try {
@@ -68,8 +66,8 @@ public final class Utils {
/**
* EFFECTS: Decode the input PEM file, with optional check on tags. \n must present after each line, optional after
* the last.
- * Throws {@link ParseException} if the desiredTag is specified but the input does not have the specific tag, or
- * if the input does not have any tags at all (not a PEM).
+ * Throws {@link ParseException} if the desiredTag is specified but the input does not have the specific tag, or
+ * if the input does not have any tags at all (not a PEM).
*/
public static Byte[] parsePEM(Byte[] input, String desiredTag) throws ParseException {
final String str = new String(byteToByte(input), StandardCharsets.UTF_8);