using Microsoft.VisualStudio.TestTools.UnitTesting;
using Renci.SshNet.Security.Cryptography;
using Renci.SshNet.Tests.Common;
using Renci.SshNet.Tests.Properties;
using System.Linq;
using System.Security.Cryptography;
namespace Renci.SshNet.Tests.Classes.Security.Cryptography
{
///
/// Provides HMAC algorithm implementation.
///
///
[TestClass]
public class HMacTest : TestBase
{
[TestMethod]
[TestCategory("integration")]
public void Test_HMac_MD5_Connection()
{
var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD);
connectionInfo.HmacAlgorithms.Clear();
connectionInfo.HmacAlgorithms.Add("hmac-md5", new HashInfo(16 * 8, (key) => { return new HMac(key); }));
using (var client = new SshClient(connectionInfo))
{
client.Connect();
client.Disconnect();
}
}
[TestMethod]
[TestCategory("integration")]
public void Test_HMac_Sha1_Connection()
{
var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD);
connectionInfo.HmacAlgorithms.Clear();
connectionInfo.HmacAlgorithms.Add("hmac-sha1", new HashInfo(20 * 8, (key) => { return new HMac(key); }));
using (var client = new SshClient(connectionInfo))
{
client.Connect();
client.Disconnect();
}
}
[TestMethod]
[TestCategory("integration")]
public void Test_HMac_MD5_96_Connection()
{
var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD);
connectionInfo.HmacAlgorithms.Clear();
connectionInfo.HmacAlgorithms.Add("hmac-md5", new HashInfo(16 * 8, (key) => { return new HMac(key, 96); }));
using (var client = new SshClient(connectionInfo))
{
client.Connect();
client.Disconnect();
}
}
[TestMethod]
[TestCategory("integration")]
public void Test_HMac_Sha1_96_Connection()
{
var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD);
connectionInfo.HmacAlgorithms.Clear();
connectionInfo.HmacAlgorithms.Add("hmac-sha1", new HashInfo(20 * 8, (key) => { return new HMac(key, 96); }));
using (var client = new SshClient(connectionInfo))
{
client.Connect();
client.Disconnect();
}
}
[TestMethod]
[TestCategory("integration")]
public void Test_HMac_Sha256_Connection()
{
var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD);
connectionInfo.HmacAlgorithms.Clear();
connectionInfo.HmacAlgorithms.Add("hmac-sha2-256", new HashInfo(32 * 8, (key) => { return new HMac(key); }));
using (var client = new SshClient(connectionInfo))
{
client.Connect();
client.Disconnect();
}
}
[TestMethod]
[TestCategory("integration")]
public void Test_HMac_Sha256_96_Connection()
{
var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD);
connectionInfo.HmacAlgorithms.Clear();
connectionInfo.HmacAlgorithms.Add("hmac-sha2-256-96", new HashInfo(32 * 8, (key) => { return new HMac(key, 96); }));
using (var client = new SshClient(connectionInfo))
{
client.Connect();
client.Disconnect();
}
}
[TestMethod]
[TestCategory("integration")]
public void Test_HMac_RIPEMD160_Connection()
{
var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD);
connectionInfo.HmacAlgorithms.Clear();
connectionInfo.HmacAlgorithms.Add("hmac-ripemd160", new HashInfo(160, (key) => { return new HMac(key); }));
using (var client = new SshClient(connectionInfo))
{
client.Connect();
client.Disconnect();
}
}
[TestMethod]
[TestCategory("integration")]
public void Test_HMac_RIPEMD160_OPENSSH_Connection()
{
var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD);
connectionInfo.HmacAlgorithms.Clear();
connectionInfo.HmacAlgorithms.Add("hmac-ripemd160@openssh.com", new HashInfo(160, (key) => { return new HMac(key); }));
using (var client = new SshClient(connectionInfo))
{
client.Connect();
client.Disconnect();
}
}
///
///A test for HMac`1 Constructor
///
public void HMacConstructorTestHelper()
where T : HashAlgorithm, new()
{
byte[] key = null; // TODO: Initialize to an appropriate value
HMac target = new HMac(key);
Assert.Inconclusive("TODO: Implement code to verify target");
}
[TestMethod()]
public void HMacConstructorTest()
{
Assert.Inconclusive("No appropriate type parameter is found to satisfies the type constraint(s) of T. " +
"Please call HMacConstructorTestHelper() with appropriate type parameters.");
}
///
///A test for Initialize
///
public void InitializeTestHelper()
where T : HashAlgorithm, new()
{
byte[] key = null; // TODO: Initialize to an appropriate value
HMac target = new HMac(key); // TODO: Initialize to an appropriate value
target.Initialize();
Assert.Inconclusive("A method that does not return a value cannot be verified.");
}
[TestMethod()]
public void InitializeTest()
{
Assert.Inconclusive("No appropriate type parameter is found to satisfies the type constraint(s) of T. " +
"Please call InitializeTestHelper() with appropriate type parameters.");
}
///
///A test for Key
///
public void KeyTestHelper()
where T : HashAlgorithm, new()
{
byte[] key = null; // TODO: Initialize to an appropriate value
HMac target = new HMac(key); // TODO: Initialize to an appropriate value
byte[] expected = null; // TODO: Initialize to an appropriate value
byte[] actual;
target.Key = expected;
actual = target.Key;
Assert.AreEqual(expected, actual);
Assert.Inconclusive("Verify the correctness of this test method.");
}
[TestMethod()]
public void KeyTest()
{
Assert.Inconclusive("No appropriate type parameter is found to satisfies the type constraint(s) of T. " +
"Please call KeyTestHelper() with appropriate type parameters.");
}
}
}