private SSLEngineResult handshakeWrap(SSLEngine engine, CodecCallback callback)
            throws IOException {
        SSLEngineResult result;
        SSLEngineResult.Status status;
        ByteBuffer output = allocate();
        while (true) {
            result = engineWrap(engine, allocate(0), output);
            status = result.getStatus();
            output.flip();
            if (output.hasRemaining()) {
                callback.onEncrypt(output);
            }
            if (status == SSLEngineResult.Status.BUFFER_OVERFLOW) {
                output = allocate(engine.getSession().getApplicationBufferSize());
            } else {
                if (status == SSLEngineResult.Status.CLOSED) {
                    mEngineClosed = true;
                }
                break;
            }
        }
        return result;
    }
Try to encrypt a plaintext packet. If SSL handshake has finished, then encode it,
otherwise add it to queue and wait handshake finished.

@param buffer The plaintext packet.
@param callback A callback to observe actions and receive output packets.
@throws IOException If an I/O error has occurred.
netbare-core/src/main/java/com/github/megatronking/netbare/ssl/SSLCodec.java