001 /* Certificate.java -- base class of public-key certificates.
002 Copyright (C) 2004 Free Software Foundation, Inc.
003
004 This file is part of GNU Classpath.
005
006 GNU Classpath is free software; you can redistribute it and/or modify
007 it under the terms of the GNU General Public License as published by
008 the Free Software Foundation; either version 2, or (at your option)
009 any later version.
010
011 GNU Classpath 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 for more details.
015
016 You should have received a copy of the GNU General Public License
017 along with GNU Classpath; see the file COPYING. If not, write to the
018 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
019 02110-1301 USA.
020
021 Linking this library statically or dynamically with other modules is
022 making a combined work based on this library. Thus, the terms and
023 conditions of the GNU General Public License cover the whole
024 combination.
025
026 As a special exception, the copyright holders of this library give you
027 permission to link this library with independent modules to produce an
028 executable, regardless of the license terms of these independent
029 modules, and to copy and distribute the resulting executable under
030 terms of your choice, provided that you also meet, for each linked
031 independent module, the terms and conditions of the license of that
032 module. An independent module is a module which is not derived from
033 or based on this library. If you modify this library, you may extend
034 this exception to your version of the library, but you are not
035 obligated to do so. If you do not wish to do so, delete this
036 exception statement from your version. */
037
038
039 package javax.security.cert;
040
041 import java.security.InvalidKeyException;
042 import java.security.NoSuchAlgorithmException;
043 import java.security.NoSuchProviderException;
044 import java.security.PublicKey;
045 import java.security.SignatureException;
046
047 import java.util.Arrays;
048 import java.util.zip.Adler32;
049
050 /**
051 * <p>The base class for public-key certificates.</p>
052 *
053 * <p><b>This class is deprecated in favor of the {@link
054 * java.security.cert.Certificate} class. It should not be used in new
055 * applications.</b></p>
056 */
057 public abstract class Certificate
058 {
059
060 // Constructors.
061 // -------------------------------------------------------------------------
062
063 public Certificate()
064 {
065 super();
066 }
067
068 // Instance methods.
069 // -------------------------------------------------------------------------
070
071 /**
072 * <p>Tests if this certificate equals another.</p>
073 *
074 * @param other The object to test.
075 * @return True if the certificates are equal.
076 */
077 public boolean equals(Object other)
078 {
079 if (other == null || !(other instanceof Certificate))
080 {
081 return false;
082 }
083 if (other == this)
084 {
085 return true;
086 }
087 try
088 {
089 return Arrays.equals(getEncoded(), ((Certificate) other).getEncoded());
090 }
091 catch (CertificateEncodingException cee)
092 {
093 return false;
094 }
095 }
096
097 /**
098 * <p>Computes a hash code for this certificate.</p>
099 *
100 * @return The hash code.
101 */
102 public int hashCode()
103 {
104 try
105 {
106 Adler32 csum = new Adler32();
107 csum.update(getEncoded());
108 return (int) csum.getValue();
109 }
110 catch (CertificateEncodingException cee)
111 {
112 return 0;
113 }
114 }
115
116 // Abstract methods.
117 // -------------------------------------------------------------------------
118
119 /**
120 * <p>Return the encoded form of this certificate.</p>
121 *
122 * @return The encoded form.
123 * @throws CertificateEncodingException If the certificate could not be
124 * encoded.
125 */
126 public abstract byte[] getEncoded() throws CertificateEncodingException;
127
128 /**
129 * <p>Verifies the signature of this certificate.</p>
130 *
131 * @param key The signer's public key.
132 * @throws CertificateException
133 * @throws NoSuchAlgorithmException If the algorithm used to sign the
134 * certificate is not available.
135 * @throws InvalidKeyException If the supplied key is not appropriate for the
136 * certificate's signature algorithm.
137 * @throws NoSuchProviderException
138 * @throws SignatureException If the signature could not be verified.
139 */
140 public abstract void verify(PublicKey key)
141 throws CertificateException, NoSuchAlgorithmException, InvalidKeyException,
142 NoSuchProviderException, SignatureException;
143
144 /**
145 * <p>Verifies the signature of this certificate, using the specified security
146 * provider.</p>
147 *
148 * @param key The signer's public key.
149 * @param sigProvider The name of the signature provider.
150 * @throws CertificateException
151 * @throws NoSuchAlgorithmException If the algorithm used to sign the
152 * certificate is not available.
153 * @throws InvalidKeyException If the supplied key is not appropriate for the
154 * certificate's signature algorithm.
155 * @throws NoSuchProviderException If <i>sigProvider</i> is not the name of an
156 * installed provider.
157 * @throws SignatureException If the signature could not be verified.
158 */
159 public abstract void verify(PublicKey key, String sigProvider)
160 throws CertificateException, NoSuchAlgorithmException, InvalidKeyException,
161 NoSuchProviderException, SignatureException;
162
163 /**
164 * <p>Returns a printable representation of this certificate.</p>
165 *
166 * @return The string.
167 */
168 public abstract String toString();
169
170 /**
171 * <p>Returns this certificate's public key.</p>
172 *
173 * @return The public key.
174 */
175 public abstract PublicKey getPublicKey();
176 }