2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libjava / java / security / cert / PKIXBuilderParameters.java
blobbb44a0561986c0532489189ce59a72b38153a08b
1 /* PKIXBuilderParameters.java -- parameters for PKIX cert path builders
2 Copyright (C) 2003 Free Software Foundation, Inc.
4 This file is 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, or (at your option)
9 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; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 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 java.security.cert;
41 import java.security.InvalidAlgorithmParameterException;
42 import java.security.KeyStore;
43 import java.security.KeyStoreException;
45 import java.util.Set;
47 /**
48 * Parameters for building certificate paths using the PKIX algorithm.
50 * @see CertPathBuilder
52 public class PKIXBuilderParameters extends PKIXParameters
55 // Fields.
56 // ------------------------------------------------------------------------
58 /** The maximum path length. */
59 private int maxPathLength;
61 // Constructors.
62 // ------------------------------------------------------------------------
64 /**
65 * Create a new PKIXBuilderParameters object, populating the trusted
66 * certificates set with all X.509 certificates found in the given key
67 * store. All certificates found in the key store are assumed to be
68 * trusted by this constructor.
70 * @param keystore The key store.
71 * @param targetConstraints The target certificate constraints.
72 * @throws KeyStoreException If the certificates cannot be retrieved
73 * from the key store.
74 * @throws InvalidAlgorithmParameterException If there are no
75 * certificates in the key store.
76 * @throws NullPointerException If <i>keystore</i> is null.
78 public PKIXBuilderParameters(KeyStore keystore,
79 CertSelector targetConstraints)
80 throws KeyStoreException, InvalidAlgorithmParameterException
82 super(keystore);
83 setTargetCertConstraints(targetConstraints);
84 maxPathLength = 5;
87 /**
88 * Create a new PKIXBuilderParameters object, populating the trusted
89 * certificates set with the elements of the given set, each of which
90 * must be a {@link TrustAnchor}.
92 * @param trustAnchors The set of trust anchors.
93 * @param targetConstraints The target certificate constraints.
94 * @throws InvalidAlgorithmParameterException If there are no
95 * certificates in the set.
96 * @throws NullPointerException If <i>trustAnchors</i> is null.
97 * @throws ClassCastException If every element in <i>trustAnchors</i>
98 * is not a {@link TrustAnchor}.
100 public PKIXBuilderParameters(Set trustAnchors, CertSelector targetConstraints)
101 throws InvalidAlgorithmParameterException
103 super(trustAnchors);
104 setTargetCertConstraints(targetConstraints);
105 maxPathLength = 5;
108 // Instance methods.
109 // ------------------------------------------------------------------------
112 * Returns the maximum length of certificate paths to build.
114 * <p>If this value is 0 it is taken to mean that the certificate path
115 * should contain only one certificate. A value of -1 means that the
116 * certificate path length is unconstrained. The default value is 5.
118 * @return The maximum path length.
120 public int getMaxPathLength()
122 return maxPathLength;
126 * Sets the maximum length of certificate paths to build.
128 * @param maxPathLength The new path length.
129 * @throws IllegalArgumentException If <i>maxPathLength</i> is less
130 * than -1.
132 public void setMaxPathLength(int maxPathLength)
134 if (maxPathLength < -1)
135 throw new IllegalArgumentException();
136 this.maxPathLength = maxPathLength;
139 public String toString()
141 StringBuffer buf = new StringBuffer(super.toString());
142 buf.insert(buf.length() - 2, "; Max Path Length=" + maxPathLength);
143 return buf.toString();