001 /*
002 * Copyright 1997-2004 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025
026 package java.security;
027
028 import java.io.*;
029 import java.security.spec.AlgorithmParameterSpec;
030 import java.security.spec.InvalidParameterSpecException;
031
032 /**
033 * This class defines the <i>Service Provider Interface</i> (<b>SPI</b>)
034 * for the <code>AlgorithmParameters</code> class, which is used to manage
035 * algorithm parameters.
036 *
037 * <p> All the abstract methods in this class must be implemented by each
038 * cryptographic service provider who wishes to supply parameter management
039 * for a particular algorithm.
040 *
041 * @author Jan Luehe
042 *
043 * @version 1.20, 05/05/07
044 *
045 * @see AlgorithmParameters
046 * @see java.security.spec.AlgorithmParameterSpec
047 * @see java.security.spec.DSAParameterSpec
048 *
049 * @since 1.2
050 */
051
052 public abstract class AlgorithmParametersSpi {
053
054 /**
055 * Initializes this parameters object using the parameters
056 * specified in <code>paramSpec</code>.
057 *
058 * @param paramSpec the parameter specification.
059 *
060 * @exception InvalidParameterSpecException if the given parameter
061 * specification is inappropriate for the initialization of this parameter
062 * object.
063 */
064 protected abstract void engineInit(AlgorithmParameterSpec paramSpec)
065 throws InvalidParameterSpecException;
066
067 /**
068 * Imports the specified parameters and decodes them
069 * according to the primary decoding format for parameters.
070 * The primary decoding format for parameters is ASN.1, if an ASN.1
071 * specification for this type of parameters exists.
072 *
073 * @param params the encoded parameters.
074 *
075 * @exception IOException on decoding errors
076 */
077 protected abstract void engineInit(byte[] params)
078 throws IOException;
079
080 /**
081 * Imports the parameters from <code>params</code> and
082 * decodes them according to the specified decoding format.
083 * If <code>format</code> is null, the
084 * primary decoding format for parameters is used. The primary decoding
085 * format is ASN.1, if an ASN.1 specification for these parameters
086 * exists.
087 *
088 * @param params the encoded parameters.
089 *
090 * @param format the name of the decoding format.
091 *
092 * @exception IOException on decoding errors
093 */
094 protected abstract void engineInit(byte[] params, String format)
095 throws IOException;
096
097 /**
098 * Returns a (transparent) specification of this parameters
099 * object.
100 * <code>paramSpec</code> identifies the specification class in which
101 * the parameters should be returned. It could, for example, be
102 * <code>DSAParameterSpec.class</code>, to indicate that the
103 * parameters should be returned in an instance of the
104 * <code>DSAParameterSpec</code> class.
105 *
106 * @param paramSpec the the specification class in which
107 * the parameters should be returned.
108 *
109 * @return the parameter specification.
110 *
111 * @exception InvalidParameterSpecException if the requested parameter
112 * specification is inappropriate for this parameter object.
113 */
114 protected abstract <T extends AlgorithmParameterSpec> T engineGetParameterSpec(
115 Class<T> paramSpec) throws InvalidParameterSpecException;
116
117 /**
118 * Returns the parameters in their primary encoding format.
119 * The primary encoding format for parameters is ASN.1, if an ASN.1
120 * specification for this type of parameters exists.
121 *
122 * @return the parameters encoded using their primary encoding format.
123 *
124 * @exception IOException on encoding errors.
125 */
126 protected abstract byte[] engineGetEncoded() throws IOException;
127
128 /**
129 * Returns the parameters encoded in the specified format.
130 * If <code>format</code> is null, the
131 * primary encoding format for parameters is used. The primary encoding
132 * format is ASN.1, if an ASN.1 specification for these parameters
133 * exists.
134 *
135 * @param format the name of the encoding format.
136 *
137 * @return the parameters encoded using the specified encoding scheme.
138 *
139 * @exception IOException on encoding errors.
140 */
141 protected abstract byte[] engineGetEncoded(String format)
142 throws IOException;
143
144 /**
145 * Returns a formatted string describing the parameters.
146 *
147 * @return a formatted string describing the parameters.
148 */
149 protected abstract String engineToString();
150 }
|