Files
Gert Driesen 508fc87d2a Fix analyzer errors in Renci.SshNet and Renci.SshNet.TestTools.OpenSSH (#1229)
* Fix analyzer errors in Renci.SshNet and Renci.SshNet.TestTools.OpenSSH.
Suppress all errors in unit tests and integration tests.

* Update unit tests now that we pass 'mode' as argument name when we throw ArgumentException.

* Remove stale comment and add unit tests for SshData.ReadBytes(int length).

* Remove unnessary suppression.

* Remove Visual Studio magic.

* Removed duplicate source file.

* Clarified that suppression hides a false positive.

* Remove suppressions for S2372.

* Update ReadExtensionPair() to return concrete dictionary.
2023-11-01 11:33:42 +01:00

48 lines
1.3 KiB
C#

using System.Text.RegularExpressions;
namespace Renci.SshNet.TestTools.OpenSSH
{
public sealed class Subsystem
{
public Subsystem(string name, string command)
{
Name = name;
Command = command;
}
public string Name { get; }
public string Command { get; set; }
public static Subsystem FromConfig(string value)
{
var subSystemValueRegex = new Regex(@"^\s*(?<name>[\S]+)\s+(?<command>.+?){1}\s*$");
var match = subSystemValueRegex.Match(value);
if (match.Success)
{
var nameGroup = match.Groups["name"];
var commandGroup = match.Groups["command"];
var name = nameGroup.Value;
var command = commandGroup.Value;
return new Subsystem(name, command);
}
throw new ArgumentException($"'{value}' not recognized as value for Subsystem.",
nameof(value));
}
public void WriteTo(TextWriter writer)
{
if (writer is null)
{
throw new ArgumentNullException(nameof(writer));
}
writer.WriteLine(Name + "=" + Command);
}
}
}