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
18/**
19* @author Vladimir N. Molotkov
20*/
21
22package org.apache.harmony.security.tests.support.cert;
23
24import java.security.cert.CertPath;
25import java.security.cert.CertificateEncodingException;
26import java.util.Collections;
27import java.util.Iterator;
28import java.util.List;
29import java.util.Vector;
30
31
32/**
33 * Stub class for <code>java.security.cert.CertPath</code> tests
34 *
35 */
36public class MyCertPath extends CertPath {
37    /**
38     * my certificates list
39     */
40    private final Vector certificates;
41    /**
42     * List of encodings supported
43     */
44    private final Vector encodingNames;
45    /**
46     * my cert path the only encoding
47     */
48    private final byte[] encoding;
49
50    /**
51     * Constructs new instance of <code>MyCertPath</code>
52     *
53     * @param type
54     * @param encoding
55     */
56    public MyCertPath(byte[] encoding) {
57        super("MyEncoding");
58        this.encoding = encoding;
59        certificates = new Vector();
60        certificates.add(new MyCertificate("MyEncoding", encoding));
61        encodingNames = new Vector();
62        encodingNames.add("MyEncoding");
63    }
64
65    /**
66     * @return certificates list
67     * @see java.security.cert.CertPath#getCertificates()
68     */
69    public List getCertificates() {
70        return Collections.unmodifiableList(certificates);
71    }
72
73    /**
74     * @return default encoded form of this cert path
75     * @see java.security.cert.CertPath#getEncoded()
76     */
77    public byte[] getEncoded() throws CertificateEncodingException {
78        return encoding.clone();
79    }
80
81    /**
82     * @return encoded form of this cert path as specified by
83     * <code>encoding</code> parameter
84     * @throws CertificateEncodingException if <code>encoding</code>
85     * not equals "MyEncoding"
86     * @see java.security.cert.CertPath#getEncoded(java.lang.String)
87     */
88    public byte[] getEncoded(String encoding)
89            throws CertificateEncodingException {
90        if (getType().equals(encoding)) {
91            return this.encoding.clone();
92        }
93        throw new CertificateEncodingException("Encoding not supported: " +
94                encoding);
95    }
96
97    /**
98     * @return iterator through encodings supported
99     * @see java.security.cert.CertPath#getEncodings()
100     */
101    public Iterator getEncodings() {
102        return Collections.unmodifiableCollection(encodingNames).iterator();
103    }
104
105}
106