1/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License
15 */
16
17package libcore.javax.crypto;
18
19import java.security.AlgorithmParameters;
20import java.security.InvalidAlgorithmParameterException;
21import java.security.InvalidKeyException;
22import java.security.Key;
23import java.security.NoSuchAlgorithmException;
24import java.security.SecureRandom;
25import java.security.spec.AlgorithmParameterSpec;
26
27import javax.crypto.BadPaddingException;
28import javax.crypto.MacSpi;
29import javax.crypto.IllegalBlockSizeException;
30import javax.crypto.NoSuchPaddingException;
31import javax.crypto.ShortBufferException;
32
33/**
34 * Mock CipherSpi used by {@link libcore.javax.crypto.CipherTest}.
35 */
36public class MockMacSpi extends MacSpi {
37    public static class SpecificKeyTypes extends MockMacSpi {
38        @Override
39        public void checkKeyType(Key key) throws InvalidKeyException {
40            if (!(key instanceof MockKey)) {
41                throw new InvalidKeyException("Must be MockKey!");
42            }
43        }
44    }
45
46    public static class SpecificKeyTypes2 extends MockMacSpi {
47        @Override
48        public void checkKeyType(Key key) throws InvalidKeyException {
49            System.err.println("Checking key of type " + key.getClass().getName());
50            if (!(key instanceof MockKey2)) {
51                throw new InvalidKeyException("Must be MockKey2!");
52            }
53        }
54    }
55
56    public static class AllKeyTypes extends MockMacSpi {
57    }
58
59    public void checkKeyType(Key key) throws InvalidKeyException {
60    }
61
62    @Override
63    protected int engineGetMacLength() {
64        throw new UnsupportedOperationException("not implemented");
65    }
66
67    @Override
68    protected void engineInit(Key key, AlgorithmParameterSpec params)
69            throws InvalidKeyException, InvalidAlgorithmParameterException {
70        throw new UnsupportedOperationException("not implemented");
71    }
72
73    @Override
74    protected void engineUpdate(byte input) {
75        throw new UnsupportedOperationException("not implemented");
76    }
77
78    @Override
79    protected void engineUpdate(byte[] input, int inputOffset, int inputLen) {
80        throw new UnsupportedOperationException("not implemented");
81    }
82
83    @Override
84    protected byte[] engineDoFinal() {
85        throw new UnsupportedOperationException("not implemented");
86    }
87
88    @Override
89    protected void engineReset() {
90        throw new UnsupportedOperationException("not implemented");
91    }
92}
93