1
2 package jsdsi.sexp;
3
4 import java.io.EOFException;
5 import java.io.IOException;
6 import java.io.InputStream;
7 import java.security.cert.CRL;
8 import java.security.cert.CRLException;
9 import java.security.cert.CertificateException;
10 import java.security.cert.CertificateFactorySpi;
11 import java.security.cert.CertificateParsingException;
12 import java.util.ArrayList;
13 import java.util.Arrays;
14 import java.util.Collection;
15 import java.util.Iterator;
16 import java.util.List;
17
18 import jsdsi.Obj;
19 import jsdsi.Proof;
20 import jsdsi.Sequence;
21
22 /***
23 * Creates certificates and certification paths from S-expressions.
24 *
25 * @author Sameer Ajmani
26 * @version $Revision: 1.1.6.1 $ $Date: 2005/11/08 03:12:52 $
27 */
28 public class CertificateFactory extends CertificateFactorySpi {
29 private Obj readObj(InputStream in)
30 throws SexpParseException, SexpException, IOException {
31 return new ObjInputStream(in).readObj();
32 }
33 private java.security.cert.Certificate readCertificate(InputStream in)
34 throws CertificateException,
35 SexpParseException, SexpException, IOException {
36 try {
37 return jsdsi.Certificate.fromSequence((Sequence) readObj(in));
38 } catch (ClassCastException e) {
39 throw (CertificateParsingException) new CertificateParsingException(
40 "expected a Sequence").initCause(
41 e);
42 }
43 }
44 public java.security.cert.Certificate engineGenerateCertificate(
45 InputStream in)
46 throws CertificateException {
47 try {
48 return readCertificate(in);
49 } catch (CertificateException e) {
50 throw e;
51 } catch (Exception e) {
52 throw (CertificateParsingException) new CertificateParsingException()
53 .initCause(
54 e);
55 }
56 }
57
58 public Collection engineGenerateCertificates(InputStream in)
59 throws CertificateException {
60 Collection c = new ArrayList();
61 while (true) {
62 try {
63 c.add(readCertificate(in));
64 } catch (EOFException e) {
65 break;
66 } catch (CertificateException e) {
67 throw e;
68 } catch (Exception e) {
69 throw (CertificateParsingException) new CertificateParsingException()
70 .initCause(
71 e);
72 }
73 }
74 return c;
75 }
76
77 public java.security.cert.CertPath engineGenerateCertPath(InputStream in)
78 throws CertificateException {
79 try {
80 return new jsdsi.CertPath((Proof) readObj(in));
81 } catch (ClassCastException e) {
82 throw (CertificateParsingException) new CertificateParsingException(
83 "expected a Proof").initCause(
84 e);
85 } catch (Exception e) {
86 throw (CertificateParsingException) new CertificateParsingException()
87 .initCause(
88 e);
89 }
90 }
91
92 public java.security.cert.CertPath engineGenerateCertPath(
93 InputStream in,
94 String encoding)
95 throws CertificateException {
96 if (encoding.equals("SEXP")) {
97 return engineGenerateCertPath(in);
98 }
99 throw new CertificateParsingException(
100 "unsupported encoding: " + encoding);
101 }
102
103 public java.security.cert.CertPath engineGenerateCertPath(List certs)
104 throws CertificateException {
105 // we can't support this interface
106 throw new UnsupportedOperationException();
107 }
108
109 public Iterator engineGetCertPathEncodings() {
110 return Arrays.asList(new String[] { "SEXP" }).iterator();
111 }
112
113 public CRL engineGenerateCRL(InputStream in) throws CRLException {
114 throw new UnsupportedOperationException();
115 }
116
117 public Collection engineGenerateCRLs(InputStream in) throws CRLException {
118 throw new UnsupportedOperationException();
119 }
120 }
This page was automatically generated by Maven