1 7 8 package java.security.cert; 9 10 import java.util.Arrays ; 11 12 import java.security.PublicKey ; 13 import java.security.NoSuchAlgorithmException ; 14 import java.security.NoSuchProviderException ; 15 import java.security.InvalidKeyException ; 16 import java.security.SignatureException ; 17 18 import sun.security.x509.X509CertImpl; 19 20 43 44 public abstract class Certificate implements java.io.Serializable { 45 46 private static final long serialVersionUID = -3585440601605666277L; 47 48 private final String type; 50 51 60 protected Certificate(String type) { 61 this.type = type; 62 } 63 64 69 public final String getType() { 70 return this.type; 71 } 72 73 84 public boolean equals(Object other) { 85 if (this == other) { 86 return true; 87 } 88 if (!(other instanceof Certificate )) { 89 return false; 90 } 91 try { 92 byte[] thisCert = X509CertImpl.getEncodedInternal(this); 93 byte[] otherCert = X509CertImpl.getEncodedInternal((Certificate )other); 94 95 return Arrays.equals(thisCert, otherCert); 96 } catch (CertificateException e) { 97 return false; 98 } 99 } 100 101 107 public int hashCode() { 108 int retval = 0; 109 try { 110 byte[] certData = X509CertImpl.getEncodedInternal(this); 111 for (int i = 1; i < certData.length; i++) { 112 retval += certData[i] * i; 113 } 114 return retval; 115 } catch (CertificateException e) { 116 return retval; 117 } 118 } 119 120 130 public abstract byte[] getEncoded() 131 throws CertificateEncodingException ; 132 133 146 public abstract void verify(PublicKey key) 147 throws CertificateException , NoSuchAlgorithmException , 148 InvalidKeyException , NoSuchProviderException , 149 SignatureException ; 150 151 167 public abstract void verify(PublicKey key, String sigProvider) 168 throws CertificateException , NoSuchAlgorithmException , 169 InvalidKeyException , NoSuchProviderException , 170 SignatureException ; 171 172 177 public abstract String toString(); 178 179 184 public abstract PublicKey getPublicKey(); 185 186 189 protected static class CertificateRep implements java.io.Serializable { 190 191 private static final long serialVersionUID = -8563758940495660020L; 192 193 private String type; 194 private byte[] data; 195 196 206 protected CertificateRep(String type, byte[] data) { 207 this.type = type; 208 this.data = data; 209 } 210 211 221 protected Object readResolve() throws java.io.ObjectStreamException { 222 try { 223 CertificateFactory cf = CertificateFactory.getInstance(type); 224 return cf.generateCertificate 225 (new java.io.ByteArrayInputStream (data)); 226 } catch (CertificateException e) { 227 throw new java.io.NotSerializableException 228 ("java.security.cert.Certificate: " + 229 type + 230 ": " + 231 e.getMessage()); 232 } 233 } 234 } 235 236 244 protected Object writeReplace() throws java.io.ObjectStreamException { 245 try { 246 return new CertificateRep(type, getEncoded()); 247 } catch (CertificateException e) { 248 throw new java.io.NotSerializableException 249 ("java.security.cert.Certificate: " + 250 type + 251 ": " + 252 e.getMessage()); 253 } 254 } 255 } 256 | Popular Tags |