Inheritance: System.Text.Encoding
Ejemplo n.º 1
0
        partial void SocketReadLine(ref string response)
        {
            var encoding = new Renci.SshNet.Common.ASCIIEncoding();

            var line = new StringBuilder();
            //  Read data one byte at a time to find end of line and leave any unhandled information in the buffer to be processed later
            var buffer = new List <byte>();

            var data = new byte[1];

            do
            {
                this._socket.Receive(data);

                buffer.Add(data[0]);
            }while (!(buffer.Count > 1 && buffer[buffer.Count - 1] == 0x0A));

            if (buffer.Count > 1 && buffer[buffer.Count - 2] == 0x0D)
            {
                response = encoding.GetString(buffer.Take(buffer.Count - 2).ToArray());
            }
            else
            {
                response = encoding.GetString(buffer.Take(buffer.Count - 1).ToArray());
            }
        }
Ejemplo n.º 2
0
        partial void SocketReadLine(ref string response)
        {
            var encoding = new ASCIIEncoding();

            //  Read data one byte at a time to find end of line and leave any unhandled information in the buffer to be processed later
            var buffer = new List<byte>();

            var data = new byte[1];
            do
            {
                var asyncResult = this._socket.BeginReceive(data, 0, data.Length, SocketFlags.None, null, null);

                if (!asyncResult.AsyncWaitHandle.WaitOne(this.ConnectionInfo.Timeout))
                    throw new SshOperationTimeoutException("Socket read operation has timed out");

                var received = this._socket.EndReceive(asyncResult);

                //  If zero bytes received then exit
                if (received == 0)
                    break;

                buffer.Add(data[0]);
            }
            while (!(buffer.Count > 0 && (buffer[buffer.Count - 1] == 0x0A || buffer[buffer.Count - 1] == 0x00)));

            // Return an empty version string if the buffer consists of a 0x00 character.
            if (buffer.Count > 0 && buffer[buffer.Count - 1] == 0x00)
            {
                response = string.Empty;
            }
            else if (buffer.Count > 1 && buffer[buffer.Count - 2] == 0x0D)
                response = encoding.GetString(buffer.Take(buffer.Count - 2).ToArray());
            else
                response = encoding.GetString(buffer.Take(buffer.Count - 1).ToArray());
        }
Ejemplo n.º 3
0
        partial void SocketReadLine(ref string response)
        {
            var encoding = new Renci.SshNet.Common.ASCIIEncoding();

            var line = new StringBuilder();
            //  Read data one byte at a time to find end of line and leave any unhandled information in the buffer to be processed later
            var buffer = new List<byte>();

            var data = new byte[1];
            do
            {
                var received = this._socket.Receive(data);

                //  If zero bytes received then exit
                if (received == 0)
                    break;

                buffer.Add(data[0]);
            }
            while (!(buffer.Count > 1 && (buffer[buffer.Count - 1] == 0x0A || buffer[buffer.Count - 1] == 0x00)));

            // Return an empty version string if the buffer consists of a 0x00 character.
            if (buffer[buffer.Count - 1] == 0x00)
            {
                response = string.Empty;
            }
            else if (buffer.Count > 1 && buffer[buffer.Count - 2] == 0x0D)
                response = encoding.GetString(buffer.Take(buffer.Count - 2).ToArray());
            else
                response = encoding.GetString(buffer.Take(buffer.Count - 1).ToArray());
        }
Ejemplo n.º 4
0
 public void GetCharCountTest()
 {
     ASCIIEncoding target = new ASCIIEncoding(); // TODO: Initialize to an appropriate value
     byte[] bytes = null; // TODO: Initialize to an appropriate value
     int index = 0; // TODO: Initialize to an appropriate value
     int count = 0; // TODO: Initialize to an appropriate value
     int expected = 0; // TODO: Initialize to an appropriate value
     int actual;
     actual = target.GetCharCount(bytes, index, count);
     Assert.AreEqual(expected, actual);
     Assert.Inconclusive("Verify the correctness of this test method.");
 }
Ejemplo n.º 5
0
        partial void SocketReadLine(ref string response)
        {
            var encoding = new Renci.SshNet.Common.ASCIIEncoding();

            var line = new StringBuilder();
            //  Read data one byte at a time to find end of line and leave any unhandled information in the buffer to be processed later
            var buffer = new List <byte>();

            var data = new byte[1];

            do
            {
                SocketAsyncEventArgs args = new SocketAsyncEventArgs();
                args.SetBuffer(data, 0, data.Length);
                args.UserToken      = this._socket;
                args.RemoteEndPoint = this._socket.RemoteEndPoint;
                args.Completed     += new EventHandler <SocketAsyncEventArgs>(OnReceive);
                this._socket.ReceiveAsync(args);

                if (!this._receiveEvent.WaitOne(this.ConnectionInfo.Timeout))
                {
                    throw new SshOperationTimeoutException("Socket read operation has timed out");
                }

                //  If zero bytes received then exit
                if (args.BytesTransferred == 0)
                {
                    break;
                }

                buffer.Add(data[0]);
            }while (!(buffer.Count > 0 && (buffer[buffer.Count - 1] == 0x0A || buffer[buffer.Count - 1] == 0x00)));

            // Return an empty version string if the buffer consists of a 0x00 character.
            if (buffer.Count > 0 && buffer[buffer.Count - 1] == 0x00)
            {
                response = string.Empty;
            }
            else if (buffer.Count == 0)
            {
                response = string.Empty;
            }
            else if (buffer.Count > 1 && buffer[buffer.Count - 2] == 0x0D)
            {
                response = encoding.GetString(buffer.ToArray(), 0, buffer.Count - 2);
            }
            else
            {
                response = encoding.GetString(buffer.ToArray(), 0, buffer.Count - 1);
            }
        }
Ejemplo n.º 6
0
        partial void SocketReadLine(ref string response)
        {
            var encoding = new Renci.SshNet.Common.ASCIIEncoding();

            var line = new StringBuilder();
            //  Read data one byte at a time to find end of line and leave any unhandled information in the buffer to be processed later
            var buffer = new List <byte>();

            var data = new byte[1];

            do
            {
                var asyncResult = this._socket.BeginReceive(data, 0, data.Length, SocketFlags.None, null, null);

                if (!asyncResult.AsyncWaitHandle.WaitOne(this.ConnectionInfo.Timeout))
                {
                    throw new SshOperationTimeoutException("Socket read operation has timed out");
                }

                var received = this._socket.EndReceive(asyncResult);

                //  If zero bytes received then exit
                if (received == 0)
                {
                    break;
                }

                buffer.Add(data[0]);
            }while (!(buffer.Count > 0 && (buffer[buffer.Count - 1] == 0x0A || buffer[buffer.Count - 1] == 0x00)));

            // Return an empty version string if the buffer consists of a 0x00 character.
            if (buffer.Count > 0 && buffer[buffer.Count - 1] == 0x00)
            {
                response = string.Empty;
            }
            else if (buffer.Count > 1 && buffer[buffer.Count - 2] == 0x0D)
            {
                response = encoding.GetString(buffer.Take(buffer.Count - 2).ToArray());
            }
            else
            {
                response = encoding.GetString(buffer.Take(buffer.Count - 1).ToArray());
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Performs a blocking read on the socket until a line is read.
        /// </summary>
        /// <param name="response">The line read from the socket, or <c>null</c> when the remote server has shutdown and all data has been received.</param>
        /// <param name="timeout">A <see cref="TimeSpan"/> that represents the time to wait until a line is read.</param>
        /// <exception cref="SshOperationTimeoutException">The read has timed-out.</exception>
        /// <exception cref="SocketException">An error occurred when trying to access the socket.</exception>
        partial void SocketReadLine(ref string response, TimeSpan timeout)
        {
            var encoding = new ASCIIEncoding();
            var buffer = new List<byte>();
            var data = new byte[1];

            // read data one byte at a time to find end of line and leave any unhandled information in the buffer
            // to be processed by subsequent invocations
            do
            {
                var args = CreateSocketAsyncEventArgs(_receiveEvent, data, 0, data.Length);
                if (_socket.ReceiveAsync(args))
                {
                    if (!_receiveEvent.WaitOne(timeout))
                        throw new SshOperationTimeoutException(string.Format(CultureInfo.InvariantCulture,
                            "Socket read operation has timed out after {0:F0} milliseconds.", timeout.TotalMilliseconds));
                }

                if (args.SocketError != SocketError.Success)
                    throw new SocketException((int) args.SocketError);

                if (args.BytesTransferred == 0)
                    // the remote server shut down the socket
                    break;

                buffer.Add(data[0]);
            }
            while (!(buffer.Count > 0 && (buffer[buffer.Count - 1] == LineFeed || buffer[buffer.Count - 1] == Null)));

            if (buffer.Count == 0)
                response = null;
            else if (buffer.Count == 1 && buffer[buffer.Count - 1] == 0x00)
                // return an empty version string if the buffer consists of only a 0x00 character
                response = string.Empty;
            else if (buffer.Count > 1 && buffer[buffer.Count - 2] == CarriageReturn)
                // strip trailing CRLF
                response = encoding.GetString(buffer.ToArray(), 0, buffer.Count - 2);
            else if (buffer.Count > 1 && buffer[buffer.Count - 1] == LineFeed)
                // strip trailing LF
                response = encoding.GetString(buffer.ToArray(), 0, buffer.Count - 1);
            else
                response = encoding.GetString(buffer.ToArray(), 0, buffer.Count);
        }
Ejemplo n.º 8
0
        partial void SocketReadLine(ref string response)
        {
            var encoding = new Renci.SshNet.Common.ASCIIEncoding();

            var line = new StringBuilder();
            //  Read data one byte at a time to find end of line and leave any unhandled information in the buffer to be processed later
            var buffer = new List<byte>();

            var data = new byte[1];
            do
            {
                this._socket.Receive(data);

                buffer.Add(data[0]);
            }
            while (!(buffer.Count > 1 && buffer[buffer.Count - 1] == 0x0A));

            if (buffer.Count > 1 && buffer[buffer.Count - 2] == 0x0D)
                response = encoding.GetString(buffer.Take(buffer.Count - 2).ToArray());
            else
                response = encoding.GetString(buffer.Take(buffer.Count - 1).ToArray());
        }
Ejemplo n.º 9
0
        partial void SocketReadLine(ref string response)
        {
            var encoding = new Renci.SshNet.Common.ASCIIEncoding();

            var line = new StringBuilder();
            //  Read data one byte at a time to find end of line and leave any unhandled information in the buffer to be processed later
            var buffer = new List <byte>();

            var data = new byte[1];

            do
            {
                var received = this._socketReader.Receive(data);

                //  If zero bytes received then exit
                if (received == 0)
                {
                    break;
                }

                buffer.Add(data[0]);
            }while (!(buffer.Count > 1 && (buffer[buffer.Count - 1] == 0x0A || buffer[buffer.Count - 1] == 0x00)));

            // Return an empty version string if the buffer consists of a 0x00 character.
            if (buffer[buffer.Count - 1] == 0x00)
            {
                response = string.Empty;
            }
            else if (buffer.Count > 1 && buffer[buffer.Count - 2] == 0x0D)
            {
                response = encoding.GetString(buffer.ToArray(), 0, buffer.Count - 2);
            }
            else
            {
                response = encoding.GetString(buffer.ToArray(), 0, buffer.Count - 1);
            }
        }
Ejemplo n.º 10
0
        public void Test_PasswordConnectionInfo_PasswordExpired()
        {
            var host = Resources.HOST;
            var username = Resources.USERNAME;
            var password = Resources.PASSWORD;

            #region Example PasswordConnectionInfo PasswordExpired
            var connectionInfo = new PasswordConnectionInfo("host", "username", "password");
            var encoding = new Renci.SshNet.Common.ASCIIEncoding();
            connectionInfo.PasswordExpired += delegate(object sender, AuthenticationPasswordChangeEventArgs e)
            {
                e.NewPassword = encoding.GetBytes("123456");
            };

            using (var client = new SshClient(connectionInfo))
            {
                client.Connect();

                client.Disconnect();
            }
            #endregion

            Assert.Inconclusive();
        }
Ejemplo n.º 11
0
        public void Test_PasswordConnectionInfo_PasswordExpired()
        {
            var host     = Resources.HOST;
            var username = Resources.USERNAME;
            var password = Resources.PASSWORD;

            #region Example PasswordConnectionInfo PasswordExpired
            var connectionInfo = new PasswordConnectionInfo("host", "username", "password");
            var encoding       = new Renci.SshNet.Common.ASCIIEncoding();
            connectionInfo.PasswordExpired += delegate(object sender, AuthenticationPasswordChangeEventArgs e)
            {
                e.NewPassword = encoding.GetBytes("123456");
            };

            using (var client = new SshClient(connectionInfo))
            {
                client.Connect();

                client.Disconnect();
            }
            #endregion

            Assert.Inconclusive();
        }
Ejemplo n.º 12
0
partial         void SocketReadLine(ref string response)
        {
            var encoding = new Renci.SshNet.Common.ASCIIEncoding();

            var line = new StringBuilder();
            //  Read data one byte at a time to find end of line and leave any unhandled information in the buffer to be processed later
            var buffer = new List<byte>();

            var data = new byte[1];
            do
            {
                SocketAsyncEventArgs args = new SocketAsyncEventArgs();
                args.SetBuffer(data, 0, data.Length);
                args.UserToken = this._socket;
                args.RemoteEndPoint = this._socket.RemoteEndPoint;
                args.Completed += new EventHandler<SocketAsyncEventArgs>(OnReceive);
                this._socket.ReceiveAsync(args);

                if (!this._receiveEvent.WaitOne(this.ConnectionInfo.Timeout))
                    throw new SshOperationTimeoutException("Socket read operation has timed out");

                //  If zero bytes received then exit
                if (args.BytesTransferred == 0)
                    break;

                buffer.Add(data[0]);
            }
            while (!(buffer.Count > 0 && (buffer[buffer.Count - 1] == 0x0A || buffer[buffer.Count - 1] == 0x00)));

            // Return an empty version string if the buffer consists of a 0x00 character.
            if (buffer.Count > 0 && buffer[buffer.Count - 1] == 0x00)
            {
                response = string.Empty;
            }
            else if (buffer.Count == 0)
                response = string.Empty;
            else if (buffer.Count > 1 && buffer[buffer.Count - 2] == 0x0D)
                response = encoding.GetString(buffer.ToArray(), 0, buffer.Count - 2);
            else
                response = encoding.GetString(buffer.ToArray(), 0, buffer.Count - 1);
        }
Ejemplo n.º 13
0
        public bool InitRepositoryLocal ()
        {
            // Error out if the target folder is not empty
            if (!Directory.Exists (DatabasePath)) {
                Directory.CreateDirectory (DatabasePath);

            } else {
                Utils.Log ("Could not init local: " + DatabasePath + " already exists");
                return false;
            }

            // Create structure locally
            Directory.CreateDirectory (Path.Combine (DatabasePath, "objects"));
            StreamWriter writer = new StreamWriter (Path.Combine (DatabasePath, "HEAD"));
            writer.WriteLine ("0:0");
            writer.Close ();

            // Create a randomish ID
            writer = new StreamWriter (Path.Combine (DatabasePath, "ID"));
            string random = DateTime.Now.ToString ("YYDDMMhhmmssFFF") + new Random ().Next (0, 1000);
            ASCIIEncoding encoding = new ASCIIEncoding ();
            writer.WriteLine (Utils.SHA1 (encoding.GetBytes (random)));
            writer.Close ();

            return true;
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Performs a blocking read on the socket until a line is read.
        /// </summary>
        /// <param name="response">The line read from the socket, or <c>null</c> when the remote server has shutdown and all data has been received.</param>
        /// <param name="timeout">A <see cref="TimeSpan"/> that represents the time to wait until a line is read.</param>
        /// <exception cref="SshOperationTimeoutException">The read has timed-out.</exception>
        /// <exception cref="SocketException">An error occurred when trying to access the socket.</exception>
        partial void SocketReadLine(ref string response, TimeSpan timeout)
        {
            var encoding = new ASCIIEncoding();
            var buffer = new List<byte>();
            var data = new byte[1];

            // read data one byte at a time to find end of line and leave any unhandled information in the buffer
            // to be processed by subsequent invocations
            do
            {
                var asyncResult = _socket.BeginReceive(data, 0, data.Length, SocketFlags.None, null, null);
                if (!asyncResult.AsyncWaitHandle.WaitOne(timeout))
                    throw new SshOperationTimeoutException(string.Format(CultureInfo.InvariantCulture,
                        "Socket read operation has timed out after {0:F0} milliseconds.", timeout.TotalMilliseconds));

                var received = _socket.EndReceive(asyncResult);

                if (received == 0)
                    // the remote server shut down the socket
                    break;

                buffer.Add(data[0]);
            }
            while (!(buffer.Count > 0 && (buffer[buffer.Count - 1] == LineFeed || buffer[buffer.Count - 1] == Null)));

            if (buffer.Count == 0)
                response = null;
            else if (buffer.Count == 1 && buffer[buffer.Count - 1] == 0x00)
                // return an empty version string if the buffer consists of only a 0x00 character
                response = string.Empty;
            else if (buffer.Count > 1 && buffer[buffer.Count - 2] == CarriageReturn)
                // strip trailing CRLF
                response = encoding.GetString(buffer.Take(buffer.Count - 2).ToArray());
            else if (buffer.Count > 1 && buffer[buffer.Count - 1] == LineFeed)
                // strip trailing LF
                response = encoding.GetString(buffer.Take(buffer.Count - 1).ToArray());
            else
                response = encoding.GetString(buffer.ToArray());
        }
Ejemplo n.º 15
0
 public void ASCIIEncodingConstructorTest()
 {
     ASCIIEncoding target = new ASCIIEncoding();
     Assert.Inconclusive("TODO: Implement code to verify target");
 }