diff options
author | Yuuta Liang <yuutaw@student.cs.ubc.ca> | 2023-10-25 03:30:45 +0800 |
---|---|---|
committer | Yuuta Liang <yuutaw@student.cs.ubc.ca> | 2023-10-25 03:30:45 +0800 |
commit | d7ff9d5e217873609d79efe279f2634e3a3dd8b4 (patch) | |
tree | 704729e5eed658728b521acd407c6ca767f7e865 /src/main/model/asn1 | |
parent | 55df54e5dbf26e6824123410784d00aa793c3781 (diff) | |
download | jca-d7ff9d5e217873609d79efe279f2634e3a3dd8b4.tar jca-d7ff9d5e217873609d79efe279f2634e3a3dd8b4.tar.gz jca-d7ff9d5e217873609d79efe279f2634e3a3dd8b4.tar.bz2 jca-d7ff9d5e217873609d79efe279f2634e3a3dd8b4.zip |
Refactor: move all logics into CertificationAuthority
Signed-off-by: Yuuta Liang <yuutaw@student.cs.ubc.ca>
Diffstat (limited to 'src/main/model/asn1')
-rw-r--r-- | src/main/model/asn1/ASN1Time.java | 2 | ||||
-rw-r--r-- | src/main/model/asn1/GeneralizedTime.java | 10 | ||||
-rw-r--r-- | src/main/model/asn1/UtcTime.java | 10 | ||||
-rw-r--r-- | src/main/model/asn1/exceptions/InvalidCAException.java | 10 |
4 files changed, 21 insertions, 11 deletions
diff --git a/src/main/model/asn1/ASN1Time.java b/src/main/model/asn1/ASN1Time.java index 8f386f5..94e58b3 100644 --- a/src/main/model/asn1/ASN1Time.java +++ b/src/main/model/asn1/ASN1Time.java @@ -15,7 +15,7 @@ public abstract class ASN1Time extends ASN1Object { /** * The time. */ - private ZonedDateTime timestamp; + private final ZonedDateTime timestamp; /** * EFFECTS: Initialize the time with the specific tag, parentTag, and timestamp. For tag and parentTag, consult diff --git a/src/main/model/asn1/GeneralizedTime.java b/src/main/model/asn1/GeneralizedTime.java index 5482906..c97a51b 100644 --- a/src/main/model/asn1/GeneralizedTime.java +++ b/src/main/model/asn1/GeneralizedTime.java @@ -22,7 +22,7 @@ public class GeneralizedTime extends ASN1Time { /** * Rather stupid impl ... */ - private static final DateTimeFormatter formatterNoSecs = new DateTimeFormatterBuilder() + private static final DateTimeFormatter FORMATTER_NO_SECS = new DateTimeFormatterBuilder() .appendValue(ChronoField.YEAR, 4) .appendValue(ChronoField.MONTH_OF_YEAR, 2) .appendValue(ChronoField.DAY_OF_MONTH, 2) @@ -32,7 +32,7 @@ public class GeneralizedTime extends ASN1Time { .toFormatter() .withZone(ZoneId.of("UTC")); - private static final DateTimeFormatter formatter = new DateTimeFormatterBuilder() + private static final DateTimeFormatter FORMATTER = new DateTimeFormatterBuilder() .appendValue(ChronoField.YEAR, 4) .appendValue(ChronoField.MONTH_OF_YEAR, 2) .appendValue(ChronoField.DAY_OF_MONTH, 2) @@ -71,7 +71,7 @@ public class GeneralizedTime extends ASN1Time { @Override public ZonedDateTime toDate(String str) throws ParseException { try { - return ZonedDateTime.parse(str, formatter); + return ZonedDateTime.parse(str, FORMATTER); } catch (DateTimeParseException e) { throw new ParseException(e.getMessage()); } @@ -83,8 +83,8 @@ public class GeneralizedTime extends ASN1Time { @Override public String toString() { if (getTimestamp().getSecond() == 0) { - return getTimestamp().format(formatterNoSecs); + return getTimestamp().format(FORMATTER_NO_SECS); } - return getTimestamp().format(formatter); + return getTimestamp().format(FORMATTER); } } diff --git a/src/main/model/asn1/UtcTime.java b/src/main/model/asn1/UtcTime.java index 7fa93d1..54b7a5a 100644 --- a/src/main/model/asn1/UtcTime.java +++ b/src/main/model/asn1/UtcTime.java @@ -23,7 +23,7 @@ public class UtcTime extends ASN1Time { /** * Rather stupid impl ... */ - private static final DateTimeFormatter formatterNoSecs = new DateTimeFormatterBuilder() + private static final DateTimeFormatter FORMATTER_NO_SECS = new DateTimeFormatterBuilder() .appendPattern("yy") .appendValue(ChronoField.MONTH_OF_YEAR, 2) .appendValue(ChronoField.DAY_OF_MONTH, 2) @@ -33,7 +33,7 @@ public class UtcTime extends ASN1Time { .toFormatter() .withZone(ZoneId.of("UTC")); - private static final DateTimeFormatter formatter = new DateTimeFormatterBuilder() + private static final DateTimeFormatter FORMATTER = new DateTimeFormatterBuilder() .appendPattern("yy") .appendValue(ChronoField.MONTH_OF_YEAR, 2) .appendValue(ChronoField.DAY_OF_MONTH, 2) @@ -72,7 +72,7 @@ public class UtcTime extends ASN1Time { @Override public ZonedDateTime toDate(String str) throws ParseException { try { - return ZonedDateTime.parse(str, formatter); + return ZonedDateTime.parse(str, FORMATTER); } catch (DateTimeParseException e) { throw new ParseException(e.getMessage()); } @@ -84,8 +84,8 @@ public class UtcTime extends ASN1Time { @Override public String toString() { if (getTimestamp().getSecond() == 0) { - return getTimestamp().format(formatterNoSecs); + return getTimestamp().format(FORMATTER_NO_SECS); } - return getTimestamp().format(formatter); + return getTimestamp().format(FORMATTER); } } diff --git a/src/main/model/asn1/exceptions/InvalidCAException.java b/src/main/model/asn1/exceptions/InvalidCAException.java new file mode 100644 index 0000000..e487509 --- /dev/null +++ b/src/main/model/asn1/exceptions/InvalidCAException.java @@ -0,0 +1,10 @@ +package model.asn1.exceptions; + +/** + * Indicate the error that the CA being installed is invalid. + */ +public class InvalidCAException extends Exception { + public InvalidCAException(String message) { + super(message); + } +} |