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