Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/javax/crypto/ExemptionMechanismSpi.java
38829 views
/*1* Copyright (c) 1999, 2007, 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* Returns the length in bytes that an output buffer would need to be in49* order to hold the result of the next50* {@link #engineGenExemptionBlob(byte[], int) engineGenExemptionBlob}51* operation, given the input length <code>inputLen</code> (in bytes).52*53* <p>The actual output length of the next54* {@link #engineGenExemptionBlob(byte[], int) engineGenExemptionBlob}55* call may be smaller than the length returned by this method.56*57* @param inputLen the input length (in bytes)58*59* @return the required output buffer size (in bytes)60*/61protected abstract int engineGetOutputSize(int inputLen);6263/**64* Initializes this exemption mechanism with a key.65*66* <p>If this exemption mechanism requires any algorithm parameters67* that cannot be derived from the given <code>key</code>, the underlying68* exemption mechanism implementation is supposed to generate the required69* parameters itself (using provider-specific default values); in the case70* that algorithm parameters must be specified by the caller, an71* <code>InvalidKeyException</code> is raised.72*73* @param key the key for this exemption mechanism74*75* @exception InvalidKeyException if the given key is inappropriate for76* this exemption mechanism.77* @exception ExemptionMechanismException if problem(s) encountered in the78* process of initializing.79*/80protected abstract void engineInit(Key key)81throws InvalidKeyException, ExemptionMechanismException;8283/**84* Initializes this exemption mechanism with a key and a set of algorithm85* parameters.86*87* <p>If this exemption mechanism requires any algorithm parameters and88* <code>params</code> is null, the underlying exemption mechanism89* implementation is supposed to generate the required parameters90* itself (using provider-specific default values); in the case that91* algorithm parameters must be specified by the caller, an92* <code>InvalidAlgorithmParameterException</code> is raised.93*94* @param key the key for this exemption mechanism95* @param params the algorithm parameters96*97* @exception InvalidKeyException if the given key is inappropriate for98* this exemption mechanism.99* @exception InvalidAlgorithmParameterException if the given algorithm100* parameters are inappropriate for this exemption mechanism.101* @exception ExemptionMechanismException if problem(s) encountered in the102* process of initializing.103*/104protected abstract void engineInit(Key key, AlgorithmParameterSpec params)105throws InvalidKeyException, InvalidAlgorithmParameterException,106ExemptionMechanismException;107108/**109* Initializes this exemption mechanism with a key and a set of algorithm110* parameters.111*112* <p>If this exemption mechanism requires any algorithm parameters113* and <code>params</code> is null, the underlying exemption mechanism114* implementation is supposed to generate the required parameters115* itself (using provider-specific default values); in the case that116* algorithm parameters must be specified by the caller, an117* <code>InvalidAlgorithmParameterException</code> is raised.118*119* @param key the key for this exemption mechanism120* @param params the algorithm parameters121*122* @exception InvalidKeyException if the given key is inappropriate for123* this exemption mechanism.124* @exception InvalidAlgorithmParameterException if the given algorithm125* parameters are inappropriate for this exemption mechanism.126* @exception ExemptionMechanismException if problem(s) encountered in the127* process of initializing.128*/129protected abstract void engineInit(Key key, AlgorithmParameters params)130throws InvalidKeyException, InvalidAlgorithmParameterException,131ExemptionMechanismException;132133/**134* Generates the exemption mechanism key blob.135*136* @return the new buffer with the result key blob.137*138* @exception ExemptionMechanismException if problem(s) encountered in the139* process of generating.140*/141protected abstract byte[] engineGenExemptionBlob()142throws ExemptionMechanismException;143144/**145* Generates the exemption mechanism key blob, and stores the result in146* the <code>output</code> buffer, starting at <code>outputOffset</code>147* inclusive.148*149* <p>If the <code>output</code> buffer is too small to hold the result,150* a <code>ShortBufferException</code> is thrown. In this case, repeat this151* call with a larger output buffer. Use152* {@link #engineGetOutputSize(int) engineGetOutputSize} to determine153* how big the output buffer should be.154*155* @param output the buffer for the result156* @param outputOffset the offset in <code>output</code> where the result157* is stored158*159* @return the number of bytes stored in <code>output</code>160*161* @exception ShortBufferException if the given output buffer is too small162* to hold the result.163* @exception ExemptionMechanismException if problem(s) encountered in the164* process of generating.165*/166protected abstract int engineGenExemptionBlob167(byte[] output, int outputOffset)168throws ShortBufferException, ExemptionMechanismException;169}170171172