Imported GNU Classpath 0.90
[official-gcc.git] / libjava / classpath / gnu / java / security / jce / sig / DSSKeyPairGeneratorSpi.java
blob44503b26b9aebc08fc731884b110518dae926f91
1 /* DSSKeyPairGeneratorSpi.java --
2 Copyright 2001, 2002, 2006 Free Software Foundation, Inc.
4 This file is a part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or (at
9 your option) any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
19 USA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package gnu.java.security.jce.sig;
41 import gnu.java.security.Registry;
42 import gnu.java.security.key.dss.DSSKeyPairGenerator;
44 import java.security.InvalidAlgorithmParameterException;
45 import java.security.InvalidParameterException;
46 import java.security.SecureRandom;
47 import java.security.interfaces.DSAKeyPairGenerator;
48 import java.security.interfaces.DSAParams;
49 import java.security.spec.AlgorithmParameterSpec;
50 import java.security.spec.DSAParameterSpec;
51 import java.util.HashMap;
53 /**
54 * The implementation of a {@link java.security.KeyPairGenerator} adapter class
55 * to wrap gnu.crypto DSS keypair generator instances.<p>
57 * In case the client does not explicitly initialize the KeyPairGenerator (via
58 * a call to an <code>initialize()</code> method), the GNU Crypto provider
59 * uses a default <i>modulus</i> size (keysize) of 1024 bits.<p>
61 public class DSSKeyPairGeneratorSpi extends KeyPairGeneratorAdapter implements
62 DSAKeyPairGenerator
65 // Constants and variables
66 // -------------------------------------------------------------------------
68 // Constructor(s)
69 // -------------------------------------------------------------------------
71 public DSSKeyPairGeneratorSpi()
73 super(Registry.DSS_KPG);
76 // Class methods
77 // -------------------------------------------------------------------------
79 // Instance methods
80 // -------------------------------------------------------------------------
82 public void initialize(int keysize, SecureRandom random)
84 this.initialize(keysize, false, random);
87 public void initialize(AlgorithmParameterSpec params, SecureRandom random)
88 throws InvalidAlgorithmParameterException
90 HashMap attributes = new HashMap();
91 if (params != null)
93 if (!(params instanceof DSAParameterSpec))
94 throw new InvalidAlgorithmParameterException(
95 "Parameters argument is not a non-null instance, or " +
96 "sub-instance, of java.security.spec.DSAParameterSpec");
98 attributes.put(DSSKeyPairGenerator.DSS_PARAMETERS, params);
101 if (random != null)
103 attributes.put(DSSKeyPairGenerator.SOURCE_OF_RANDOMNESS, random);
106 attributes.put(DSSKeyPairGenerator.PREFERRED_ENCODING_FORMAT,
107 new Integer(Registry.ASN1_ENCODING_ID));
110 adaptee.setup(attributes);
112 catch (IllegalArgumentException x)
114 InvalidAlgorithmParameterException y =
115 new InvalidAlgorithmParameterException();
116 y.initCause(x);
117 throw y;
121 // java.security.interfaces.DSAKeyPairGenerator interface implementation -----
123 public void initialize(DSAParams params, SecureRandom random)
124 throws InvalidParameterException
126 if (params == null || !(params instanceof DSAParameterSpec))
127 throw new InvalidParameterException(
128 "Parameters argument is either null or is not an instance, or " +
129 "sub-instance, of java.security.spec.DSAParameterSpec");
130 DSAParameterSpec spec = (DSAParameterSpec) params;
133 this.initialize((AlgorithmParameterSpec) spec, random);
135 catch (InvalidAlgorithmParameterException x)
137 InvalidParameterException y = new InvalidParameterException();
138 y.initCause(x);
139 throw y;
143 public void initialize(int modlen, boolean genParams, SecureRandom random)
144 throws InvalidParameterException
146 HashMap attributes = new HashMap();
147 attributes.put(DSSKeyPairGenerator.MODULUS_LENGTH, new Integer(modlen));
148 if (random != null)
149 attributes.put(DSSKeyPairGenerator.SOURCE_OF_RANDOMNESS, random);
151 attributes.put(DSSKeyPairGenerator.USE_DEFAULTS,
152 Boolean.valueOf(!genParams));
153 attributes.put(DSSKeyPairGenerator.STRICT_DEFAULTS, Boolean.TRUE);
154 attributes.put(DSSKeyPairGenerator.PREFERRED_ENCODING_FORMAT,
155 new Integer(Registry.ASN1_ENCODING_ID));
158 adaptee.setup(attributes);
160 catch (IllegalArgumentException x)
162 InvalidParameterException y = new InvalidParameterException();
163 y.initCause(x);
164 throw y;