MyKeyStoreSpi.java revision 561ee011997c6c2f1befbfaa9d5f0a99771c1d63
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 */
42
43public class MyKeyStoreSpi extends KeyStoreSpi {
44
45    public Key engineGetKey(String alias, char[] password)
46            throws NoSuchAlgorithmException, UnrecoverableKeyException {
47        return null;
48    }
49
50    public Certificate[] engineGetCertificateChain(String alias) {
51        return null;
52    }
53
54    public Certificate engineGetCertificate(String alias) {
55        return null;
56    }
57
58    public Date engineGetCreationDate(String alias) {
59        return new Date(0);
60    }
61
62    public void engineSetKeyEntry(String alias, Key key, char[] password,
63            Certificate[] chain) throws KeyStoreException {
64        throw new KeyStoreException(
65                "engineSetKeyEntry is not supported in myKeyStoreSpi");
66    }
67
68    public void engineSetKeyEntry(String alias, byte[] key, Certificate[] chain)
69            throws KeyStoreException {
70        throw new KeyStoreException(
71                "engineSetKeyEntry is not supported in myKeyStoreSpi");
72    }
73
74    public void engineSetCertificateEntry(String alias, Certificate cert)
75            throws KeyStoreException {
76        throw new KeyStoreException(
77                "engineSetCertificateEntry is not supported in myKeyStoreSpi");
78    }
79
80    public void engineDeleteEntry(String alias) throws KeyStoreException {
81        throw new KeyStoreException(
82                "engineDeleteEntry is not supported in myKeyStoreSpi");
83    }
84
85    public Enumeration engineAliases() {
86        return null;
87    }
88
89    public boolean engineContainsAlias(String alias) {
90        return false;
91    }
92
93    public int engineSize() {
94        return 0;
95    }
96
97    public boolean engineIsKeyEntry(String alias) {
98        return false;
99    }
100
101    public boolean engineIsCertificateEntry(String alias) {
102        return false;
103    }
104
105    public String engineGetCertificateAlias(Certificate cert) {
106        return "";
107    }
108
109    public void engineStore(OutputStream stream, char[] password)
110            throws IOException, NoSuchAlgorithmException, CertificateException {
111        if (!(stream instanceof ByteArrayOutputStream)) {
112            throw new IOException("Incorrect stream");
113        }
114        if (((ByteArrayOutputStream) stream).size() == 0) {
115            throw new IOException("Incorrect stream size ");
116
117        }
118
119    }
120
121    public void engineLoad(InputStream stream, char[] password)
122            throws IOException, NoSuchAlgorithmException, CertificateException {
123    }
124}