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 Vera Y. Petrashkova
20 */
21
22package org.apache.harmony.security.tests.support;
23
24import java.io.ByteArrayOutputStream;
25import java.io.IOException;
26import java.io.InputStream;
27import java.io.OutputStream;
28import java.security.Key;
29import java.security.KeyStoreException;
30import java.security.KeyStoreSpi;
31import java.security.NoSuchAlgorithmException;
32import java.security.UnrecoverableKeyException;
33import java.security.cert.Certificate;
34import java.security.cert.CertificateException;
35import java.util.Date;
36import java.util.Enumeration;
37
38/**
39 * Additional class for KeyStoreSpi and KeyStore verification
40 */
41
42public class MyKeyStoreSpi extends KeyStoreSpi {
43
44    public Key engineGetKey(String alias, char[] password)
45            throws NoSuchAlgorithmException, UnrecoverableKeyException {
46        return null;
47    }
48
49    public Certificate[] engineGetCertificateChain(String alias) {
50        return null;
51    }
52
53    public Certificate engineGetCertificate(String alias) {
54        return null;
55    }
56
57    public Date engineGetCreationDate(String alias) {
58        return new Date(0);
59    }
60
61    public void engineSetKeyEntry(String alias, Key key, char[] password,
62            Certificate[] chain) throws KeyStoreException {
63        throw new KeyStoreException(
64                "engineSetKeyEntry is not supported in myKeyStoreSpi");
65    }
66
67    public void engineSetKeyEntry(String alias, byte[] key, Certificate[] chain)
68            throws KeyStoreException {
69        throw new KeyStoreException(
70                "engineSetKeyEntry is not supported in myKeyStoreSpi");
71    }
72
73    public void engineSetCertificateEntry(String alias, Certificate cert)
74            throws KeyStoreException {
75        throw new KeyStoreException(
76                "engineSetCertificateEntry is not supported in myKeyStoreSpi");
77    }
78
79    public void engineDeleteEntry(String alias) throws KeyStoreException {
80        throw new KeyStoreException(
81                "engineDeleteEntry is not supported in myKeyStoreSpi");
82    }
83
84    public Enumeration engineAliases() {
85        return null;
86    }
87
88    public boolean engineContainsAlias(String alias) {
89        return false;
90    }
91
92    public int engineSize() {
93        return 0;
94    }
95
96    public boolean engineIsKeyEntry(String alias) {
97        return false;
98    }
99
100    public boolean engineIsCertificateEntry(String alias) {
101        return false;
102    }
103
104    public String engineGetCertificateAlias(Certificate cert) {
105        return "";
106    }
107
108    public void engineStore(OutputStream stream, char[] password)
109            throws IOException, NoSuchAlgorithmException, CertificateException {
110        if (!(stream instanceof ByteArrayOutputStream)) {
111            throw new IOException("Incorrect stream");
112        }
113        if (((ByteArrayOutputStream) stream).size() == 0) {
114            throw new IOException("Incorrect stream size ");
115
116        }
117
118    }
119
120    public void engineLoad(InputStream stream, char[] password)
121            throws IOException, NoSuchAlgorithmException, CertificateException {
122    }
123}