Skip to content

Commit 18e6673

Browse files
Improvements after #1177 (#1180)
1 parent 8732d3d commit 18e6673

18 files changed

+68
-104
lines changed

src/Renci.SshNet.Benchmarks/Security/Cryptography/Ciphers/RsaCipherBenchmarks.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ public RsaCipherBenchmarks()
2121

2222
using (var s = typeof(RsaCipherBenchmarks).Assembly.GetManifestResourceStream("Renci.SshNet.Benchmarks.Data.Key.RSA.txt"))
2323
{
24-
_privateKey = (RsaKey)((KeyHostAlgorithm) new PrivateKeyFile(s).HostKey).Key;
24+
25+
_privateKey = (RsaKey)new PrivateKeyFile(s).Key;
2526

2627
// The implementations of RsaCipher.Encrypt/Decrypt differ based on whether the supplied RsaKey has private key information
2728
// or only public. So we extract out the public key information to a separate variable.

src/Renci.SshNet.Benchmarks/Security/Cryptography/ED25519DigitalSignatureBenchmarks.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public ED25519DigitalSignatureBenchmarks()
2121

2222
using (var s = typeof(ED25519DigitalSignatureBenchmarks).Assembly.GetManifestResourceStream("Renci.SshNet.Benchmarks.Data.Key.OPENSSH.ED25519.txt"))
2323
{
24-
_key = (ED25519Key) ((KeyHostAlgorithm) new PrivateKeyFile(s).HostKey).Key;
24+
_key = (ED25519Key) new PrivateKeyFile(s).Key;
2525
}
2626
_signature = new ED25519DigitalSignature(_key).Sign(_data);
2727
}

src/Renci.SshNet.Tests/Classes/BaseClientTest_Connect_OnConnectedThrowsException.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Linq;
23
using System.Reflection;
34
using System.Threading;
45
using Microsoft.VisualStudio.TestTools.UnitTesting;
@@ -140,7 +141,7 @@ private static KeyHostAlgorithm GetKeyHostAlgorithm()
140141
using (var s = executingAssembly.GetManifestResourceStream(string.Format("Renci.SshNet.Tests.Data.{0}", "Key.RSA.txt")))
141142
{
142143
var privateKey = new PrivateKeyFile(s);
143-
return (KeyHostAlgorithm) privateKey.HostKey;
144+
return (KeyHostAlgorithm) privateKey.HostKeyAlgorithms.First();
144145
}
145146
}
146147

src/Renci.SshNet.Tests/Classes/Common/HostKeyEventArgsTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ private static KeyHostAlgorithm GetKeyHostAlgorithm()
8989
using (var s = executingAssembly.GetManifestResourceStream(string.Format("Renci.SshNet.Tests.Data.{0}", "Key.RSA.txt")))
9090
{
9191
var privateKey = new PrivateKeyFile(s);
92-
return (KeyHostAlgorithm)privateKey.HostKey;
92+
return (KeyHostAlgorithm)privateKey.HostKeyAlgorithms.First();
9393
}
9494
}
9595

src/Renci.SshNet.Tests/Classes/NetConfClientTest_Connect_NetConfSessionConnectFailure.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Linq;
23
using System.Reflection;
34
using System.Threading;
45

@@ -113,7 +114,7 @@ private static KeyHostAlgorithm GetKeyHostAlgorithm()
113114
using (var s = executingAssembly.GetManifestResourceStream(string.Format("Renci.SshNet.Tests.Data.{0}", "Key.RSA.txt")))
114115
{
115116
var privateKey = new PrivateKeyFile(s);
116-
return (KeyHostAlgorithm)privateKey.HostKey;
117+
return (KeyHostAlgorithm)privateKey.HostKeyAlgorithms.First();
117118
}
118119
}
119120
}

src/Renci.SshNet.Tests/Classes/PrivateKeyFileTest.cs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
using Microsoft.VisualStudio.TestTools.UnitTesting;
22
using Renci.SshNet.Common;
3-
using Renci.SshNet.Security;
43
using Renci.SshNet.Tests.Common;
54
using System;
6-
using System.Collections.Generic;
75
using System.IO;
86
using System.Linq;
97

@@ -412,7 +410,7 @@ public void ConstructorWithStreamAndPassphrase()
412410
using (var stream = GetData("Key.RSA.Encrypted.Aes.128.CBC.12345.txt"))
413411
{
414412
var privateKeyFile = new PrivateKeyFile(stream, "12345");
415-
Assert.IsNotNull(privateKeyFile.HostKey);
413+
TestRsaKeyFile(privateKeyFile);
416414
}
417415
}
418416

@@ -430,7 +428,7 @@ public void ConstructorWithFileNameAndPassphrase()
430428
using (var fs = File.Open(_temporaryFile, FileMode.Open, FileAccess.Read, FileShare.Read))
431429
{
432430
var privateKeyFile = new PrivateKeyFile(_temporaryFile, "12345");
433-
Assert.IsNotNull(privateKeyFile.HostKey);
431+
TestRsaKeyFile(privateKeyFile);
434432

435433
fs.Close();
436434
}
@@ -498,7 +496,7 @@ public void ConstructorWithFileName()
498496
}
499497

500498
var privateKeyFile = new PrivateKeyFile(_temporaryFile, "12345");
501-
Assert.IsNotNull(privateKeyFile.HostKey);
499+
TestRsaKeyFile(privateKeyFile);
502500
}
503501

504502
/// <summary>
@@ -510,7 +508,7 @@ public void ConstructorWithStream()
510508
using (var stream = GetData("Key.RSA.txt"))
511509
{
512510
var privateKeyFile = new PrivateKeyFile(stream);
513-
Assert.IsNotNull(privateKeyFile.HostKey);
511+
TestRsaKeyFile(privateKeyFile);
514512
}
515513
}
516514

@@ -526,7 +524,7 @@ public void ConstructorWithFileNameShouldBeAbleToReadFileThatIsSharedForReadAcce
526524
using (var fs = File.Open(_temporaryFile, FileMode.Open, FileAccess.Read, FileShare.Read))
527525
{
528526
var privateKeyFile = new PrivateKeyFile(_temporaryFile);
529-
Assert.IsNotNull(privateKeyFile.HostKey);
527+
TestRsaKeyFile(privateKeyFile);
530528

531529
fs.Close();
532530
}
@@ -544,7 +542,7 @@ public void ConstructorWithFileNameAndPassPhraseShouldBeAbleToReadFileThatIsShar
544542
using (var fs = File.Open(_temporaryFile, FileMode.Open, FileAccess.Read, FileShare.Read))
545543
{
546544
var privateKeyFile = new PrivateKeyFile(_temporaryFile, "12345");
547-
Assert.IsNotNull(privateKeyFile.HostKey);
545+
TestRsaKeyFile(privateKeyFile);
548546

549547
fs.Close();
550548
}
@@ -684,15 +682,14 @@ private string GetTempFileName()
684682

685683
private static void TestRsaKeyFile(PrivateKeyFile rsaPrivateKeyFile)
686684
{
687-
Assert.AreEqual(3, rsaPrivateKeyFile.HostAlgorithms.Count);
685+
Assert.IsNotNull(rsaPrivateKeyFile.HostKeyAlgorithms);
686+
Assert.AreEqual(3, rsaPrivateKeyFile.HostKeyAlgorithms.Count);
688687

689-
List<KeyHostAlgorithm> algorithms = rsaPrivateKeyFile.HostAlgorithms.Cast<KeyHostAlgorithm>().ToList();
688+
var algorithms = rsaPrivateKeyFile.HostKeyAlgorithms.ToList();
690689

691690
Assert.AreEqual("rsa-sha2-512", algorithms[0].Name);
692691
Assert.AreEqual("rsa-sha2-256", algorithms[1].Name);
693692
Assert.AreEqual("ssh-rsa", algorithms[2].Name);
694-
695-
Assert.AreSame(algorithms[0], rsaPrivateKeyFile.HostKey);
696693
}
697694
}
698695
}

src/Renci.SshNet.Tests/Classes/Security/Cryptography/RsaDigitalSignatureTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ private static RsaKey GetRsaKey()
164164
{
165165
using (var stream = GetData("Key.RSA.txt"))
166166
{
167-
return (RsaKey) ((KeyHostAlgorithm) new PrivateKeyFile(stream).HostKey).Key;
167+
return (RsaKey) new PrivateKeyFile(stream).Key;
168168
}
169169
}
170170

src/Renci.SshNet.Tests/Classes/Security/KeyAlgorithmTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Security.Cryptography;
1+
using System.Security.Cryptography;
22
using System.Text;
33

44
using Microsoft.VisualStudio.TestTools.UnitTesting;
@@ -176,7 +176,7 @@ private static RsaKey GetRsaKey()
176176
{
177177
using (var stream = GetData("Key.RSA.txt"))
178178
{
179-
return (RsaKey) ((KeyHostAlgorithm) new PrivateKeyFile(stream).HostKey).Key;
179+
return (RsaKey) new PrivateKeyFile(stream).Key;
180180
}
181181
}
182182

src/Renci.SshNet.Tests/Classes/SftpClientTest_Connect_SftpSessionConnectFailure.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Linq;
23
using System.Reflection;
34
using System.Threading;
45

@@ -122,7 +123,7 @@ private static KeyHostAlgorithm GetKeyHostAlgorithm()
122123
using (var s = executingAssembly.GetManifestResourceStream(string.Format("Renci.SshNet.Tests.Data.{0}", "Key.RSA.txt")))
123124
{
124125
var privateKey = new PrivateKeyFile(s);
125-
return (KeyHostAlgorithm)privateKey.HostKey;
126+
return (KeyHostAlgorithm)privateKey.HostKeyAlgorithms.First();
126127
}
127128
}
128129
}

src/Renci.SshNet/IHostAlgorithmsProvider.cs

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)