diff options
Diffstat (limited to 'pki/base/util/src/netscape/security/x509/CertificateValidity.java')
-rw-r--r-- | pki/base/util/src/netscape/security/x509/CertificateValidity.java | 117 |
1 files changed, 58 insertions, 59 deletions
diff --git a/pki/base/util/src/netscape/security/x509/CertificateValidity.java b/pki/base/util/src/netscape/security/x509/CertificateValidity.java index 89b665f4..e0b26428 100644 --- a/pki/base/util/src/netscape/security/x509/CertificateValidity.java +++ b/pki/base/util/src/netscape/security/x509/CertificateValidity.java @@ -35,7 +35,7 @@ import netscape.security.util.DerValue; /** * This class defines the interval for which the certificate is valid. - * + * * @author Amit Kapoor * @author Hemma Prafullchandra * @version 1.12 @@ -47,9 +47,9 @@ public class CertificateValidity implements CertAttrSet, Serializable { */ private static final long serialVersionUID = 8277703278213804194L; /** - * Identifier for this attribute, to be used with the get, set, delete - * methods of Certificate, x509 type. - */ + * 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. @@ -60,24 +60,24 @@ public class CertificateValidity implements CertAttrSet, Serializable { private static final long YR_2050 = 2524636800000L; // Private data members - private Date notBefore; - private Date notAfter; + private Date notBefore; + private Date notAfter; // Returns the first time the certificate is valid. - private Date getNotBefore() { + private Date getNotBefore() { return (new Date(notBefore.getTime())); } // Returns the last time the certificate is valid. private Date getNotAfter() { - return (new Date(notAfter.getTime())); + return (new Date(notAfter.getTime())); } // Construct the class from the DerValue private void construct(DerValue derVal) throws IOException { if (derVal.tag != DerValue.tag_Sequence) { - throw new IOException("Invalid encoded CertificateValidity, " - + "starting sequence tag missing."); + throw new IOException("Invalid encoded CertificateValidity, " + + "starting sequence tag missing."); } // check if UTCTime encoded or GeneralizedTime if (derVal.data.available() == 0) @@ -108,16 +108,15 @@ public class CertificateValidity implements CertAttrSet, Serializable { /** * Default constructor for the class. */ - public CertificateValidity() { - } + public CertificateValidity() { } /** * The default constructor for this class for the specified interval. - * - * @param notBefore the date and time before which the certificate is not - * valid. - * @param notAfter the date and time after which the certificate is not - * valid. + * + * @param notBefore the date and time before which the certificate + * is not valid. + * @param notAfter the date and time after which the certificate is + * not valid. */ public CertificateValidity(Date notBefore, Date notAfter) { this.notBefore = notBefore; @@ -126,7 +125,7 @@ public class CertificateValidity implements CertAttrSet, Serializable { /** * Create the object, decoding the values from the passed DER stream. - * + * * @param in the DerInputStream to read the CertificateValidity from. * @exception IOException on decoding errors. */ @@ -141,13 +140,13 @@ public class CertificateValidity implements CertAttrSet, Serializable { public String toString() { if (notBefore == null || notAfter == null) return ""; - return ("Validity: [From: " + notBefore.toString() - + ",\n To: " + notAfter.toString() + "]"); + return ("Validity: [From: " + notBefore.toString() + + ",\n To: " + notAfter.toString() + "]"); } /** * Decode the CertificateValidity period from the InputStream. - * + * * @param in the InputStream to unmarshal the contents from. * @exception IOException on errors. */ @@ -157,18 +156,18 @@ public class CertificateValidity implements CertAttrSet, Serializable { } private synchronized void writeObject(ObjectOutputStream stream) - throws IOException { + throws IOException { encode(stream); } private synchronized void readObject(ObjectInputStream stream) - throws IOException { - decode(stream); + throws IOException { + decode(stream); } /** * Encode the CertificateValidity period in DER form to the stream. - * + * * @param out the OutputStream to marshal the contents to. * @exception IOException on errors. */ @@ -177,13 +176,13 @@ public class CertificateValidity implements CertAttrSet, Serializable { // in cases where default constructor is used check for // null values if (notBefore == null || notAfter == null) { - throw new IOException("CertAttrSet:CertificateValidity:" - + " null values to encode.\n"); + throw new IOException("CertAttrSet:CertificateValidity:" + + " null values to encode.\n"); } DerOutputStream pair = new DerOutputStream(); if (notBefore.getTime() < YR_2050) { - pair.putUTCTime(notBefore); + pair.putUTCTime(notBefore); } else pair.putGeneralizedTime(notBefore); @@ -193,7 +192,7 @@ public class CertificateValidity implements CertAttrSet, Serializable { pair.putGeneralizedTime(notAfter); } DerOutputStream seq = new DerOutputStream(); - seq.write(DerValue.tag_Sequence, pair); + seq.write(DerValue.tag_Sequence,pair); out.write(seq.toByteArray()); } @@ -206,12 +205,12 @@ public class CertificateValidity implements CertAttrSet, Serializable { throw new IOException("Attribute must be of type Date."); } if (name.equalsIgnoreCase(NOT_BEFORE)) { - notBefore = (Date) obj; + notBefore = (Date)obj; } else if (name.equalsIgnoreCase(NOT_AFTER)) { - notAfter = (Date) obj; + notAfter = (Date)obj; } else { - throw new IOException("Attribute name not recognized by " - + "CertAttrSet: CertificateValidity."); + throw new IOException("Attribute name not recognized by " + + "CertAttrSet: CertificateValidity."); } } @@ -224,8 +223,8 @@ public class CertificateValidity implements CertAttrSet, Serializable { } else if (name.equalsIgnoreCase(NOT_AFTER)) { return (getNotAfter()); } else { - throw new IOException("Attribute name not recognized by " - + "CertAttrSet: CertificateValidity."); + throw new IOException("Attribute name not recognized by " + + "CertAttrSet: CertificateValidity."); } } @@ -238,8 +237,8 @@ public class CertificateValidity implements CertAttrSet, Serializable { } else if (name.equalsIgnoreCase(NOT_AFTER)) { notAfter = null; } else { - throw new IOException("Attribute name not recognized by " - + "CertAttrSet: CertificateValidity."); + throw new IOException("Attribute name not recognized by " + + "CertAttrSet: CertificateValidity."); } } @@ -251,10 +250,10 @@ public class CertificateValidity implements CertAttrSet, Serializable { Vector<String> elements = new Vector<String>(); elements.addElement(NOT_BEFORE); elements.addElement(NOT_AFTER); - + return (elements.elements()); } - + /** * Return the name of this attribute. */ @@ -264,42 +263,42 @@ public class CertificateValidity implements CertAttrSet, Serializable { /** * Verify that the current time is within the validity period. - * + * * @exception CertificateExpiredException if the certificate has expired. - * @exception CertificateNotYetValidException if the certificate is not yet - * valid. + * @exception CertificateNotYetValidException if the certificate is not + * yet valid. */ - public void valid() throws CertificateNotYetValidException, - CertificateExpiredException { + public void valid() + throws CertificateNotYetValidException, CertificateExpiredException { Date now = new Date(); valid(now); } /** * Verify that the passed time is within the validity period. - * - * @param now the Date against which to compare the validity period. - * + * @param now the Date against which to compare the validity + * period. + * * @exception CertificateExpiredException if the certificate has expired - * with respect to the <code>Date</code> supplied. - * @exception CertificateNotYetValidException if the certificate is not yet - * valid with respect to the <code>Date</code> supplied. + * with respect to the <code>Date</code> supplied. + * @exception CertificateNotYetValidException if the certificate is not + * yet valid with respect to the <code>Date</code> supplied. * */ - public void valid(Date now) throws CertificateNotYetValidException, - CertificateExpiredException { + public void valid(Date now) + throws CertificateNotYetValidException, CertificateExpiredException { /* - * we use the internal Dates rather than the passed in Date because - * someone could override the Date methods after() and before() to do - * something entirely different. + * we use the internal Dates rather than the passed in Date + * because someone could override the Date methods after() + * and before() to do something entirely different. */ if (notBefore.after(now)) { - throw new CertificateNotYetValidException("NotBefore: " - + notBefore.toString()); + throw new CertificateNotYetValidException("NotBefore: " + + notBefore.toString()); } if (notAfter.before(now)) { - throw new CertificateExpiredException("NotAfter: " - + notAfter.toString()); + throw new CertificateExpiredException("NotAfter: " + + notAfter.toString()); } } } |