001 /*
002 * Copyright 1997-2003 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025
026 package java.security.cert;
027
028 import java.math.BigInteger;
029 import java.util.Date;
030 import java.util.Set;
031
032 import javax.security.auth.x500.X500Principal;
033
034 /**
035 * <p>Abstract class for a revoked certificate in a CRL (Certificate
036 * Revocation List).
037 *
038 * The ASN.1 definition for <em>revokedCertificates</em> is:
039 * <pre>
040 * revokedCertificates SEQUENCE OF SEQUENCE {
041 * userCertificate CertificateSerialNumber,
042 * revocationDate ChoiceOfTime,
043 * crlEntryExtensions Extensions OPTIONAL
044 * -- if present, must be v2
045 * } OPTIONAL
046 *<p>
047 * CertificateSerialNumber ::= INTEGER
048 *<p>
049 * Extensions ::= SEQUENCE SIZE (1..MAX) OF Extension
050 *<p>
051 * Extension ::= SEQUENCE {
052 * extnId OBJECT IDENTIFIER,
053 * critical BOOLEAN DEFAULT FALSE,
054 * extnValue OCTET STRING
055 * -- contains a DER encoding of a value
056 * -- of the type registered for use with
057 * -- the extnId object identifier value
058 * }
059 * </pre>
060 *
061 * @see X509CRL
062 * @see X509Extension
063 *
064 * @author Hemma Prafullchandra
065 * @version 1.23 07/05/05
066 */
067
068 public abstract class X509CRLEntry implements X509Extension {
069
070 /**
071 * Compares this CRL entry for equality with the given
072 * object. If the <code>other</code> object is an
073 * <code>instanceof</code> <code>X509CRLEntry</code>, then
074 * its encoded form (the inner SEQUENCE) is retrieved and compared
075 * with the encoded form of this CRL entry.
076 *
077 * @param other the object to test for equality with this CRL entry.
078 * @return true iff the encoded forms of the two CRL entries
079 * match, false otherwise.
080 */
081 public boolean equals(Object other) {
082 if (this == other)
083 return true;
084 if (!(other instanceof X509CRLEntry))
085 return false;
086 try {
087 byte[] this CRLEntry = this .getEncoded();
088 byte[] otherCRLEntry = ((X509CRLEntry) other).getEncoded();
089
090 if (this CRLEntry.length != otherCRLEntry.length)
091 return false;
092 for (int i = 0; i < this CRLEntry.length; i++)
093 if (this CRLEntry[i] != otherCRLEntry[i])
094 return false;
095 } catch (CRLException ce) {
096 return false;
097 }
098 return true;
099 }
100
101 /**
102 * Returns a hashcode value for this CRL entry from its
103 * encoded form.
104 *
105 * @return the hashcode value.
106 */
107 public int hashCode() {
108 int retval = 0;
109 try {
110 byte[] entryData = this .getEncoded();
111 for (int i = 1; i < entryData.length; i++)
112 retval += entryData[i] * i;
113
114 } catch (CRLException ce) {
115 return (retval);
116 }
117 return (retval);
118 }
119
120 /**
121 * Returns the ASN.1 DER-encoded form of this CRL Entry,
122 * that is the inner SEQUENCE.
123 *
124 * @return the encoded form of this certificate
125 * @exception CRLException if an encoding error occurs.
126 */
127 public abstract byte[] getEncoded() throws CRLException;
128
129 /**
130 * Gets the serial number from this X509CRLEntry,
131 * the <em>userCertificate</em>.
132 *
133 * @return the serial number.
134 */
135 public abstract BigInteger getSerialNumber();
136
137 /**
138 * Get the issuer of the X509Certificate described by this entry. If
139 * the certificate issuer is also the CRL issuer, this method returns
140 * null.
141 *
142 * <p>This method is used with indirect CRLs. The default implementation
143 * always returns null. Subclasses that wish to support indirect CRLs
144 * should override it.
145 *
146 * @return the issuer of the X509Certificate described by this entry
147 * or null if it is issued by the CRL issuer.
148 *
149 * @since 1.5
150 */
151 public X500Principal getCertificateIssuer() {
152 return null;
153 }
154
155 /**
156 * Gets the revocation date from this X509CRLEntry,
157 * the <em>revocationDate</em>.
158 *
159 * @return the revocation date.
160 */
161 public abstract Date getRevocationDate();
162
163 /**
164 * Returns true if this CRL entry has extensions.
165 *
166 * @return true if this entry has extensions, false otherwise.
167 */
168 public abstract boolean hasExtensions();
169
170 /**
171 * Returns a string representation of this CRL entry.
172 *
173 * @return a string representation of this CRL entry.
174 */
175 public abstract String toString();
176 }
|