Path: blob/master/src/java.base/share/classes/java/security/AlgorithmParametersSpi.java
41152 views
/*1* Copyright (c) 1997, 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 java.security;2627import java.io.*;28import java.security.spec.AlgorithmParameterSpec;29import java.security.spec.InvalidParameterSpecException;3031/**32* This class defines the <i>Service Provider Interface</i> (<b>SPI</b>)33* for the {@code AlgorithmParameters} class, which is used to manage34* algorithm parameters.35*36* <p> All the abstract methods in this class must be implemented by each37* cryptographic service provider who wishes to supply parameter management38* for a particular algorithm.39*40* @author Jan Luehe41*42*43* @see AlgorithmParameters44* @see java.security.spec.AlgorithmParameterSpec45* @see java.security.spec.DSAParameterSpec46*47* @since 1.248*/4950public abstract class AlgorithmParametersSpi {5152/**53* Constructor for subclasses to call.54*/55public AlgorithmParametersSpi() {}5657/**58* Initializes this parameters object using the parameters59* specified in {@code paramSpec}.60*61* @param paramSpec the parameter specification.62*63* @throws InvalidParameterSpecException if the given parameter64* specification is inappropriate for the initialization of this parameter65* object.66*/67protected abstract void engineInit(AlgorithmParameterSpec paramSpec)68throws InvalidParameterSpecException;6970/**71* Imports the specified parameters and decodes them72* according to the primary decoding format for parameters.73* The primary decoding format for parameters is ASN.1, if an ASN.174* specification for this type of parameters exists.75*76* @param params the encoded parameters.77*78* @throws IOException on decoding errors79*/80protected abstract void engineInit(byte[] params)81throws IOException;8283/**84* Imports the parameters from {@code params} and85* decodes them according to the specified decoding format.86* If {@code format} is null, the87* primary decoding format for parameters is used. The primary decoding88* format is ASN.1, if an ASN.1 specification for these parameters89* exists.90*91* @param params the encoded parameters.92*93* @param format the name of the decoding format.94*95* @throws IOException on decoding errors96*/97protected abstract void engineInit(byte[] params, String format)98throws IOException;99100/**101* Returns a (transparent) specification of this parameters102* object.103* {@code paramSpec} identifies the specification class in which104* the parameters should be returned. It could, for example, be105* {@code DSAParameterSpec.class}, to indicate that the106* parameters should be returned in an instance of the107* {@code DSAParameterSpec} class.108*109* @param <T> the type of the parameter specification to be returned110*111* @param paramSpec the specification class in which112* the parameters should be returned.113*114* @return the parameter specification.115*116* @throws InvalidParameterSpecException if the requested parameter117* specification is inappropriate for this parameter object.118*/119protected abstract120<T extends AlgorithmParameterSpec>121T engineGetParameterSpec(Class<T> paramSpec)122throws InvalidParameterSpecException;123124/**125* Returns the parameters in their primary encoding format.126* The primary encoding format for parameters is ASN.1, if an ASN.1127* specification for this type of parameters exists.128*129* @return the parameters encoded using their primary encoding format.130*131* @throws IOException on encoding errors.132*/133protected abstract byte[] engineGetEncoded() throws IOException;134135/**136* Returns the parameters encoded in the specified format.137* If {@code format} is null, the138* primary encoding format for parameters is used. The primary encoding139* format is ASN.1, if an ASN.1 specification for these parameters140* exists.141*142* @param format the name of the encoding format.143*144* @return the parameters encoded using the specified encoding scheme.145*146* @throws IOException on encoding errors.147*/148protected abstract byte[] engineGetEncoded(String format)149throws IOException;150151/**152* Returns a formatted string describing the parameters.153*154* @return a formatted string describing the parameters.155*/156protected abstract String engineToString();157}158159160