Home | History | Annotate | Download | only in security
      1 /*
      2  *  Licensed to the Apache Software Foundation (ASF) under one or more
      3  *  contributor license agreements.  See the NOTICE file distributed with
      4  *  this work for additional information regarding copyright ownership.
      5  *  The ASF licenses this file to You under the Apache License, Version 2.0
      6  *  (the "License"); you may not use this file except in compliance with
      7  *  the License.  You may obtain a copy of the License at
      8  *
      9  *     http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  *  Unless required by applicable law or agreed to in writing, software
     12  *  distributed under the License is distributed on an "AS IS" BASIS,
     13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  *  See the License for the specific language governing permissions and
     15  *  limitations under the License.
     16  */
     17 
     18 package java.security;
     19 
     20 import java.io.IOException;
     21 import java.security.spec.AlgorithmParameterSpec;
     22 import java.security.spec.InvalidParameterSpecException;
     23 
     24 /**
     25  * {@code AlgorithmParametersSpi} is the Service Provider Interface (SPI)
     26  * definition for {@code AlgorithmParameters}.
     27  *
     28  * @see AlgorithmParameters
     29  */
     30 public abstract class AlgorithmParametersSpi {
     31 
     32     /**
     33      * Initializes this {@code AlgorithmParametersSpi} with the specified
     34      * {@code AlgorithmParameterSpec}.
     35      *
     36      * @param paramSpec
     37      *            the parameter specification.
     38      * @throws InvalidParameterSpecException
     39      *             if this {@code AlgorithmParametersSpi} has already been
     40      *             initialized or the given {@code paramSpec} is not appropriate
     41      *             for initializing this {@code AlgorithmParametersSpi}.
     42      */
     43     protected abstract void engineInit(AlgorithmParameterSpec paramSpec)
     44             throws InvalidParameterSpecException;
     45 
     46     /**
     47      * Initializes this {@code AlgorithmParametersSpi} with the specified
     48      * {@code byte[]} using the default decoding format for parameters. The
     49      * default encoding format is ASN.1.
     50      *
     51      * @param params
     52      *            the encoded parameters.
     53      * @throws IOException
     54      *             if this {@code AlgorithmParametersSpi} has already been
     55      *             initialized, or the parameter could not be encoded.
     56      */
     57     protected abstract void engineInit(byte[] params) throws IOException;
     58 
     59     /**
     60      * Initializes this {@code AlgorithmParametersSpi} with the specified
     61      * {@code byte[]} using the specified decoding format.
     62      *
     63      * @param params
     64      *            the encoded parameters.
     65      * @param format
     66      *            the name of the decoding format.
     67      * @throws IOException
     68      *             if this {@code AlgorithmParametersSpi} has already been
     69      *             initialized, or the parameter could not be encoded.
     70      */
     71     protected abstract void engineInit(byte[] params, String format)
     72             throws IOException;
     73 
     74     /**
     75      * Returns the {@code AlgorithmParameterSpec} for this {@code
     76      * AlgorithmParametersSpi}.
     77      *
     78      * @param paramSpec
     79      *            the type of the parameter specification in which this
     80      *            parameters should be converted.
     81      * @return the {@code AlgorithmParameterSpec} for this {@code
     82      *         AlgorithmParametersSpi}.
     83      * @throws InvalidParameterSpecException
     84      *             if this {@code AlgorithmParametersSpi} has already been
     85      *             initialized, or if this parameters could not be converted to
     86      *             the specified class.
     87      */
     88     protected abstract <T extends AlgorithmParameterSpec> T engineGetParameterSpec(
     89             Class<T> paramSpec) throws InvalidParameterSpecException;
     90 
     91     /**
     92      * Returns the parameters in their default encoding format. The default
     93      * encoding format is ASN.1.
     94      *
     95      * @return the encoded parameters.
     96      * @throws IOException
     97      *             if this {@code AlgorithmParametersSpi} has already been
     98      *             initialized, or if this parameters could not be encoded.
     99      */
    100     protected abstract byte[] engineGetEncoded() throws IOException;
    101 
    102     /**
    103      * Returns the parameters in the specified encoding format.
    104      *
    105      * @param format
    106      *            the name of the encoding format.
    107      * @return the encoded parameters.
    108      * @throws IOException
    109      *             if this {@code AlgorithmParametersSpi} has already been
    110      *             initialized, or if this parameters could not be encoded.
    111      */
    112     protected abstract byte[] engineGetEncoded(String format)
    113             throws IOException;
    114 
    115     /**
    116      * Returns a string containing a concise, human-readable description of this
    117      * {@code AlgorithmParametersSpi}.
    118      *
    119      * @return a printable representation for this {@code
    120      *         AlgorithmParametersSpi}.
    121      */
    122     protected abstract String engineToString();
    123 
    124 }
    125