Files
ssh.net/test/Renci.SshNet.Tests/Classes/Security/KeyExchangeDiffieHellmanTest.cs
Rob Hague dab8a11738 Use BouncyCastle for Diffie-Hellman key exchange (#1654)
Removes another vestige of hand-rolled crypto, and makes the classes public +
configurable for if/when we remove certain algorithms.
2025-08-02 11:08:56 +02:00

50 lines
2.0 KiB
C#

using System;
using System.Security.Cryptography;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Org.BouncyCastle.Crypto.Agreement;
using Renci.SshNet.Security;
namespace Renci.SshNet.Tests.Classes.Security
{
[TestClass]
public class KeyExchangeDiffieHellmanTest
{
[TestMethod]
public void NameShouldBeCtorValue()
{
KeyExchangeDiffieHellman kex = new("diffie-hellman-group16-sha512", DHStandardGroups.rfc3526_4096, HashAlgorithmName.SHA512);
Assert.AreEqual("diffie-hellman-group16-sha512", kex.Name);
}
[TestMethod]
public void Ctor_ArgumentNullException()
{
var ex = Assert.Throws<ArgumentNullException>(() => new KeyExchangeDiffieHellman(name: null, DHStandardGroups.rfc3526_4096, HashAlgorithmName.SHA512));
Assert.AreEqual("name", ex.ParamName);
ex = Assert.Throws<ArgumentNullException>(() => new KeyExchangeDiffieHellman("kex", parameters: null, HashAlgorithmName.SHA512));
Assert.AreEqual("parameters", ex.ParamName);
ex = Assert.Throws<ArgumentNullException>(() => new KeyExchangeDiffieHellman("kex", DHStandardGroups.rfc3526_4096, default));
Assert.AreEqual("hashAlgorithm", ex.ParamName);
ex = Assert.Throws<ArgumentNullException>(() => new KeyExchangeDiffieHellman("kex", DHStandardGroups.rfc3526_4096, new HashAlgorithmName(null)));
Assert.AreEqual("hashAlgorithm", ex.ParamName);
}
[TestMethod]
public void Ctor_InvalidHashAlgorithm_ThrowsArgumentException()
{
var ex = Assert.ThrowsExactly<ArgumentException>(() => new KeyExchangeDiffieHellman("kex", DHStandardGroups.rfc3526_4096, new HashAlgorithmName("bad")));
Assert.AreEqual("hashAlgorithm", ex.ParamName);
ex = Assert.ThrowsExactly<ArgumentException>(() => new KeyExchangeDiffieHellman("kex", DHStandardGroups.rfc3526_4096, new HashAlgorithmName("")));
Assert.AreEqual("hashAlgorithm", ex.ParamName);
}
}
}