OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libjava/] [classpath/] [java/] [security/] [Signer.java] - Blame information for rev 14

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 14 jlechner
/* Signer.java --- Signer Class
2
   Copyright (C) 1999, 2003, Free Software Foundation, Inc.
3
 
4
This file is part of GNU Classpath.
5
 
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.
10
 
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.
15
 
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., 51 Franklin Street, Fifth Floor, Boston, MA
19
02110-1301 USA.
20
 
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.
25
 
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. */
37
 
38
package java.security;
39
 
40
/**
41
 * <p>This class is used to represent an {@link Identity} that can also
42
 * digitally sign data.</p>
43
 *
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>
47
 *
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>.
52
 */
53
public abstract class Signer extends Identity
54
{
55
  private static final long serialVersionUID = -1763464102261361480L;
56
  private PrivateKey privateKey = null;
57
 
58
  /**
59
   * Creates a <code>Signer</code>. This constructor should only be used for
60
   * serialization.
61
   */
62
  protected Signer()
63
  {
64
  }
65
 
66
  /**
67
   * Creates a <code>Signer</code> with the specified identity name.
68
   *
69
   * @param name the identity name.
70
   */
71
  public Signer(String name)
72
  {
73
    super(name);
74
  }
75
 
76
  /**
77
   * Creates a <code>Signer</code> with the specified identity name and scope.
78
   *
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.
83
   */
84
  public Signer(String name, IdentityScope scope) throws KeyManagementException
85
  {
86
    super(name, scope);
87
  }
88
 
89
  /**
90
   * <p>Returns this signer's private key.</p>
91
   *
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>
95
   *
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)
102
   */
103
  public PrivateKey getPrivateKey()
104
  {
105
    SecurityManager sm = System.getSecurityManager();
106
    if (sm != null)
107
      sm.checkSecurityAccess("getSignerPrivateKey");
108
 
109
    return privateKey;
110
  }
111
 
112
  /**
113
   * <p>Sets the key pair (public key and private key) for this signer.</p>
114
   *
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>
118
   *
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)
127
   */
128
  public final void setKeyPair(KeyPair pair)
129
    throws InvalidParameterException, KeyException
130
  {
131
    SecurityManager sm = System.getSecurityManager();
132
    if (sm != null)
133
      sm.checkSecurityAccess("setSignerKeyPair");
134
 
135
    try
136
      {
137
        if (pair.getPublic() != null)
138
          setPublicKey(pair.getPublic());
139
        else
140
          throw new InvalidParameterException();
141
 
142
      }
143
    catch (KeyManagementException kme)
144
      {
145
        throw new KeyException();
146
      }
147
 
148
    if (pair.getPrivate() != null)
149
        privateKey = pair.getPrivate();
150
    else
151
      throw new InvalidParameterException();
152
  }
153
 
154
  /**
155
   * Returns a string of information about the signer.
156
   *
157
   * @return a string of information about the signer.
158
   * @see SecurityManager#checkSecurityAccess(String)
159
   */
160
  public String toString()
161
  {
162
    return (getName() + ": " + privateKey);
163
  }
164
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.