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 org.apache.harmony.security.tests.support;
19
20import java.security.InvalidAlgorithmParameterException;
21import java.security.KeyStore;
22import java.security.KeyStoreException;
23
24import javax.net.ssl.ManagerFactoryParameters;
25import javax.net.ssl.TrustManager;
26import javax.net.ssl.TrustManagerFactorySpi;
27
28/**
29 * Class for vertifying TrustManagerFactorySpi and TrustManagerFactory
30 * functionality
31 *
32 */
33
34public class MyTrustManagerFactorySpi extends TrustManagerFactorySpi {
35    protected void engineInit(KeyStore ks) throws KeyStoreException {
36        if (ks == null) {
37            throw new KeyStoreException("Not supported operation for null KeyStore");
38        }
39    }
40
41    protected void engineInit(ManagerFactoryParameters spec)
42            throws InvalidAlgorithmParameterException {
43        if (spec == null) {
44            throw new InvalidAlgorithmParameterException("Null parameter");
45        }
46        if (spec instanceof Parameters) {
47            try {
48                engineInit(((Parameters)spec).getKeyStore());
49            } catch (KeyStoreException e) {
50                throw new RuntimeException(e);
51            }
52        } else {
53            throw new InvalidAlgorithmParameterException("Invalid parameter");
54        }
55    }
56
57    protected TrustManager[] engineGetTrustManagers() {
58        return null;
59    }
60
61
62    public static class Parameters implements ManagerFactoryParameters {
63        private KeyStore keyStore;
64        public Parameters (KeyStore ks) {
65            this.keyStore = ks;
66        }
67        public KeyStore getKeyStore() {
68            return keyStore;
69        }
70    }
71}
72