public int Send(byte[] buffer, int size, SocketFlags flags)
        {
            int bytesToSend = 0;
            int obfsSendSize;

            byte[] obfsBuffer;

            lock (_encryptionLock)
            {
                int outlength;
                //if (!header_sent)
                //{
                //    header_sent = true;
                //    if (buffer[0] == 3 && _method == "none")
                //    {
                //        for (int i = 0; i < buffer[1]; ++i)
                //        {
                //            buffer[i + 2] |= 0x80;
                //        }
                //        buffer[0] = 2;
                //    }
                //}
                byte[] bytesToEncrypt = _protocol.ClientPreEncrypt(buffer, size, out outlength);
                if (bytesToEncrypt == null)
                {
                    return(0);
                }
                Util.Utils.SetArrayMinSize(ref SendEncryptBuffer, outlength + 32);
                _encryptor.Encrypt(bytesToEncrypt, outlength, SendEncryptBuffer, out bytesToSend);
                obfsBuffer = _obfs.ClientEncode(SendEncryptBuffer, bytesToSend, out obfsSendSize);
            }
            return(SendAll(obfsBuffer, obfsSendSize, 0));
        }
 public override byte[] ClientEncode(byte[] encryptdata, int datalength, out int outlength)
 {
     if (subObfs != null)
     {
         return(subObfs.ClientEncode(encryptdata, datalength, out outlength));
     }
     outlength = datalength;
     return(encryptdata);
 }
        public int BeginSend(byte[] buffer, int size, SocketFlags flags, AsyncCallback callback, object state)
        {
            CallbackState st = new CallbackState();

            st.size  = size;
            st.state = state;

            int bytesToSend = 0;
            int obfsSendSize;

            byte[] obfsBuffer;
            lock (_encryptionLock)
            {
                int    outlength;
                byte[] bytesToEncrypt = _protocol.ClientPreEncrypt(buffer, size, out outlength);
                _encryptor.Encrypt(bytesToEncrypt, outlength, SendEncryptBuffer, out bytesToSend);
                obfsBuffer = _obfs.ClientEncode(SendEncryptBuffer, bytesToSend, out obfsSendSize);
                _socket.BeginSend(obfsBuffer, 0, obfsSendSize, 0, callback, st);
            }
            return(obfsSendSize);
        }