1 7 8 package java.security.cert; 9 10 import java.io.ByteArrayInputStream ; 11 import java.io.NotSerializableException ; 12 import java.io.ObjectStreamException ; 13 import java.io.Serializable ; 14 import java.util.Iterator ; 15 import java.util.List ; 16 17 90 public abstract class CertPath implements Serializable { 91 92 private static final long serialVersionUID = 6068470306649138683L; 93 94 private String type; 96 105 protected CertPath(String type) { 106 this.type = type; 107 } 108 109 118 public String getType() { 119 return type; 120 } 121 122 131 public abstract Iterator <String > getEncodings(); 132 133 148 public boolean equals(Object other) { 149 if (this == other) 150 return true; 151 152 if (! (other instanceof CertPath )) 153 return false; 154 155 CertPath otherCP = (CertPath ) other; 156 if (! otherCP.getType().equals(type)) 157 return false; 158 159 List thisCertList = this.getCertificates(); 160 List otherCertList = otherCP.getCertificates(); 161 return(thisCertList.equals(otherCertList)); 162 } 163 164 179 public int hashCode() { 180 int hashCode = type.hashCode(); 181 hashCode = 31*hashCode + getCertificates().hashCode(); 182 return hashCode; 183 } 184 185 192 public String toString() { 193 StringBuffer sb = new StringBuffer (); 194 Iterator stringIterator = getCertificates().iterator(); 195 196 sb.append("\n" + type + " Cert Path: length = " 197 + getCertificates().size() + ".\n"); 198 sb.append("[\n"); 199 int i = 1; 200 while (stringIterator.hasNext()) { 201 sb.append("==========================================" 202 + "===============Certificate " + i + " start.\n"); 203 Certificate stringCert = (Certificate ) stringIterator.next(); 204 sb.append(stringCert.toString()); 205 sb.append("\n========================================" 206 + "=================Certificate " + i + " end.\n\n\n"); 207 i++; 208 } 209 210 sb.append("\n]"); 211 return sb.toString(); 212 } 213 214 221 public abstract byte[] getEncoded() 222 throws CertificateEncodingException ; 223 224 233 public abstract byte[] getEncoded(String encoding) 234 throws CertificateEncodingException ; 235 236 243 public abstract List <? extends Certificate > getCertificates(); 244 245 254 protected Object writeReplace() throws ObjectStreamException { 255 try { 256 return new CertPathRep(type, getEncoded()); 257 } catch (CertificateException ce) { 258 NotSerializableException nse = 259 new NotSerializableException 260 ("java.security.cert.CertPath: " + type); 261 nse.initCause(ce); 262 throw nse; 263 } 264 } 265 266 269 protected static class CertPathRep implements Serializable { 270 271 private static final long serialVersionUID = 3015633072427920915L; 272 273 274 private String type; 275 276 private byte[] data; 277 278 285 protected CertPathRep(String type, byte[] data) { 286 this.type = type; 287 this.data = data; 288 } 289 290 298 protected Object readResolve() throws ObjectStreamException { 299 try { 300 CertificateFactory cf = CertificateFactory.getInstance(type); 301 return cf.generateCertPath(new ByteArrayInputStream (data)); 302 } catch (CertificateException ce) { 303 NotSerializableException nse = 304 new NotSerializableException 305 ("java.security.cert.CertPath: " + type); 306 nse.initCause(ce); 307 throw nse; 308 } 309 } 310 } 311 } 312 | Popular Tags |