001: /*
002: * @(#)X509CRLEntry.java 1.18 06/10/10
003: *
004: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: *
026: */
027:
028: package java.security.cert;
029:
030: import java.math.BigInteger;
031: import java.util.Date;
032: import java.util.Set;
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.12 00/02/02
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: * Gets the revocation date from this X509CRLEntry,
139: * the <em>revocationDate</em>.
140: *
141: * @return the revocation date.
142: */
143: public abstract Date getRevocationDate();
144:
145: /**
146: * Returns true if this CRL entry has extensions.
147: *
148: * @return true if this entry has extensions, false otherwise.
149: */
150: public abstract boolean hasExtensions();
151:
152: /**
153: * Returns a string representation of this CRL entry.
154: *
155: * @return a string representation of this CRL entry.
156: */
157: public abstract String toString();
158: }
|