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.NoSuchPaddingException; 30import javax.crypto.ShortBufferException; 31 32/** 33 * Mock CipherSpi used by {@link libcore.javax.crypto.CipherTest}. 34 */ 35public class MockMacSpi extends MacSpi { 36 public static class SpecificKeyTypes extends MockMacSpi { 37 @Override 38 public void checkKeyType(Key key) throws InvalidKeyException { 39 if (!(key instanceof MockKey)) { 40 throw new InvalidKeyException("Must be MockKey!"); 41 } 42 } 43 } 44 45 public static class SpecificKeyTypes2 extends MockMacSpi { 46 @Override 47 public void checkKeyType(Key key) throws InvalidKeyException { 48 System.err.println("Checking key of type " + key.getClass().getName()); 49 if (!(key instanceof MockKey2)) { 50 throw new InvalidKeyException("Must be MockKey2!"); 51 } 52 } 53 } 54 55 public static class AllKeyTypes extends MockMacSpi { 56 } 57 58 public void checkKeyType(Key key) throws InvalidKeyException { 59 } 60 61 @Override 62 protected int engineGetMacLength() { 63 throw new UnsupportedOperationException("not implemented"); 64 } 65 66 @Override 67 protected void engineInit(Key key, AlgorithmParameterSpec params) 68 throws InvalidKeyException, InvalidAlgorithmParameterException { 69 throw new UnsupportedOperationException("not implemented"); 70 } 71 72 @Override 73 protected void engineUpdate(byte input) { 74 throw new UnsupportedOperationException("not implemented"); 75 } 76 77 @Override 78 protected void engineUpdate(byte[] input, int inputOffset, int inputLen) { 79 throw new UnsupportedOperationException("not implemented"); 80 } 81 82 @Override 83 protected byte[] engineDoFinal() { 84 throw new UnsupportedOperationException("not implemented"); 85 } 86 87 @Override 88 protected void engineReset() { 89 throw new UnsupportedOperationException("not implemented"); 90 } 91} 92