1/* 2 * Copyright 2014 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 org.apache.harmony.crypto.tests.javax.crypto; 18 19import java.security.InvalidKeyException; 20import java.security.InvalidParameterException; 21import java.security.Key; 22import java.security.spec.AlgorithmParameterSpec; 23import javax.crypto.MacSpi; 24import libcore.javax.crypto.MockKey; 25import libcore.javax.crypto.MockKey2; 26 27public class MockMacSpi extends MacSpi { 28 public static class SpecificKeyTypes extends MockMacSpi { 29 @Override 30 public void checkKeyType(Key key) throws InvalidKeyException { 31 if (!(key instanceof MockKey)) { 32 throw new InvalidKeyException("Must be MockKey!"); 33 } 34 } 35 } 36 37 public static class SpecificKeyTypes2 extends MockMacSpi { 38 @Override 39 public void checkKeyType(Key key) throws InvalidKeyException { 40 if (!(key instanceof MockKey2)) { 41 throw new InvalidKeyException("Must be MockKey2!"); 42 } 43 } 44 } 45 46 public static class AllKeyTypes extends MockMacSpi { 47 } 48 49 public void checkKeyType(Key key) throws InvalidKeyException { 50 } 51 52 @Override 53 protected int engineGetMacLength() { 54 throw new UnsupportedOperationException(); 55 } 56 57 @Override 58 protected void engineInit(Key key, AlgorithmParameterSpec params) throws InvalidKeyException, 59 InvalidParameterException { 60 checkKeyType(key); 61 } 62 63 @Override 64 protected void engineUpdate(byte input) { 65 throw new UnsupportedOperationException(); 66 } 67 68 @Override 69 protected void engineUpdate(byte[] input, int offset, int len) { 70 throw new UnsupportedOperationException(); 71 } 72 73 @Override 74 protected byte[] engineDoFinal() { 75 throw new UnsupportedOperationException(); 76 } 77 78 @Override 79 protected void engineReset() { 80 throw new UnsupportedOperationException(); 81 } 82} 83