jdk/src/java.base/share/classes/javax/net/ssl/SSLEngineResult.java
author martin
Tue, 15 Sep 2015 21:56:04 -0700
changeset 32649 2ee9017c7597
parent 31646 6abb6f423de4
child 38963 31331a991a58
permissions -rw-r--r--
8136583: Core libraries should use blessed modifier order Summary: Run blessed-modifier-order script (see bug) Reviewed-by: psandoz, chegar, alanb, plevart
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
     2
 * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.net.ssl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * An encapsulation of the result state produced by
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    30
 * {@code SSLEngine} I/O calls.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 *
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    32
 * <p> A {@code SSLEngine} provides a means for establishing
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    33
 * secure communication sessions between two peers.  {@code SSLEngine}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * operations typically consume bytes from an input buffer and produce
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * bytes in an output buffer.  This class provides operational result
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    36
 * values describing the state of the {@code SSLEngine}, including
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * indications of what operations are needed to finish an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * ongoing handshake.  Lastly, it reports the number of bytes consumed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * and produced as a result of this operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * @see SSLEngine
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * @see SSLEngine#wrap(ByteBuffer, ByteBuffer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * @see SSLEngine#unwrap(ByteBuffer, ByteBuffer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * @author Brad R. Wetmore
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
public class SSLEngineResult {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    /**
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    52
     * An {@code SSLEngineResult} enum describing the overall result
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    53
     * of the {@code SSLEngine} operation.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     *
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    55
     * The {@code Status} value does not reflect the
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    56
     * state of a {@code SSLEngine} handshake currently
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    57
     * in progress.  The {@code SSLEngineResult's HandshakeStatus}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * should be consulted for that information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * @author Brad R. Wetmore
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    public static enum Status {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        /**
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    66
         * The {@code SSLEngine} was not able to unwrap the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
         * incoming data because there were not enough source bytes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
         * available to make a complete packet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
         * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
         * Repeat the call once more bytes are available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        BUFFER_UNDERFLOW,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        /**
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    76
         * The {@code SSLEngine} was not able to process the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
         * operation because there are not enough bytes available in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
         * destination buffer to hold the result.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
         * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
         * Repeat the call once more bytes are available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
         * @see SSLSession#getPacketBufferSize()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
         * @see SSLSession#getApplicationBufferSize()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        BUFFER_OVERFLOW,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        /**
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    88
         * The {@code SSLEngine} completed the operation, and
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
         * is available to process similar calls.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        OK,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
         * The operation just closed this side of the
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    95
         * {@code SSLEngine}, or the operation
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
         * could not be completed because it was already closed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        CLOSED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    /**
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   102
     * An {@code SSLEngineResult} enum describing the current
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   103
     * handshaking state of this {@code SSLEngine}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * @author Brad R. Wetmore
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    public static enum HandshakeStatus {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        /**
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   111
         * The {@code SSLEngine} is not currently handshaking.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        NOT_HANDSHAKING,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        /**
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   116
         * The {@code SSLEngine} has just finished handshaking.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
         * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
         * This value is only generated by a call to
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   119
         * {@code SSLEngine.wrap()/unwrap()} when that call
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
         * finishes a handshake.  It is never generated by
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   121
         * {@code SSLEngine.getHandshakeStatus()}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
         * @see SSLEngine#wrap(ByteBuffer, ByteBuffer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
         * @see SSLEngine#unwrap(ByteBuffer, ByteBuffer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
         * @see SSLEngine#getHandshakeStatus()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        FINISHED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        /**
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   130
         * The {@code SSLEngine} needs the results of one (or more)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
         * delegated tasks before handshaking can continue.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
         * @see SSLEngine#getDelegatedTask()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        NEED_TASK,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        /**
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   138
         * The {@code SSLEngine} must send data to the remote side
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   139
         * before handshaking can continue, so {@code SSLEngine.wrap()}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
         * should be called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
         * @see SSLEngine#wrap(ByteBuffer, ByteBuffer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        NEED_WRAP,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        /**
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   147
         * The {@code SSLEngine} needs to receive data from the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
         * remote side before handshaking can continue.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
         */
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   150
        NEED_UNWRAP,
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   151
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   152
        /**
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   153
         * The {@code SSLEngine} needs to unwrap before handshaking can
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   154
         * can continue.
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   155
         * <P>
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   156
         * This value is used to indicate that not-yet-interpreted data
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   157
         * has been previously received from the remote side, and does
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   158
         * not need to be received again.
31646
6abb6f423de4 8130461: HandshakeStatus.NEED_UNWRAP_AGAIN applies only to DTLS
xuelei
parents: 30967
diff changeset
   159
         * <P>
6abb6f423de4 8130461: HandshakeStatus.NEED_UNWRAP_AGAIN applies only to DTLS
xuelei
parents: 30967
diff changeset
   160
         * This handshake status only applies to DTLS.
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   161
         *
31646
6abb6f423de4 8130461: HandshakeStatus.NEED_UNWRAP_AGAIN applies only to DTLS
xuelei
parents: 30967
diff changeset
   162
         * @since   9
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   163
         */
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   164
        NEED_UNWRAP_AGAIN;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    private final Status status;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    private final HandshakeStatus handshakeStatus;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    private final int bytesConsumed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    private final int bytesProduced;
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   172
    private final long sequenceNumber;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * Initializes a new instance of this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * @param   status
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     *          the return value of the operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * @param   handshakeStatus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     *          the current handshaking status.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * @param   bytesConsumed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     *          the number of bytes consumed from the source ByteBuffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * @param   bytesProduced
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     *          the number of bytes placed into the destination ByteBuffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * @throws  IllegalArgumentException
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   190
     *          if the {@code status} or {@code handshakeStatus}
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   191
     *          arguments are null, or if {@code bytesConsumed} or
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   192
     *          {@code bytesProduced} is negative.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    public SSLEngineResult(Status status, HandshakeStatus handshakeStatus,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            int bytesConsumed, int bytesProduced) {
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   196
        this(status, handshakeStatus, bytesConsumed, bytesProduced, -1);
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   197
    }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   198
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   199
    /**
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   200
     * Initializes a new instance of this class.
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   201
     *
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   202
     * @param   status
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   203
     *          the return value of the operation.
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   204
     *
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   205
     * @param   handshakeStatus
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   206
     *          the current handshaking status.
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   207
     *
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   208
     * @param   bytesConsumed
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   209
     *          the number of bytes consumed from the source ByteBuffer
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   210
     *
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   211
     * @param   bytesProduced
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   212
     *          the number of bytes placed into the destination ByteBuffer
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   213
     *
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   214
     * @param   sequenceNumber
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   215
     *          the sequence number (unsigned long) of the produced or
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   216
     *          consumed SSL/TLS/DTLS record, or ${@code -1L} if no record
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   217
     *          produced or consumed
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   218
     *
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   219
     * @throws  IllegalArgumentException
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   220
     *          if the {@code status} or {@code handshakeStatus}
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   221
     *          arguments are null, or if {@code bytesConsumed} or
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   222
     *          {@code bytesProduced} is negative
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   223
     *
31646
6abb6f423de4 8130461: HandshakeStatus.NEED_UNWRAP_AGAIN applies only to DTLS
xuelei
parents: 30967
diff changeset
   224
     * @since   9
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   225
     */
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   226
    public SSLEngineResult(Status status, HandshakeStatus handshakeStatus,
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   227
            int bytesConsumed, int bytesProduced, long sequenceNumber) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        if ((status == null) || (handshakeStatus == null) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                (bytesConsumed < 0) || (bytesProduced < 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            throw new IllegalArgumentException("Invalid Parameter(s)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        this.status = status;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        this.handshakeStatus = handshakeStatus;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        this.bytesConsumed = bytesConsumed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        this.bytesProduced = bytesProduced;
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   238
        this.sequenceNumber = sequenceNumber;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    /**
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   242
     * Gets the return value of this {@code SSLEngine} operation.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * @return  the return value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 31646
diff changeset
   246
    public final Status getStatus() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        return status;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    /**
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   251
     * Gets the handshake status of this {@code SSLEngine}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * @return  the handshake status
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 31646
diff changeset
   256
    public final HandshakeStatus getHandshakeStatus() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        return handshakeStatus;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * Returns the number of bytes consumed from the input buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * @return  the number of bytes consumed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 31646
diff changeset
   265
    public final int bytesConsumed() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        return bytesConsumed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * Returns the number of bytes written to the output buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * @return  the number of bytes produced
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 31646
diff changeset
   274
    public final int bytesProduced() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        return bytesProduced;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    /**
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   279
     * Returns the sequence number of the produced or consumed SSL/TLS/DTLS
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   280
     * record (optional operation).
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   281
     *
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   282
     * @apiNote  Note that sequence number is an unsigned long and cannot
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   283
     *           exceed {@code -1L}.  It is desired to use the unsigned
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   284
     *           long comparing mode for comparison of unsigned long values
30967
cfeec3444c25 8083664: Update AudioFileWriter to generate working @see reference
darcy
parents: 30904
diff changeset
   285
     *           (see also {@link java.lang.Long#compareUnsigned(long, long)
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   286
     *           Long.compareUnsigned()}).
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   287
     *           <P>
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   288
     *           For DTLS protocols, the first 16 bits of the sequence
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   289
     *           number is a counter value (epoch) that is incremented on
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   290
     *           every cipher state change.  The remaining 48 bits on the
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   291
     *           right side of the sequence number represents the sequence
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   292
     *           of the record, which is maintained separately for each epoch.
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   293
     *
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   294
     * @implNote It is recommended that providers should never allow the
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   295
     *           sequence number incremented to {@code -1L}.  If the sequence
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   296
     *           number is close to wrapping, renegotiate should be requested,
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   297
     *           otherwise the connection should be closed immediately.
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   298
     *           This should be carried on automatically by the underlying
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   299
     *           implementation.
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   300
     *
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   301
     * @return  the sequence number of the produced or consumed SSL/TLS/DTLS
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   302
     *          record; or ${@code -1L} if no record is produced or consumed,
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   303
     *          or this operation is not supported by the underlying provider
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   304
     *
30967
cfeec3444c25 8083664: Update AudioFileWriter to generate working @see reference
darcy
parents: 30904
diff changeset
   305
     * @see     java.lang.Long#compareUnsigned(long, long)
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   306
     *
31646
6abb6f423de4 8130461: HandshakeStatus.NEED_UNWRAP_AGAIN applies only to DTLS
xuelei
parents: 30967
diff changeset
   307
     * @since   9
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   308
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 31646
diff changeset
   309
    public final long sequenceNumber() {
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   310
        return sequenceNumber;
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   311
    }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   312
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   313
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * Returns a String representation of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     */
14514
46a8ed03c7fc 8003587: Warning cleanup in package javax.net.ssl
xuelei
parents: 5506
diff changeset
   316
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        return ("Status = " + status +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            " HandshakeStatus = " + handshakeStatus +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            "\nbytesConsumed = " + bytesConsumed +
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   321
            " bytesProduced = " + bytesProduced +
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   322
            (sequenceNumber == -1 ? "" :
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   323
                " sequenceNumber = " + Long.toUnsignedString(sequenceNumber)));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
}