2004-09-21 Andreas Tobler <a.tobler@schweiz.ch>
[official-gcc.git] / libjava / javax / security / cert / Certificate.java
blob8090817fcf4439b4f9a8c48888a82c4a677df631
1 /* Certificate.java -- base class of public-key certificates.
2 Copyright (C) 2004 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package javax.security.cert;
41 import java.security.InvalidKeyException;
42 import java.security.NoSuchAlgorithmException;
43 import java.security.NoSuchProviderException;
44 import java.security.PublicKey;
45 import java.security.SignatureException;
47 import java.util.Arrays;
48 import java.util.zip.Adler32;
50 /**
51 * <p>The base class for public-key certificates.</p>
53 * <p><b>This class is deprecated in favor of the {@link
54 * java.security.cert.Certificate} class. It should not be used in new
55 * applications.</b></p>
57 public abstract class Certificate
60 // Constructors.
61 // -------------------------------------------------------------------------
63 public Certificate()
65 super();
68 // Instance methods.
69 // -------------------------------------------------------------------------
71 /**
72 * <p>Tests if this certificate equals another.</p>
74 * @param other The object to test.
75 * @return True if the certificates are equal.
77 public boolean equals(Object other)
79 if (other == null || !(other instanceof Certificate))
81 return false;
83 if (other == this)
85 return true;
87 try
89 return Arrays.equals(getEncoded(), ((Certificate) other).getEncoded());
91 catch (CertificateEncodingException cee)
93 return false;
97 /**
98 * <p>Computes a hash code for this certificate.</p>
100 * @return The hash code.
102 public int hashCode()
106 Adler32 csum = new Adler32();
107 csum.update(getEncoded());
108 return (int) csum.getValue();
110 catch (CertificateEncodingException cee)
112 return 0;
116 // Abstract methods.
117 // -------------------------------------------------------------------------
120 * <p>Return the encoded form of this certificate.</p>
122 * @return The encoded form.
123 * @throws CertificateEncodingException If the certificate could not be
124 * encoded.
126 public abstract byte[] getEncoded() throws CertificateEncodingException;
129 * <p>Verifies the signature of this certificate.</p>
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.
140 public abstract void verify(PublicKey key)
141 throws CertificateException, NoSuchAlgorithmException, InvalidKeyException,
142 NoSuchProviderException, SignatureException;
145 * <p>Verifies the signature of this certificate, using the specified security
146 * provider.</p>
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.
159 public abstract void verify(PublicKey key, String sigProvider)
160 throws CertificateException, NoSuchAlgorithmException, InvalidKeyException,
161 NoSuchProviderException, SignatureException;
164 * <p>Returns a printable representation of this certificate.</p>
166 * @return The string.
168 public abstract String toString();
171 * <p>Returns this certificate's public key.</p>
173 * @return The public key.
175 public abstract PublicKey getPublicKey();