2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 package javax.net.ssl;
21 * The result object describing the state of the {@code SSLEngine} produced
22 * by the {@code wrap()} and {@code unwrap()} operations.
24 public class SSLEngineResult {
27 * The {@code enum} describing the state of the current handshake.
29 public enum HandshakeStatus {
31 * No handshake in progress.
35 * The handshake is finished.
39 * The results of one (or more) delegated tasks are needed to continue
44 * The engine must send data to the remote side to continue the
49 * The engine needs to receive data from the remote side to continue the
56 * The {@code enum} describing the result of the {@code SSLEngine}
59 public static enum Status {
61 * The size of the destination buffer is too small to hold the result of
62 * the current operation.
66 * There were not enough bytes available in the source buffer to
67 * complete the current operation.
71 * The operation closed this side of the communication or was already
76 * The operation completed successfully.
81 // Store Status object
82 private final SSLEngineResult.Status status;
84 // Store HandshakeStatus object
85 private final SSLEngineResult.HandshakeStatus handshakeStatus;
87 // Store bytesConsumed
88 private final int bytesConsumed;
90 // Store bytesProduced
91 private final int bytesProduced;
94 * Creates a new {@code SSLEngineResult} instance with the specified state
98 * the return value of the {@code SSLEngine} operation.
99 * @param handshakeStatus
100 * the status of the current handshake
101 * @param bytesConsumed
102 * the number of bytes retrieved from the source buffer(s).
103 * @param bytesProduced
104 * the number of bytes transferred to the destination buffer(s).
105 * @throws IllegalArgumentException
106 * if {@code status} or {@code handshakeStatus} is {@code null},
107 * or if {@code bytesConsumed} or {@code bytesProduces} are
110 public SSLEngineResult(SSLEngineResult.Status status,
111 SSLEngineResult.HandshakeStatus handshakeStatus, int bytesConsumed, int bytesProduced) {
112 if (status == null) {
113 throw new IllegalArgumentException("status is null");
115 if (handshakeStatus == null) {
116 throw new IllegalArgumentException("handshakeStatus is null");
118 if (bytesConsumed < 0) {
119 throw new IllegalArgumentException("bytesConsumed is negative");
121 if (bytesProduced < 0) {
122 throw new IllegalArgumentException("bytesProduced is negative");
124 this.status = status;
125 this.handshakeStatus = handshakeStatus;
126 this.bytesConsumed = bytesConsumed;
127 this.bytesProduced = bytesProduced;
131 * Returns the return value of the {@code SSLEngine} operation.
133 * @return the return value of the {@code SSLEngine} operation.
135 public final Status getStatus() {
140 * Returns the status of the current handshake.
142 * @return the status of the current handshake.
144 public final HandshakeStatus getHandshakeStatus() {
145 return handshakeStatus;
149 * Returns the number of bytes retrieved from the source buffer(s).
151 * @return the number of bytes retrieved from the source buffer(s).
153 public final int bytesConsumed() {
154 return bytesConsumed;
158 * Returns the number of bytes transferred to the destination buffer(s).
160 * @return the number of bytes transferred to the destination buffer(s).
162 public final int bytesProduced() {
163 return bytesProduced;
167 public String toString() {
168 return "SSLEngineReport: Status = " + status + " HandshakeStatus = " + handshakeStatus
169 + "\n bytesConsumed = " + bytesConsumed + " bytesProduced = "