OSDN Git Service

Merged gcj-eclipse branch to trunk.
[pf3gnuchains/gcc-fork.git] / libjava / classpath / javax / net / ssl / SSLEngineResult.java
1 /* SSLEngineResult.java -- 
2    Copyright (C) 2006 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., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 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
39 package javax.net.ssl;
40
41 /**
42  * A result from an {@link SSLEngine} <code>wrap</code> or
43  * <code>unwrap</code> operation. This class conveys a possibly
44  * intermediate result, and may ask for more input data or request
45  * that output data be sent over a connection.
46  */
47 public class SSLEngineResult
48 {
49   private final HandshakeStatus handshakeStatus;
50   private final Status status;
51   private final int bytesConsumed;
52   private final int bytesProduced;
53
54   /**
55    * Creates a new SSL engine result.
56    *
57    * @param status The status of the SSL connection.
58    * @param handshakeStatus The status of the SSL handshake.
59    * @param bytesConsumed The number of bytes consumed by the previous
60    * operation.
61    * @param bytesProduced The number of bytes produced by the previous
62    * operation.
63    * @throws IllegalArgumentException If either enum value is
64    * <code>null</code>, or if either integer is negative.
65    */
66   public SSLEngineResult (Status status, HandshakeStatus handshakeStatus,
67                           int bytesConsumed, int bytesProduced)
68   {
69     if (status == null)
70       throw new IllegalArgumentException ("'status' may not be null");
71     if (handshakeStatus == null)
72       throw new IllegalArgumentException ("'handshakeStatus' may not be null");
73     if (bytesConsumed < 0)
74       throw new IllegalArgumentException ("'bytesConumed' must be nonnegative");
75     if (bytesProduced < 0)
76       throw new IllegalArgumentException ("'bytesProduced' must be nonnegative");
77     this.status = status;
78     this.handshakeStatus = handshakeStatus;
79     this.bytesConsumed = bytesConsumed;
80     this.bytesProduced = bytesProduced;
81   }
82
83 \f
84
85   /**
86    * An enumeration of possible general states.
87    */
88   public static enum Status
89   {
90
91     /**
92      * There were not enough input bytes available to complete the
93      * operation.
94      */
95     BUFFER_UNDERFLOW,
96
97     /**
98      * There was not enough space for the output message.
99      */
100     BUFFER_OVERFLOW,
101
102     /**
103      * Okay. No error.
104      */
105     OK,
106
107     /**
108      * The connection is closed.
109      */
110     CLOSED
111   }
112
113   /**
114    * An enumeration of possible handshake status states.
115    */
116   public static enum HandshakeStatus
117   {
118
119     /**
120      * Not currently handshaking.
121      */
122     NOT_HANDSHAKING,
123
124     /**
125      * The handshake is finished.
126      */
127     FINISHED,
128
129     /**
130      * Needs the status of one or more delegated tasks.
131      */
132     NEED_TASK,
133
134     /**
135      * Has data prepared for output, and needs a new call to
136      * <code>wrap</code>.
137      */
138     NEED_WRAP,
139
140     /**
141      * Is waiting for more input.
142      */
143     NEED_UNWRAP
144   }
145
146 \f
147
148   /**
149    * Returns the number of bytes consumed by the previous operation.
150    *
151    * @return The number of bytes consumed.
152    */
153   public int bytesConsumed ()
154   {
155     return bytesConsumed;
156   }
157
158   /**
159    * Returns the number of bytes produced by the previous operation.
160    *
161    * @return The number of bytes produced.
162    */
163   public int bytesProduced ()
164   {
165     return bytesProduced;
166   }
167
168   /**
169    * Returns the handshake status.
170    *
171    * @return The handshake status.
172    */
173   public HandshakeStatus getHandshakeStatus ()
174   {
175     return handshakeStatus;
176   }
177
178   /**
179    * Returns the connection status.
180    *
181    * @return The connection status.
182    */
183   public Status getStatus ()
184   {
185     return status;
186   }
187
188   public String toString ()
189   {
190     return (super.toString () + " [ status: " + status + "; handshakeStatus: "
191             + handshakeStatus + "; bytesConsumed: " + bytesConsumed
192             + "; bytesProduced: " + bytesProduced + " ]");
193   }
194 }