1/*
2 *  Licensed to the Apache Software Foundation (ASF) under one or more
3 *  contributor license agreements.  See the NOTICE file distributed with
4 *  this work for additional information regarding copyright ownership.
5 *  The ASF licenses this file to You under the Apache License, Version 2.0
6 *  (the "License"); you may not use this file except in compliance with
7 *  the License.  You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 *  Unless required by applicable law or agreed to in writing, software
12 *  distributed under the License is distributed on an "AS IS" BASIS,
13 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *  See the License for the specific language governing permissions and
15 *  limitations under the License.
16 */
17
18package java.security.cert;
19
20import java.io.InputStream;
21import java.util.Collection;
22import java.util.Iterator;
23import java.util.List;
24
25/**
26 * This class defines the <i>Service Provider Interface</i> (<b>SPI</b>) for the
27 * {@code CertificateFactory} class. This SPI must be implemented for each
28 * certificate type a security provider wishes to support.
29 */
30
31public abstract class CertificateFactorySpi {
32
33    /**
34     * Constructs a new instance of this class.
35     */
36    public CertificateFactorySpi() {
37    }
38
39    /**
40     * Generates and initializes a {@code Certificate} from the provided input
41     * stream.
42     *
43     * @param inStream
44     *            the stream from which the data is read to create the
45     *            certificate.
46     * @return an initialized certificate.
47     * @exception CertificateException
48     *                if parsing problems are detected.
49     */
50    public abstract Certificate engineGenerateCertificate(InputStream inStream)
51            throws CertificateException;
52
53    /**
54     * Generates and initializes a collection of certificates from the provided
55     * input stream.
56     *
57     * @param inStream
58     *            the stream from where data is read to create the certificates.
59     * @return a collection of certificates.
60     * @exception CertificateException
61     *                if parsing problems are detected.
62     */
63    public abstract Collection<? extends Certificate>
64        engineGenerateCertificates(InputStream inStream) throws CertificateException;
65
66    /**
67     * Generates and initializes a <i>Certificate Revocation List</i> (CRL) from
68     * the provided input stream.
69     *
70     * @param inStream
71     *            the stream from where data is read to create the CRL.
72     * @return an CRL instance.
73     * @exception CRLException
74     *                if parsing problems are detected.
75     */
76    public abstract CRL engineGenerateCRL(InputStream inStream)
77            throws CRLException;
78
79    /**
80     * Generates and initializes a collection of <i>Certificate Revocation
81     * List</i> (CRL) from the provided input stream.
82     *
83     * @param inStream
84     *            the stream from which the data is read to create the CRLs.
85     * @return a collection of CRLs.
86     * @exception CRLException
87     *                if parsing problems are detected.
88     */
89    public abstract Collection<? extends CRL>
90        engineGenerateCRLs(InputStream inStream) throws CRLException;
91
92    /**
93     * Generates a {@code CertPath} from the provided {@code InputStream}. The
94     * default encoding scheme is applied.
95     *
96     * @param inStream
97     *            an input stream with encoded data.
98     * @return a {@code CertPath} initialized from the provided data.
99     * @throws CertificateException
100     *             if parsing problems are detected.
101     */
102    public CertPath engineGenerateCertPath(InputStream inStream)
103            throws CertificateException {
104        throw new UnsupportedOperationException();
105    }
106
107    /**
108     * Generates a {@code CertPath} from the provided {@code
109     * InputStream} in the specified encoding.
110     *
111     * @param inStream
112     *            an input stream containing certificate path data in specified
113     *            encoding.
114     * @param encoding
115     *            the encoding of the data in the input stream.
116     * @return a {@code CertPath} initialized from the provided data
117     * @throws CertificateException
118     *             if parsing problems are detected.
119     * @throws UnsupportedOperationException
120     *             if the provider does not implement this method.
121     */
122    public CertPath engineGenerateCertPath(InputStream inStream, String encoding)
123            throws CertificateException {
124        throw new UnsupportedOperationException();
125    }
126
127    /**
128     * Generates a {@code CertPath} from the provided list of certificates. The
129     * encoding is the default encoding.
130     *
131     * @param certificates
132     *            the list containing certificates in a format supported by the
133     *            {@code CertificateFactory}.
134     * @return a {@code CertPath} initialized from the provided data.
135     * @throws CertificateException
136     *             if parsing problems are detected.
137     * @throws UnsupportedOperationException
138     *             if the provider does not implement this method.
139     */
140    public CertPath engineGenerateCertPath(List<? extends Certificate>  certificates)
141            throws CertificateException {
142        throw new UnsupportedOperationException();
143    }
144
145    /**
146     * Returns an {@code Iterator} over the supported {@code CertPath} encodings
147     * (as Strings). The first element is the default encoding.
148     *
149     * @return an iterator over supported {@code CertPath} encodings (as
150     *         Strings).
151     */
152    public Iterator<String> engineGetCertPathEncodings() {
153        throw new UnsupportedOperationException();
154    }
155}
156