diff --git a/src/Renci.SshNet/AuthenticationMethod.cs b/src/Renci.SshNet/AuthenticationMethod.cs index 81818028..631ea5cb 100644 --- a/src/Renci.SshNet/AuthenticationMethod.cs +++ b/src/Renci.SshNet/AuthenticationMethod.cs @@ -25,7 +25,7 @@ namespace Renci.SshNet /// /// Gets list of allowed authentications. /// - public IEnumerable AllowedAuthentications { get; protected set; } + public IList AllowedAuthentications { get; protected set; } /// /// Initializes a new instance of the class. diff --git a/src/Renci.SshNet/CipherInfo.cs b/src/Renci.SshNet/CipherInfo.cs index 9d06dc0c..1e890dfe 100644 --- a/src/Renci.SshNet/CipherInfo.cs +++ b/src/Renci.SshNet/CipherInfo.cs @@ -1,5 +1,5 @@ using System; -using System.Linq; +using Renci.SshNet.Common; using Renci.SshNet.Security.Cryptography; namespace Renci.SshNet @@ -30,7 +30,7 @@ namespace Renci.SshNet public CipherInfo(int keySize, Func cipher) { KeySize = keySize; - Cipher = (key, iv) => (cipher(key.Take(KeySize / 8).ToArray(), iv)); + Cipher = (key, iv) => (cipher(key.Take(KeySize / 8), iv)); } } } diff --git a/src/Renci.SshNet/ClientAuthentication.cs b/src/Renci.SshNet/ClientAuthentication.cs index 38ba0a7b..06bdcb19 100644 --- a/src/Renci.SshNet/ClientAuthentication.cs +++ b/src/Renci.SshNet/ClientAuthentication.cs @@ -30,7 +30,7 @@ namespace Renci.SshNet var authenticated = noneAuthenticationMethod.Authenticate(session); if (authenticated != AuthenticationResult.Success) { - if (!TryAuthenticate(session, new AuthenticationState(connectionInfo.AuthenticationMethods.ToList()), noneAuthenticationMethod.AllowedAuthentications.ToList(), ref authenticationException)) + if (!TryAuthenticate(session, new AuthenticationState(connectionInfo.AuthenticationMethods), noneAuthenticationMethod.AllowedAuthentications.ToList(), ref authenticationException)) { throw authenticationException; } @@ -51,7 +51,7 @@ namespace Renci.SshNet ICollection allowedAuthenticationMethods, ref SshAuthenticationException authenticationException) { - if (!allowedAuthenticationMethods.Any()) + if (allowedAuthenticationMethods.Count == 0) { authenticationException = new SshAuthenticationException("No authentication methods defined on SSH server."); return false; @@ -61,7 +61,7 @@ namespace Renci.SshNet // passed in the ctor, not the order in which the SSH server returns // the allowed authentication methods var matchingAuthenticationMethods = authenticationState.SupportedAuthenticationMethods.Where(a => allowedAuthenticationMethods.Contains(a.Name)).ToList(); - if (!matchingAuthenticationMethods.Any()) + if (matchingAuthenticationMethods.Count == 0) { authenticationException = new SshAuthenticationException(string.Format("No suitable authentication method found to complete authentication ({0}).", string.Join(",", allowedAuthenticationMethods.ToArray()))); return false; @@ -87,7 +87,7 @@ namespace Renci.SshNet switch (authenticationResult) { case AuthenticationResult.PartialSuccess: - if (TryAuthenticate(session, authenticationState, authenticationMethod.AllowedAuthentications.ToList(), ref authenticationException)) + if (TryAuthenticate(session, authenticationState, authenticationMethod.AllowedAuthentications, ref authenticationException)) { authenticationResult = AuthenticationResult.Success; } diff --git a/src/Renci.SshNet/Common/DerData.cs b/src/Renci.SshNet/Common/DerData.cs index 934c6196..5df74dba 100644 --- a/src/Renci.SshNet/Common/DerData.cs +++ b/src/Renci.SshNet/Common/DerData.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; namespace Renci.SshNet.Common { diff --git a/src/Renci.SshNet/Common/Extensions.cs b/src/Renci.SshNet/Common/Extensions.cs index 7d0f3b3e..9bbb956e 100644 --- a/src/Renci.SshNet/Common/Extensions.cs +++ b/src/Renci.SshNet/Common/Extensions.cs @@ -228,7 +228,7 @@ namespace Renci.SshNet.Common /// A array that contains the specified number of bytes at the specified offset /// of the input array. /// - internal static byte[] Take(this byte[] value, int offset, int count) + public static byte[] Take(this byte[] value, int offset, int count) { if (value == null) throw new ArgumentNullException("value"); @@ -244,7 +244,7 @@ namespace Renci.SshNet.Common return taken; } - internal static byte[] Take(this byte[] value, int count) + public static byte[] Take(this byte[] value, int count) { if (value == null) throw new ArgumentNullException("value"); diff --git a/src/Renci.SshNet/ConnectionInfo.cs b/src/Renci.SshNet/ConnectionInfo.cs index 0691179b..ba2fc666 100644 --- a/src/Renci.SshNet/ConnectionInfo.cs +++ b/src/Renci.SshNet/ConnectionInfo.cs @@ -46,7 +46,7 @@ namespace Renci.SshNet /// /// Gets supported authentication methods for this connection. /// - public IEnumerable AuthenticationMethods { get; private set; } + public IList AuthenticationMethods { get; private set; } /// /// Gets supported compression algorithms for this connection. @@ -284,7 +284,7 @@ namespace Renci.SshNet if (authenticationMethods == null) throw new ArgumentNullException("authenticationMethods"); - if (!authenticationMethods.Any()) + if (authenticationMethods.Length == 0) throw new ArgumentException("At least one authentication method should be specified.", "authenticationMethods"); // Set default connection values @@ -437,9 +437,9 @@ namespace Renci.SshNet return new NoneAuthenticationMethod(Username); } - IEnumerable IConnectionInfoInternal.AuthenticationMethods + IList IConnectionInfoInternal.AuthenticationMethods { - get { return AuthenticationMethods.Cast(); } + get { return AuthenticationMethods.Cast().ToList(); } } } } diff --git a/src/Renci.SshNet/HashInfo.cs b/src/Renci.SshNet/HashInfo.cs index 05923a81..6ffbaeb1 100644 --- a/src/Renci.SshNet/HashInfo.cs +++ b/src/Renci.SshNet/HashInfo.cs @@ -1,6 +1,6 @@ using System; -using System.Linq; using System.Security.Cryptography; +using Renci.SshNet.Common; namespace Renci.SshNet { @@ -30,7 +30,7 @@ namespace Renci.SshNet public HashInfo(int keySize, Func hash) { KeySize = keySize; - HashAlgorithm = key => (hash(key.Take(KeySize / 8).ToArray())); + HashAlgorithm = key => (hash(key.Take(KeySize / 8))); } } } diff --git a/src/Renci.SshNet/IAuthenticationMethod.cs b/src/Renci.SshNet/IAuthenticationMethod.cs index 777e4dee..0ffdb0fe 100644 --- a/src/Renci.SshNet/IAuthenticationMethod.cs +++ b/src/Renci.SshNet/IAuthenticationMethod.cs @@ -22,7 +22,7 @@ namespace Renci.SshNet /// /// The list of allowed authentications. /// - IEnumerable AllowedAuthentications { get; } + IList AllowedAuthentications { get; } /// /// Gets the name of the authentication method. diff --git a/src/Renci.SshNet/IConnectionInfo.cs b/src/Renci.SshNet/IConnectionInfo.cs index 2922df66..98409c09 100644 --- a/src/Renci.SshNet/IConnectionInfo.cs +++ b/src/Renci.SshNet/IConnectionInfo.cs @@ -22,7 +22,7 @@ namespace Renci.SshNet /// /// The supported authentication methods for this connection. /// - IEnumerable AuthenticationMethods { get; } + IList AuthenticationMethods { get; } /// /// Creates a for the credentials represented diff --git a/src/Renci.SshNet/KeyboardInteractiveAuthenticationMethod.cs b/src/Renci.SshNet/KeyboardInteractiveAuthenticationMethod.cs index 591111bf..7615c9f3 100644 --- a/src/Renci.SshNet/KeyboardInteractiveAuthenticationMethod.cs +++ b/src/Renci.SshNet/KeyboardInteractiveAuthenticationMethod.cs @@ -91,8 +91,8 @@ namespace Renci.SshNet else _authenticationResult = AuthenticationResult.Failure; - // Copy allowed authentication methods - AllowedAuthentications = e.Message.AllowedAuthentications.ToList(); + // Copy allowed authentication methods + AllowedAuthentications = e.Message.AllowedAuthentications; _authenticationCompleted.Set(); } diff --git a/src/Renci.SshNet/Messages/Authentication/RequestMessageKeyboardInteractive.cs b/src/Renci.SshNet/Messages/Authentication/RequestMessageKeyboardInteractive.cs index 1f7c2f61..8736ab54 100644 --- a/src/Renci.SshNet/Messages/Authentication/RequestMessageKeyboardInteractive.cs +++ b/src/Renci.SshNet/Messages/Authentication/RequestMessageKeyboardInteractive.cs @@ -1,4 +1,6 @@ -namespace Renci.SshNet.Messages.Authentication +using Renci.SshNet.Common; + +namespace Renci.SshNet.Messages.Authentication { /// /// Represents "keyboard-interactive" SSH_MSG_USERAUTH_REQUEST message. @@ -42,8 +44,8 @@ public RequestMessageKeyboardInteractive(ServiceName serviceName, string username) : base(serviceName, username, "keyboard-interactive") { - Language = new byte[0]; - SubMethods = new byte[0]; + Language = Array.Empty; + SubMethods = Array.Empty; } /// diff --git a/src/Renci.SshNet/Messages/Transport/IgnoreMessage.cs b/src/Renci.SshNet/Messages/Transport/IgnoreMessage.cs index 0d364106..39bb223d 100644 --- a/src/Renci.SshNet/Messages/Transport/IgnoreMessage.cs +++ b/src/Renci.SshNet/Messages/Transport/IgnoreMessage.cs @@ -1,4 +1,5 @@ using System; +using Renci.SshNet.Common; namespace Renci.SshNet.Messages.Transport { @@ -20,7 +21,7 @@ namespace Renci.SshNet.Messages.Transport /// public IgnoreMessage() { - Data = new byte[0]; + Data = Array.Empty; } /// diff --git a/src/Renci.SshNet/NoneAuthenticationMethod.cs b/src/Renci.SshNet/NoneAuthenticationMethod.cs index d96f6521..e7f8267c 100644 --- a/src/Renci.SshNet/NoneAuthenticationMethod.cs +++ b/src/Renci.SshNet/NoneAuthenticationMethod.cs @@ -1,5 +1,4 @@ using System; -using System.Linq; using System.Threading; using Renci.SshNet.Messages.Authentication; using Renci.SshNet.Messages; @@ -76,8 +75,8 @@ namespace Renci.SshNet else _authenticationResult = AuthenticationResult.Failure; - // Copy allowed authentication methods - AllowedAuthentications = e.Message.AllowedAuthentications.ToList(); + // Copy allowed authentication methods + AllowedAuthentications = e.Message.AllowedAuthentications; _authenticationCompleted.Set(); } diff --git a/src/Renci.SshNet/PasswordAuthenticationMethod.cs b/src/Renci.SshNet/PasswordAuthenticationMethod.cs index 252cf784..0ed626ef 100644 --- a/src/Renci.SshNet/PasswordAuthenticationMethod.cs +++ b/src/Renci.SshNet/PasswordAuthenticationMethod.cs @@ -1,5 +1,4 @@ using System; -using System.Linq; using System.Text; using System.Threading; using Renci.SshNet.Abstractions; @@ -116,7 +115,7 @@ namespace Renci.SshNet _authenticationResult = AuthenticationResult.Failure; // Copy allowed authentication methods - AllowedAuthentications = e.Message.AllowedAuthentications.ToList(); + AllowedAuthentications = e.Message.AllowedAuthentications; _authenticationCompleted.Set(); } diff --git a/src/Renci.SshNet/PrivateKeyAuthenticationMethod.cs b/src/Renci.SshNet/PrivateKeyAuthenticationMethod.cs index b8cb46b1..4847c929 100644 --- a/src/Renci.SshNet/PrivateKeyAuthenticationMethod.cs +++ b/src/Renci.SshNet/PrivateKeyAuthenticationMethod.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Collections.ObjectModel; using Renci.SshNet.Messages.Authentication; using Renci.SshNet.Messages; @@ -127,7 +126,7 @@ namespace Renci.SshNet _authenticationResult = AuthenticationResult.Failure; // Copy allowed authentication methods - AllowedAuthentications = e.Message.AllowedAuthentications.ToList(); + AllowedAuthentications = e.Message.AllowedAuthentications; _authenticationCompleted.Set(); } diff --git a/src/Renci.SshNet/PrivateKeyFile.cs b/src/Renci.SshNet/PrivateKeyFile.cs index eb70705c..9e12164d 100644 --- a/src/Renci.SshNet/PrivateKeyFile.cs +++ b/src/Renci.SshNet/PrivateKeyFile.cs @@ -1,5 +1,4 @@ using System; -using System.Linq; using System.Collections.Generic; using System.IO; using System.Text; @@ -191,11 +190,11 @@ namespace Renci.SshNet switch (keyName) { case "RSA": - _key = new RsaKey(decryptedData.ToArray()); + _key = new RsaKey(decryptedData); HostKey = new KeyHostAlgorithm("ssh-rsa", _key); break; case "DSA": - _key = new DsaKey(decryptedData.ToArray()); + _key = new DsaKey(decryptedData); HostKey = new KeyHostAlgorithm("ssh-dss", _key); break; case "SSH2 ENCRYPTED": @@ -288,13 +287,13 @@ namespace Renci.SshNet while (cipherKey.Count < length) { - hash = passwordBytes.Concat(hash).ToArray(); + hash = passwordBytes.Concat(hash); hash = md5.ComputeHash(hash); cipherKey.AddRange(hash); } } - return cipherKey.Take(length).ToArray(); + return cipherKey.ToArray().Take(length); } /// @@ -325,14 +324,14 @@ namespace Renci.SshNet var passwordBytes = Encoding.UTF8.GetBytes(passPhrase); // Use 8 bytes binary salt - var initVector = passwordBytes.Concat(binarySalt.Take(8)).ToArray(); + var initVector = passwordBytes.Concat(binarySalt.Take(8)); var hash = md5.ComputeHash(initVector); cipherKey.AddRange(hash); while (cipherKey.Count < cipherInfo.KeySize / 8) { - hash = hash.Concat(initVector).ToArray(); + hash = hash.Concat(initVector); hash = md5.ComputeHash(hash); cipherKey.AddRange(hash); } @@ -425,7 +424,7 @@ namespace Renci.SshNet var bytesArray = new byte[data.Length + 1]; Buffer.BlockCopy(data, 0, bytesArray, 1, data.Length); - return new BigInteger(bytesArray.Reverse().ToArray()); + return new BigInteger(bytesArray.Reverse()); } protected override void LoadData() diff --git a/src/Renci.SshNet/Security/Cryptography/CipherDigitalSignature.cs b/src/Renci.SshNet/Security/Cryptography/CipherDigitalSignature.cs index 88f6ddad..fae6537d 100644 --- a/src/Renci.SshNet/Security/Cryptography/CipherDigitalSignature.cs +++ b/src/Renci.SshNet/Security/Cryptography/CipherDigitalSignature.cs @@ -1,5 +1,4 @@ using System; -using System.Linq; using Renci.SshNet.Common; namespace Renci.SshNet.Security.Cryptography @@ -39,7 +38,7 @@ namespace Renci.SshNet.Security.Cryptography var encryptedSignature = _cipher.Decrypt(signature); var hashData = Hash(input); var expected = DerEncode(hashData); - return expected.SequenceEqual(encryptedSignature); + return expected.IsEqualTo(encryptedSignature); } /// @@ -57,7 +56,7 @@ namespace Renci.SshNet.Security.Cryptography // Calculate DER string var derEncodedHash = DerEncode(hashData); - return _cipher.Encrypt(derEncodedHash).TrimLeadingZero().ToArray(); + return _cipher.Encrypt(derEncodedHash).TrimLeadingZeros(); } /// diff --git a/src/Renci.SshNet/Security/Cryptography/Ciphers/CipherMode.cs b/src/Renci.SshNet/Security/Cryptography/Ciphers/CipherMode.cs index 7fda5edc..7489456f 100644 --- a/src/Renci.SshNet/Security/Cryptography/Ciphers/CipherMode.cs +++ b/src/Renci.SshNet/Security/Cryptography/Ciphers/CipherMode.cs @@ -1,4 +1,4 @@ -using System.Linq; +using Renci.SshNet.Common; namespace Renci.SshNet.Security.Cryptography.Ciphers { @@ -39,7 +39,7 @@ namespace Renci.SshNet.Security.Cryptography.Ciphers { Cipher = cipher; _blockSize = cipher.BlockSize; - IV = IV.Take(_blockSize).ToArray(); + IV = IV.Take(_blockSize); } /// diff --git a/src/Renci.SshNet/Security/Cryptography/DsaDigitalSignature.cs b/src/Renci.SshNet/Security/Cryptography/DsaDigitalSignature.cs index 480a3238..3a902cf7 100644 --- a/src/Renci.SshNet/Security/Cryptography/DsaDigitalSignature.cs +++ b/src/Renci.SshNet/Security/Cryptography/DsaDigitalSignature.cs @@ -1,5 +1,4 @@ using System; -using System.Linq; using System.Security.Cryptography; using Renci.SshNet.Common; @@ -42,7 +41,7 @@ namespace Renci.SshNet.Security.Cryptography { var hashInput = _hash.ComputeHash(input); - var hm = new BigInteger(hashInput.Reverse().Concat(new byte[] { 0 }).ToArray()); + var hm = new BigInteger(hashInput.Reverse().Concat(new byte[] { 0 })); if (signature.Length != 40) throw new InvalidOperationException("Invalid signature."); @@ -98,7 +97,7 @@ namespace Renci.SshNet.Security.Cryptography { var hashInput = _hash.ComputeHash(input); - var m = new BigInteger(hashInput.Reverse().Concat(new byte[] { 0 }).ToArray()); + var m = new BigInteger(hashInput.Reverse().Concat(new byte[] { 0 })); BigInteger s; BigInteger r; @@ -139,11 +138,11 @@ namespace Renci.SshNet.Security.Cryptography var signature = new byte[40]; // issue #1918: pad part with zero's on the left if length is less than 20 - var rBytes = r.ToByteArray().Reverse().TrimLeadingZero().ToArray(); + var rBytes = r.ToByteArray().Reverse().TrimLeadingZeros(); Array.Copy(rBytes, 0, signature, 20 - rBytes.Length, rBytes.Length); // issue #1918: pad part with zero's on the left if length is less than 20 - var sBytes = s.ToByteArray().Reverse().TrimLeadingZero().ToArray(); + var sBytes = s.ToByteArray().Reverse().TrimLeadingZeros(); Array.Copy(sBytes, 0, signature, 40 - sBytes.Length, sBytes.Length); return signature; diff --git a/src/Renci.SshNet/Security/Cryptography/HMACMD5.cs b/src/Renci.SshNet/Security/Cryptography/HMACMD5.cs index d19c9df2..572ec152 100644 --- a/src/Renci.SshNet/Security/Cryptography/HMACMD5.cs +++ b/src/Renci.SshNet/Security/Cryptography/HMACMD5.cs @@ -1,6 +1,6 @@ #if FEATURE_HMAC_MD5 -using System.Linq; +using Renci.SshNet.Common; namespace Renci.SshNet.Security.Cryptography { @@ -31,7 +31,7 @@ namespace Renci.SshNet.Security.Cryptography protected override byte[] HashFinal() { var hash = base.HashFinal(); - return hash.Take(HashSize / 8).ToArray(); + return hash.Take(HashSize / 8); } } } diff --git a/src/Renci.SshNet/Security/Cryptography/HMACSHA1.cs b/src/Renci.SshNet/Security/Cryptography/HMACSHA1.cs index a1642c19..6acb9c16 100644 --- a/src/Renci.SshNet/Security/Cryptography/HMACSHA1.cs +++ b/src/Renci.SshNet/Security/Cryptography/HMACSHA1.cs @@ -1,6 +1,6 @@ #if FEATURE_HMAC_SHA1 -using System.Linq; +using Renci.SshNet.Common; namespace Renci.SshNet.Security.Cryptography { @@ -28,7 +28,7 @@ namespace Renci.SshNet.Security.Cryptography protected override byte[] HashFinal() { var hash = base.HashFinal(); - return hash.Take(HashSize / 8).ToArray(); + return hash.Take(HashSize / 8); } } } diff --git a/src/Renci.SshNet/Security/Cryptography/HMACSHA256.cs b/src/Renci.SshNet/Security/Cryptography/HMACSHA256.cs index 93d5b859..cc8a1375 100644 --- a/src/Renci.SshNet/Security/Cryptography/HMACSHA256.cs +++ b/src/Renci.SshNet/Security/Cryptography/HMACSHA256.cs @@ -1,6 +1,6 @@ #if FEATURE_HMAC_SHA256 -using System.Linq; +using Renci.SshNet.Common; namespace Renci.SshNet.Security.Cryptography { @@ -28,7 +28,7 @@ namespace Renci.SshNet.Security.Cryptography protected override byte[] HashFinal() { var hash = base.HashFinal(); - return hash.Take(HashSize / 8).ToArray(); + return hash.Take(HashSize / 8); } } } diff --git a/src/Renci.SshNet/Security/Cryptography/HMACSHA384.cs b/src/Renci.SshNet/Security/Cryptography/HMACSHA384.cs index f73b0483..b63034dd 100644 --- a/src/Renci.SshNet/Security/Cryptography/HMACSHA384.cs +++ b/src/Renci.SshNet/Security/Cryptography/HMACSHA384.cs @@ -1,6 +1,6 @@ #if FEATURE_HMAC_SHA384 -using System.Linq; +using Renci.SshNet.Common; namespace Renci.SshNet.Security.Cryptography { @@ -28,7 +28,7 @@ namespace Renci.SshNet.Security.Cryptography protected override byte[] HashFinal() { var hash = base.HashFinal(); - return hash.Take(HashSize / 8).ToArray(); + return hash.Take(HashSize / 8); } } } diff --git a/src/Renci.SshNet/Security/Cryptography/HMACSHA512.cs b/src/Renci.SshNet/Security/Cryptography/HMACSHA512.cs index f36be2a7..e60bdfa4 100644 --- a/src/Renci.SshNet/Security/Cryptography/HMACSHA512.cs +++ b/src/Renci.SshNet/Security/Cryptography/HMACSHA512.cs @@ -1,6 +1,6 @@ #if FEATURE_HMAC_SHA512 -using System.Linq; +using Renci.SshNet.Common; namespace Renci.SshNet.Security.Cryptography { @@ -28,7 +28,7 @@ namespace Renci.SshNet.Security.Cryptography protected override byte[] HashFinal() { var hash = base.HashFinal(); - return hash.Take(HashSize / 8).ToArray(); + return hash.Take(HashSize / 8); } } } diff --git a/src/Renci.SshNet/Security/KeyExchangeDiffieHellmanGroup14Sha1.cs b/src/Renci.SshNet/Security/KeyExchangeDiffieHellmanGroup14Sha1.cs index a64efbf5..384cef1a 100644 --- a/src/Renci.SshNet/Security/KeyExchangeDiffieHellmanGroup14Sha1.cs +++ b/src/Renci.SshNet/Security/KeyExchangeDiffieHellmanGroup14Sha1.cs @@ -29,7 +29,7 @@ namespace Renci.SshNet.Security get { BigInteger prime; - BigInteger.TryParse(SecondOkleyGroup, NumberStyles.AllowHexSpecifier, CultureInfo.CurrentCulture, out prime); + BigInteger.TryParse(SecondOkleyGroup, NumberStyles.AllowHexSpecifier, NumberFormatInfo.CurrentInfo, out prime); return prime; } } diff --git a/src/Renci.SshNet/Security/KeyExchangeDiffieHellmanGroup1Sha1.cs b/src/Renci.SshNet/Security/KeyExchangeDiffieHellmanGroup1Sha1.cs index 25613a4e..b8df62c9 100644 --- a/src/Renci.SshNet/Security/KeyExchangeDiffieHellmanGroup1Sha1.cs +++ b/src/Renci.SshNet/Security/KeyExchangeDiffieHellmanGroup1Sha1.cs @@ -29,7 +29,7 @@ namespace Renci.SshNet.Security get { BigInteger prime; - BigInteger.TryParse(SecondOkleyGroup, NumberStyles.AllowHexSpecifier, CultureInfo.CurrentCulture, out prime); + BigInteger.TryParse(SecondOkleyGroup, NumberStyles.AllowHexSpecifier, NumberFormatInfo.CurrentInfo, out prime); return prime; } } diff --git a/src/Renci.SshNet/Security/KeyExchangeEllipticCurveDiffieHellman.cs b/src/Renci.SshNet/Security/KeyExchangeEllipticCurveDiffieHellman.cs index 2c8db75d..68a5fdb0 100644 --- a/src/Renci.SshNet/Security/KeyExchangeEllipticCurveDiffieHellman.cs +++ b/src/Renci.SshNet/Security/KeyExchangeEllipticCurveDiffieHellman.cs @@ -1,5 +1,4 @@ using System; -using System.Linq; using Renci.SshNet.Messages.Transport; using Renci.SshNet.Messages; using Renci.SshNet.Common; @@ -85,8 +84,8 @@ namespace Renci.SshNet.Security { base.Start(session, message); - _serverPayload = message.GetBytes().ToArray(); - _clientPayload = Session.ClientInitMessage.GetBytes().ToArray(); + _serverPayload = message.GetBytes(); + _clientPayload = Session.ClientInitMessage.GetBytes(); Session.RegisterMessage("SSH_MSG_KEXECDH_REPLY"); @@ -102,14 +101,14 @@ namespace Renci.SshNet.Security //3. Output (d,Q). BigInteger p; - BigInteger.TryParse("00FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF", NumberStyles.AllowHexSpecifier, CultureInfo.CurrentCulture, out p); + BigInteger.TryParse("00FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF", NumberStyles.AllowHexSpecifier, NumberFormatInfo.CurrentInfo, out p); BigInteger n; - BigInteger.TryParse("00FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC7634D81F4372DDF581A0DB248B0A77AECEC196ACCC52973", NumberStyles.AllowHexSpecifier, CultureInfo.CurrentCulture, out n); + BigInteger.TryParse("00FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC7634D81F4372DDF581A0DB248B0A77AECEC196ACCC52973", NumberStyles.AllowHexSpecifier, NumberFormatInfo.CurrentInfo, out n); BigInteger G; - BigInteger.TryParse("00036B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C296", NumberStyles.AllowHexSpecifier, CultureInfo.CurrentCulture, out G); + BigInteger.TryParse("00036B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C296", NumberStyles.AllowHexSpecifier, NumberFormatInfo.CurrentInfo, out G); BigInteger d; diff --git a/src/Renci.SshNet/Session.cs b/src/Renci.SshNet/Session.cs index 55a702e7..62591a58 100644 --- a/src/Renci.SshNet/Session.cs +++ b/src/Renci.SshNet/Session.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Net; using System.Net.Sockets; using System.Security.Cryptography; @@ -16,6 +15,7 @@ using Renci.SshNet.Messages.Connection; using Renci.SshNet.Messages.Transport; using Renci.SshNet.Security; using System.Globalization; +using System.Linq; using Renci.SshNet.Abstractions; using Renci.SshNet.Security.Cryptography; @@ -954,7 +954,7 @@ namespace Renci.SshNet if (serverHash != null) { Buffer.BlockCopy(nextBlocks, nextBlocks.Length - serverHash.Length, serverHash, 0, serverHash.Length); - nextBlocks = nextBlocks.Take(nextBlocks.Length - serverHash.Length).ToArray(); + nextBlocks = nextBlocks.Take(nextBlocks.Length - serverHash.Length); } if (nextBlocks.Length > 0) @@ -978,7 +978,7 @@ namespace Renci.SshNet { var clientHash = _serverMac.ComputeHash(data); - if (!serverHash.SequenceEqual(clientHash)) + if (!serverHash.IsEqualTo(clientHash)) { throw new SshConnectionException("MAC error", DisconnectReason.MacError); } diff --git a/src/Renci.SshNet/ShellStream.cs b/src/Renci.SshNet/ShellStream.cs index 511a0d84..502a411e 100644 --- a/src/Renci.SshNet/ShellStream.cs +++ b/src/Renci.SshNet/ShellStream.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Text; using System.IO; using Renci.SshNet.Channels; @@ -225,7 +224,7 @@ namespace Renci.SshNet /// Methods were called after the stream was closed. public override void Write(byte[] buffer, int offset, int count) { - foreach (var b in buffer.Skip(offset).Take(count).ToArray()) + foreach (var b in buffer.Take(offset, count)) { if (_outgoing.Count < BufferSize) {