aboutsummaryrefslogtreecommitdiff
path: root/src/main/model/ca/Template.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/model/ca/Template.java')
-rw-r--r--src/main/model/ca/Template.java53
1 files changed, 22 insertions, 31 deletions
diff --git a/src/main/model/ca/Template.java b/src/main/model/ca/Template.java
index af751dc..84e639e 100644
--- a/src/main/model/ca/Template.java
+++ b/src/main/model/ca/Template.java
@@ -16,22 +16,33 @@ public class Template {
/**
* Name of the template.
*/
- private String name;
+ private final String name;
/**
* Whether the template is usable or not.
*/
- private boolean enabled;
+ private final boolean enabled;
/**
* Subject of the issued certs. Null -> unspecified
*/
- private Name subject;
+ private final Name subject;
/**
* Length of validity in days since the point of issue.
*/
- private long validity;
+ private final long validity;
+
+ /**
+ * EFFECTS: Init with all given parameters, and commonName will be converted into CN=commonName,C=CA.
+ * Throws {@link ParseException} if the commonName is invalid.
+ */
+ public Template(String name,
+ boolean enabled,
+ String commonName,
+ long validity) throws ParseException {
+ this(name, enabled, parseString(commonName), validity);
+ }
/**
* EFFECTS: Init with all given parameters.
@@ -51,36 +62,24 @@ public class Template {
return name;
}
- public void setName(String name) {
- this.name = name;
- }
-
public boolean isEnabled() {
return enabled;
}
- public void setEnabled(boolean enabled) {
- this.enabled = enabled;
- }
-
public Name getSubject() {
return subject;
}
- public void setSubject(Name subject) {
- this.subject = subject;
+ public long getValidity() {
+ return validity;
}
/**
- * EFFECTS: Set the subject to CN=commonName,C=CA
- * Throws {@link ParseException} if commonName is not a valid PrintableString
+ * EFFECTS: Convert the given commonName to RDN of CN=commonName,C=CA
+ * Throws {@link ParseException} if the given commonName is invalid.
*/
- public void setSubject(String commonName) throws ParseException {
- if (commonName == null) {
- this.subject = null;
- return;
- }
- setSubject(new Name(ASN1Object.TAG_SEQUENCE, null, new RelativeDistinguishedName[]{
+ private static Name parseString(String commonName) throws ParseException {
+ return new Name(ASN1Object.TAG_SEQUENCE, null, new RelativeDistinguishedName[]{
new RelativeDistinguishedName(ASN1Object.TAG_SET, null, new AttributeTypeAndValue[]{
new AttributeTypeAndValue(ASN1Object.TAG_SEQUENCE, null,
new ObjectIdentifier(ObjectIdentifier.TAG, null,
@@ -90,14 +89,6 @@ public class Template {
new AttributeTypeAndValue(ASN1Object.TAG_SEQUENCE, null,
new ObjectIdentifier(ObjectIdentifier.TAG, null,
ObjectIdentifier.OID_C),
- new PrintableString(PrintableString.TAG, null, "CA"))})}));
- }
-
- public long getValidity() {
- return validity;
- }
-
- public void setValidity(long validity) {
- this.validity = validity;
+ new PrintableString(PrintableString.TAG, null, "CA"))})});
}
}