Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions SshNet.Keygen.Tests/TestKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,17 @@ public void TestNonAsciiCommentRoundTrips()
ClassicAssert.AreEqual(comment, ((KeyHostAlgorithm)reloaded.HostKeyAlgorithms.First()).Key.Comment);
}

[Test]
public void TestNullCommentExports()
{
var key = SshKey.Generate(new SshKeyGenerateInfo(SshKeyType.ED25519));
((KeyHostAlgorithm)key.HostKeyAlgorithms.First()).Key.Comment = null;

var reloaded = new PrivateKeyFile(key.ToOpenSshFormat().ToStream());
ClassicAssert.AreEqual("", ((KeyHostAlgorithm)reloaded.HostKeyAlgorithms.First()).Key.Comment);
Assert.DoesNotThrow((Action)(() => key.ToPuttyFormat(SshKeyFormat.PuTTYv3)));
}

[Test]
public void TestPuttyMacCoversUtf8Comment()
{
Expand Down
4 changes: 2 additions & 2 deletions SshNet.Keygen/Extensions/KeyExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ private static string OpensshPrivateKeyData(this Key key, ISshKeyEncryption encr
throw new NotSupportedException($"Unsupported KeyType: {key}");
}
// comment
privWriter.EncodeBinary(key.Comment);
privWriter.EncodeBinary(key.Comment ?? "");

// private key padding (1, 2, 3, ...)
var pad = 0;
Expand Down Expand Up @@ -245,7 +245,7 @@ internal static string ToPuttyFormat(this Key key, ISshKeyEncryption encryption,
using var macWriter = new BinaryWriter(macStream);
macWriter.EncodeBinary(key.ToString()!);
macWriter.EncodeBinary(encryption.CipherName);
macWriter.EncodeBinary(key.Comment);
macWriter.EncodeBinary(key.Comment ?? "");
macWriter.EncodeBinary(pubStream);
macWriter.EncodeBinary(privStream);

Expand Down
Loading