001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /**
019: * @author Vera Y. Petrashkova
020: * @version $Revision$
021: */package org.apache.harmony.crypto.tests.support;
022:
023: import java.security.AlgorithmParameters;
024: import java.security.InvalidAlgorithmParameterException;
025: import java.security.InvalidKeyException;
026: import java.security.Key;
027: import java.security.spec.AlgorithmParameterSpec;
028:
029: import javax.crypto.ExemptionMechanismException;
030: import javax.crypto.ExemptionMechanismSpi;
031: import javax.crypto.ShortBufferException;
032:
033: /**
034: * Additional class for verification ExemptionMechanismSpi
035: * and ExemptionMechanism classes
036: *
037: */
038:
039: public class MyExemptionMechanismSpi extends ExemptionMechanismSpi {
040:
041: private static final int byteArrayLength = 5;
042:
043: public static final int getLength() {
044: return byteArrayLength;
045: }
046:
047: @Override
048: protected byte[] engineGenExemptionBlob()
049: throws ExemptionMechanismException {
050: return new byte[byteArrayLength];
051: }
052:
053: @Override
054: protected int engineGenExemptionBlob(byte[] output, int outputOffset)
055: throws ShortBufferException, ExemptionMechanismException {
056: return byteArrayLength;
057: }
058:
059: @Override
060: protected int engineGetOutputSize(int inputLen) {
061: return 10;
062: }
063:
064: @Override
065: protected void engineInit(Key key) throws InvalidKeyException,
066: ExemptionMechanismException {
067: if (key == null) {
068: throw new InvalidKeyException("key is null");
069: }
070: if (!(key instanceof tmpKey)) {
071: throw new ExemptionMechanismException("Incorrect key");
072: }
073: }
074:
075: @Override
076: protected void engineInit(Key key, AlgorithmParameters params)
077: throws InvalidKeyException,
078: InvalidAlgorithmParameterException,
079: ExemptionMechanismException {
080: if (key == null) {
081: throw new InvalidKeyException("key is null");
082: }
083: if (!(key instanceof tmpKey)) {
084: throw new ExemptionMechanismException("Incorrect key");
085: }
086: }
087:
088: @Override
089: protected void engineInit(Key key, AlgorithmParameterSpec params)
090: throws InvalidKeyException,
091: InvalidAlgorithmParameterException,
092: ExemptionMechanismException {
093: if (key == null) {
094: throw new InvalidKeyException("key is null");
095: }
096: if (!(key instanceof tmpKey)) {
097: throw new ExemptionMechanismException("Incorrect key");
098: }
099: }
100:
101: @SuppressWarnings("serial")
102: public class tmpKey implements Key {
103: private String alg;
104: private byte[] enc;
105:
106: public tmpKey(String alg, byte[] enc) {
107: this .alg = alg;
108: this .enc = enc;
109: }
110:
111: public String getFormat() {
112: return "tmpKey";
113: }
114:
115: public String getAlgorithm() {
116: return alg;
117: }
118:
119: public byte[] getEncoded() {
120: return enc;
121: }
122: }
123:
124: @SuppressWarnings("serial")
125: public class tmp1Key implements Key {
126: private byte[] enc;
127:
128: public tmp1Key(String alg, byte[] enc) {
129: this .enc = enc;
130: }
131:
132: public String getAlgorithm() {
133: return "tmp1Key";
134: }
135:
136: public String getFormat() {
137: return "tmp1Key";
138: }
139:
140: public byte[] getEncoded() {
141: return enc;
142: }
143: }
144: }
|