Path: blob/master/src/java.base/share/classes/javax/crypto/ExemptionMechanismSpi.java
41152 views
/*1* Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.crypto;2627import java.security.Key;28import java.security.AlgorithmParameters;29import java.security.InvalidKeyException;30import java.security.InvalidAlgorithmParameterException;31import java.security.spec.AlgorithmParameterSpec;3233/**34* This class defines the <i>Service Provider Interface</i> (<b>SPI</b>)35* for the <code>ExemptionMechanism</code> class.36* All the abstract methods in this class must be implemented by each37* cryptographic service provider who wishes to supply the implementation38* of a particular exemption mechanism.39*40* @author Sharon Liu41*42* @since 1.443*/4445public abstract class ExemptionMechanismSpi {4647/**48* Constructor for subclasses to call.49*/50public ExemptionMechanismSpi() {}5152/**53* Returns the length in bytes that an output buffer would need to be in54* order to hold the result of the next55* {@link #engineGenExemptionBlob(byte[], int) engineGenExemptionBlob}56* operation, given the input length <code>inputLen</code> (in bytes).57*58* <p>The actual output length of the next59* {@link #engineGenExemptionBlob(byte[], int) engineGenExemptionBlob}60* call may be smaller than the length returned by this method.61*62* @param inputLen the input length (in bytes)63*64* @return the required output buffer size (in bytes)65*/66protected abstract int engineGetOutputSize(int inputLen);6768/**69* Initializes this exemption mechanism with a key.70*71* <p>If this exemption mechanism requires any algorithm parameters72* that cannot be derived from the given <code>key</code>, the underlying73* exemption mechanism implementation is supposed to generate the required74* parameters itself (using provider-specific default values); in the case75* that algorithm parameters must be specified by the caller, an76* <code>InvalidKeyException</code> is raised.77*78* @param key the key for this exemption mechanism79*80* @exception InvalidKeyException if the given key is inappropriate for81* this exemption mechanism.82* @exception ExemptionMechanismException if problem(s) encountered in the83* process of initializing.84*/85protected abstract void engineInit(Key key)86throws InvalidKeyException, ExemptionMechanismException;8788/**89* Initializes this exemption mechanism with a key and a set of algorithm90* parameters.91*92* <p>If this exemption mechanism requires any algorithm parameters and93* <code>params</code> is null, the underlying exemption mechanism94* implementation is supposed to generate the required parameters95* itself (using provider-specific default values); in the case that96* algorithm parameters must be specified by the caller, an97* <code>InvalidAlgorithmParameterException</code> is raised.98*99* @param key the key for this exemption mechanism100* @param params the algorithm parameters101*102* @exception InvalidKeyException if the given key is inappropriate for103* this exemption mechanism.104* @exception InvalidAlgorithmParameterException if the given algorithm105* parameters are inappropriate for this exemption mechanism.106* @exception ExemptionMechanismException if problem(s) encountered in the107* process of initializing.108*/109protected abstract void engineInit(Key key, AlgorithmParameterSpec params)110throws InvalidKeyException, InvalidAlgorithmParameterException,111ExemptionMechanismException;112113/**114* Initializes this exemption mechanism with a key and a set of algorithm115* parameters.116*117* <p>If this exemption mechanism requires any algorithm parameters118* and <code>params</code> is null, the underlying exemption mechanism119* implementation is supposed to generate the required parameters120* itself (using provider-specific default values); in the case that121* algorithm parameters must be specified by the caller, an122* <code>InvalidAlgorithmParameterException</code> is raised.123*124* @param key the key for this exemption mechanism125* @param params the algorithm parameters126*127* @exception InvalidKeyException if the given key is inappropriate for128* this exemption mechanism.129* @exception InvalidAlgorithmParameterException if the given algorithm130* parameters are inappropriate for this exemption mechanism.131* @exception ExemptionMechanismException if problem(s) encountered in the132* process of initializing.133*/134protected abstract void engineInit(Key key, AlgorithmParameters params)135throws InvalidKeyException, InvalidAlgorithmParameterException,136ExemptionMechanismException;137138/**139* Generates the exemption mechanism key blob.140*141* @return the new buffer with the result key blob.142*143* @exception ExemptionMechanismException if problem(s) encountered in the144* process of generating.145*/146protected abstract byte[] engineGenExemptionBlob()147throws ExemptionMechanismException;148149/**150* Generates the exemption mechanism key blob, and stores the result in151* the <code>output</code> buffer, starting at <code>outputOffset</code>152* inclusive.153*154* <p>If the <code>output</code> buffer is too small to hold the result,155* a <code>ShortBufferException</code> is thrown. In this case, repeat this156* call with a larger output buffer. Use157* {@link #engineGetOutputSize(int) engineGetOutputSize} to determine158* how big the output buffer should be.159*160* @param output the buffer for the result161* @param outputOffset the offset in <code>output</code> where the result162* is stored163*164* @return the number of bytes stored in <code>output</code>165*166* @exception ShortBufferException if the given output buffer is too small167* to hold the result.168* @exception ExemptionMechanismException if problem(s) encountered in the169* process of generating.170*/171protected abstract int engineGenExemptionBlob172(byte[] output, int outputOffset)173throws ShortBufferException, ExemptionMechanismException;174}175176177