@@ -0,0 +1,3398 @@
+// Copyright 2014, Kevin Ko %3Ckevin@faveset.com%3E%0A%0Apackage com.faveset.khttp;%0A%0Aimport javax.net.ssl.SSLEngine;%0A%0Aclass SSLHandshakeState %7B%0A    private SSLEngine mSSLEngine;%0A%0A    public SSLHandshakeState(SSLEngine engine) %7B%0A        mSSLEngine = engine;%0A    %7D%0A%0A    @Override%0A    public OpResult stepUnwrap(NetReader src, NetBuffer dest) %7B%0A        do %7B%0A            SSLEngineResult result = src.unwrap(mSSLEngine, dest);%0A            switch (result.getStatus()) %7B%0A                case BUFFER_OVERFLOW:%0A                    // When handshaking, no application data is unwrapped.%0A                    // Thus, this should never happen.  Instead, this would indicate some sort%0A                    // of change in state.  Break out to the subsequent switch to handle things.%0A                    break;%0A%0A                case BUFFER_UNDERFLOW:%0A                    // We need more data from the network.%0A                    return OpResult.LOAD_SRC_BUFFER;%0A%0A                case CLOSED:%0A                    return OpResult.ENGINE_CLOSE;%0A%0A                case OK:%0A                    src.updateRead();%0A%0A                    // Be greedy, and continue unwrapping.%0A                    break;%0A            %7D%0A%0A            switch (result.getHandshakeStatus()) %7B%0A                case NEED_TASK:%0A                    return OpResult.SCHEDULE_TASKS;%0A%0A                case NEED_UNWRAP:%0A                    break;%0A%0A                case NEED_WRAP:%0A                    return OpResult.SCHEDULE_WRAP;%0A%0A                case FINISHED:%0A                case NOT_HANDSHAKING:%0A                    return OpResult.STATE_CHANGE;%0A            %7D%0A        %7D while (true);%0A    %7D%0A%0A    @Override%0A    public OpResult stepWrap(NetReader src, NetBuffer dest) %7B%0A        do %7B%0A            SSLEngineResult result = src.wrap(mSSLEngine, dest);%0A            switch (result.getStatus()) %7B%0A                case BUFFER_OVERFLOW:%0A                    int newBufSize = mSSLEngine.getSession().getPacketBufferSize();%0A                    if (!resizeOverflowedBuffer(dest, newBufSize)) %7B%0A                        // dest was not empty.%0A                        return OpResult.DRAIN_DEST_BUFFER;%0A                    %7D%0A%0A                    // Otherwise, dest was resized.  Continue looping to retry.%0A                    break;%0A%0A                case BUFFER_UNDERFLOW:%0A                    // This shouldn't happen when handshaking unless we've dropped out of the%0A                    // handshake state.  Let the subsequent handshake switch() handle things.%0A                    break;%0A%0A                case CLOSED:%0A                    return OpResult.ENGINE_CLOSE;%0A%0A                case OK:%0A                    // We might have changed out of the handshaking state so just note the read.%0A                    // This is vacuous (though it consumes some ops) if we are still handshaking.%0A                    src.updateRead();%0A%0A                    // Be greedy, and continue wrapping.%0A                    break;%0A            %7D%0A%0A            switch (result.getHandshakeStatus()) %7B%0A                case NEED_TASK:%0A                    return OpResult.SCHEDULE_TASKS;%0A%0A                case NEED_UNWRAP:%0A                    return OpResult.SCHEDULE_UNWRAP;%0A%0A                case NEED_WRAP:%0A                    break;%0A%0A                case FINISHED:%0A                case NOT_HANDSHAKING:%0A                    return OpResult.STATE_CHANGE;%0A            %7D%0A        %7D while (true);%0A    %7D%0A%7D%0A

Add initial (reviewed) SSLHandshakeState.