8296143: CertAttrSet's set/get mechanism is not type-safe

Reviewed-by: mullan
This commit is contained in:
Weijun Wang 2022-11-08 22:35:29 +00:00
parent d04d6566b0
commit 671f84bd86
66 changed files with 643 additions and 2902 deletions

View file

@ -37,18 +37,9 @@ import sun.security.util.*;
* @author Hemma Prafullchandra
* @see CertAttrSet
*/
public class CertificateValidity implements CertAttrSet<String> {
/**
* Identifier for this attribute, to be used with the
* get, set, delete methods of Certificate, x509 type.
*/
public static final String IDENT = "x509.info.validity";
/**
* Sub attributes name for this CertAttrSet.
*/
public class CertificateValidity implements CertAttrSet {
public static final String NAME = "validity";
public static final String NOT_BEFORE = "notBefore";
public static final String NOT_AFTER = "notAfter";
/**
* YR_2050 date and time set to Jan01 00:00 2050 GMT
*/
@ -59,13 +50,13 @@ public class CertificateValidity implements CertAttrSet<String> {
private Date notAfter;
// Returns the first time the certificate is valid.
private Date getNotBefore() {
return (new Date(notBefore.getTime()));
public Date getNotBefore() {
return new Date(notBefore.getTime());
}
// Returns the last time the certificate is valid.
private Date getNotAfter() {
return (new Date(notAfter.getTime()));
public Date getNotAfter() {
return new Date(notAfter.getTime());
}
// Construct the class from the DerValue
@ -169,37 +160,6 @@ public class CertificateValidity implements CertAttrSet<String> {
out.write(DerValue.tag_Sequence, pair);
}
/**
* Set the attribute value.
*/
public void set(String name, Object obj) throws IOException {
if (!(obj instanceof Date)) {
throw new IOException("Attribute must be of type Date.");
}
if (name.equalsIgnoreCase(NOT_BEFORE)) {
notBefore = (Date)obj;
} else if (name.equalsIgnoreCase(NOT_AFTER)) {
notAfter = (Date)obj;
} else {
throw new IOException("Attribute name not recognized by " +
"CertAttrSet: CertificateValidity.");
}
}
/**
* Get the attribute value.
*/
public Date get(String name) throws IOException {
if (name.equalsIgnoreCase(NOT_BEFORE)) {
return (getNotBefore());
} else if (name.equalsIgnoreCase(NOT_AFTER)) {
return (getNotAfter());
} else {
throw new IOException("Attribute name not recognized by " +
"CertAttrSet: CertificateValidity.");
}
}
/**
* Verify that the current time is within the validity period.
*