Merge from mainline (gomp-merge-2005-02-26).
[official-gcc.git] / libjava / java / security / Signer.java
bloba9e20d42cabd055b10a19abbe2c60fd6fbed5230
1 /* Signer.java --- Signer Class
2 Copyright (C) 1999, 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. */
38 package java.security;
40 /**
41 * <p>This class is used to represent an {@link Identity} that can also
42 * digitally sign data.</p>
44 * <p>The management of a signer's private keys is an important and sensitive
45 * issue that should be handled by subclasses as appropriate to their intended
46 * use.</p>
48 * @author Mark Benvenuto (ivymccough@worldnet.att.net)
49 * @deprecated This class is no longer used. Its functionality has been replaced
50 * by <code>java.security.KeyStore</code>, the <code>java.security.cert</code>
51 * package, and <code>java.security.Principal</code>.
53 public abstract class Signer extends Identity
55 private static final long serialVersionUID = -1763464102261361480L;
56 private PrivateKey privateKey = null;
58 /**
59 * Creates a <code>Signer</code>. This constructor should only be used for
60 * serialization.
62 protected Signer()
66 /**
67 * Creates a <code>Signer</code> with the specified identity name.
69 * @param name the identity name.
71 public Signer(String name)
73 super(name);
76 /**
77 * Creates a <code>Signer</code> with the specified identity name and scope.
79 * @param name the identity name.
80 * @param scope the scope of the identity.
81 * @throws KeyManagementException if there is already an identity with the
82 * same name in the scope.
84 public Signer(String name, IdentityScope scope) throws KeyManagementException
86 super(name, scope);
89 /**
90 * <p>Returns this signer's private key.</p>
92 * <p>First, if there is a security manager, its <code>checkSecurityAccess()
93 * </code> method is called with <code>"getSignerPrivateKey"</code> as its
94 * argument to see if it's ok to return the private key.</p>
96 * @return this signer's private key, or <code>null</code> if the private key
97 * has not yet been set.
98 * @throws SecurityException if a security manager exists and its
99 * <code>checkSecurityAccess()</code> method doesn't allow returning the
100 * private key.
101 * @see SecurityManager#checkSecurityAccess(String)
103 public PrivateKey getPrivateKey()
105 SecurityManager sm = System.getSecurityManager();
106 if (sm != null)
107 sm.checkSecurityAccess("getSignerPrivateKey");
109 return privateKey;
113 * <p>Sets the key pair (public key and private key) for this signer.</p>
115 * <p>First, if there is a security manager, its <code>checkSecurityAccess()
116 * </code> method is called with <code>"setSignerKeyPair"</code> as its
117 * argument to see if it's ok to set the key pair.</p>
119 * @param pair an initialized key pair.
120 * @throws InvalidParameterException if the key pair is not properly
121 * initialized.
122 * @throws KeyException if the key pair cannot be set for any other reason.
123 * @throws SecurityException if a security manager exists and its
124 * <code>checkSecurityAccess()</code> method doesn't allow setting the key
125 * pair.
126 * @see SecurityManager#checkSecurityAccess(String)
128 public final void setKeyPair(KeyPair pair)
129 throws InvalidParameterException, KeyException
131 SecurityManager sm = System.getSecurityManager();
132 if (sm != null)
133 sm.checkSecurityAccess("setSignerKeyPair");
137 if (pair.getPublic() != null)
138 setPublicKey(pair.getPublic());
139 else
140 throw new InvalidParameterException();
143 catch (KeyManagementException kme)
145 throw new KeyException();
148 if (pair.getPrivate() != null)
149 privateKey = pair.getPrivate();
150 else
151 throw new InvalidParameterException();
155 * Returns a string of information about the signer.
157 * @return a string of information about the signer.
158 * @see SecurityManager#checkSecurityAccess(String)
160 public String toString()
162 return (getName() + ": " + privateKey);