Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/javax/net/ssl/SSLEngineResult.java
38918 views
/*1* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.net.ssl;2627/**28* An encapsulation of the result state produced by29* <code>SSLEngine</code> I/O calls.30*31* <p> A <code>SSLEngine</code> provides a means for establishing32* secure communication sessions between two peers. <code>SSLEngine</code>33* operations typically consume bytes from an input buffer and produce34* bytes in an output buffer. This class provides operational result35* values describing the state of the <code>SSLEngine</code>, including36* indications of what operations are needed to finish an37* ongoing handshake. Lastly, it reports the number of bytes consumed38* and produced as a result of this operation.39*40* @see SSLEngine41* @see SSLEngine#wrap(ByteBuffer, ByteBuffer)42* @see SSLEngine#unwrap(ByteBuffer, ByteBuffer)43*44* @author Brad R. Wetmore45* @since 1.546*/4748public class SSLEngineResult {4950/**51* An <code>SSLEngineResult</code> enum describing the overall result52* of the <code>SSLEngine</code> operation.53*54* The <code>Status</code> value does not reflect the55* state of a <code>SSLEngine</code> handshake currently56* in progress. The <code>SSLEngineResult's HandshakeStatus</code>57* should be consulted for that information.58*59* @author Brad R. Wetmore60* @since 1.561*/62public static enum Status {6364/**65* The <code>SSLEngine</code> was not able to unwrap the66* incoming data because there were not enough source bytes67* available to make a complete packet.68*69* <P>70* Repeat the call once more bytes are available.71*/72BUFFER_UNDERFLOW,7374/**75* The <code>SSLEngine</code> was not able to process the76* operation because there are not enough bytes available in the77* destination buffer to hold the result.78* <P>79* Repeat the call once more bytes are available.80*81* @see SSLSession#getPacketBufferSize()82* @see SSLSession#getApplicationBufferSize()83*/84BUFFER_OVERFLOW,8586/**87* The <code>SSLEngine</code> completed the operation, and88* is available to process similar calls.89*/90OK,9192/**93* The operation just closed this side of the94* <code>SSLEngine</code>, or the operation95* could not be completed because it was already closed.96*/97CLOSED;98}99100/**101* An <code>SSLEngineResult</code> enum describing the current102* handshaking state of this <code>SSLEngine</code>.103*104* @author Brad R. Wetmore105* @since 1.5106*/107public static enum HandshakeStatus {108109/**110* The <code>SSLEngine</code> is not currently handshaking.111*/112NOT_HANDSHAKING,113114/**115* The <code>SSLEngine</code> has just finished handshaking.116* <P>117* This value is only generated by a call to118* <code>SSLEngine.wrap()/unwrap()</code> when that call119* finishes a handshake. It is never generated by120* <code>SSLEngine.getHandshakeStatus()</code>.121*122* @see SSLEngine#wrap(ByteBuffer, ByteBuffer)123* @see SSLEngine#unwrap(ByteBuffer, ByteBuffer)124* @see SSLEngine#getHandshakeStatus()125*/126FINISHED,127128/**129* The <code>SSLEngine</code> needs the results of one (or more)130* delegated tasks before handshaking can continue.131*132* @see SSLEngine#getDelegatedTask()133*/134NEED_TASK,135136/**137* The <code>SSLEngine</code> must send data to the remote side138* before handshaking can continue, so <code>SSLEngine.wrap()</code>139* should be called.140*141* @see SSLEngine#wrap(ByteBuffer, ByteBuffer)142*/143NEED_WRAP,144145/**146* The <code>SSLEngine</code> needs to receive data from the147* remote side before handshaking can continue.148*/149NEED_UNWRAP;150}151152153private final Status status;154private final HandshakeStatus handshakeStatus;155private final int bytesConsumed;156private final int bytesProduced;157158/**159* Initializes a new instance of this class.160*161* @param status162* the return value of the operation.163*164* @param handshakeStatus165* the current handshaking status.166*167* @param bytesConsumed168* the number of bytes consumed from the source ByteBuffer169*170* @param bytesProduced171* the number of bytes placed into the destination ByteBuffer172*173* @throws IllegalArgumentException174* if the <code>status</code> or <code>handshakeStatus</code>175* arguments are null, or if <code>bytesConsumed</code> or176* <code>bytesProduced</code> is negative.177*/178public SSLEngineResult(Status status, HandshakeStatus handshakeStatus,179int bytesConsumed, int bytesProduced) {180181if ((status == null) || (handshakeStatus == null) ||182(bytesConsumed < 0) || (bytesProduced < 0)) {183throw new IllegalArgumentException("Invalid Parameter(s)");184}185186this.status = status;187this.handshakeStatus = handshakeStatus;188this.bytesConsumed = bytesConsumed;189this.bytesProduced = bytesProduced;190}191192/**193* Gets the return value of this <code>SSLEngine</code> operation.194*195* @return the return value196*/197final public Status getStatus() {198return status;199}200201/**202* Gets the handshake status of this <code>SSLEngine</code>203* operation.204*205* @return the handshake status206*/207final public HandshakeStatus getHandshakeStatus() {208return handshakeStatus;209}210211/**212* Returns the number of bytes consumed from the input buffer.213*214* @return the number of bytes consumed.215*/216final public int bytesConsumed() {217return bytesConsumed;218}219220/**221* Returns the number of bytes written to the output buffer.222*223* @return the number of bytes produced224*/225final public int bytesProduced() {226return bytesProduced;227}228229/**230* Returns a String representation of this object.231*/232@Override233public String toString() {234return ("Status = " + status +235" HandshakeStatus = " + handshakeStatus +236"\nbytesConsumed = " + bytesConsumed +237" bytesProduced = " + bytesProduced);238}239}240241242