1/*
2 *  Licensed to the Apache Software Foundation (ASF) under one or more
3 *  contributor license agreements.  See the NOTICE file distributed with
4 *  this work for additional information regarding copyright ownership.
5 *  The ASF licenses this file to You under the Apache License, Version 2.0
6 *  (the "License"); you may not use this file except in compliance with
7 *  the License.  You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 *  Unless required by applicable law or agreed to in writing, software
12 *  distributed under the License is distributed on an "AS IS" BASIS,
13 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *  See the License for the specific language governing permissions and
15 *  limitations under the License.
16 */
17
18package java.security.cert;
19
20import java.math.BigInteger;
21import java.util.Arrays;
22import java.util.Date;
23import javax.security.auth.x500.X500Principal;
24
25/**
26 * Abstract base class for entries in a certificate revocation list (CRL).
27 *
28 * @see X509CRL
29 */
30public abstract class X509CRLEntry implements X509Extension {
31
32    /**
33     * Creates a new {@code X509CRLEntry} instance.
34     */
35    public X509CRLEntry() {}
36
37    /**
38     * Returns whether the specified object equals to this instance.
39     *
40     * @param other
41     *            the object to compare.
42     * @return {@code true} if the specified object equals to this instance,
43     *         otherwise {@code false}.
44     */
45    public boolean equals(Object other) {
46        if (other == this) {
47            return true;
48        }
49        if (!(other instanceof X509CRLEntry)) {
50            return false;
51        }
52        X509CRLEntry obj = (X509CRLEntry) other;
53        try {
54            return Arrays.equals(getEncoded(), obj.getEncoded());
55        } catch (CRLException e) {
56            return false;
57        }
58    }
59
60    /**
61     * Returns the hashcode of this instance.
62     *
63     * @return the hashcode of this instance.
64     */
65    public int hashCode() {
66        int res = 0;
67        try {
68            byte[] array = getEncoded();
69            for (int i=0; i<array.length; i++) {
70                res += array[i] & 0xFF;
71            }
72        } catch (CRLException e) {
73        }
74        return res;
75    }
76
77    /**
78     * Returns this entry in ASN.1 DER encoded form.
79     *
80     * @return the encoded form of this entry.
81     * @throws CRLException
82     *             if encoding fails.
83     */
84    public abstract byte[] getEncoded() throws CRLException;
85
86    /**
87     * Returns the serial number of the revoked certificate.
88     *
89     * @return the serial number of the revoked certificate.
90     */
91    public abstract BigInteger getSerialNumber();
92
93    /**
94     * Returns the issuer of the revoked certificate.
95     *
96     * @return the issuer of the revoked certificate, or {@code null} if the
97     *         issuer is equal to the CRL issuer.
98     */
99    public X500Principal getCertificateIssuer() {
100        return null;
101    }
102
103    /**
104     * Returns the date when the certificate is revoked.
105     *
106     * @return the date when the certificate is revoked.
107     */
108    public abstract Date getRevocationDate();
109
110    /**
111     * Returns whether this CRL entry has extensions.
112     *
113     * @return {@code true} is this CRL entry has extensions, otherwise {@code
114     *         false}.
115     */
116    public abstract boolean hasExtensions();
117
118    /**
119     * Returns a string representation of this instance.
120     *
121     * @return a string representation of this instance.
122     */
123    public abstract String toString();
124}
125
126