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
9 changes: 6 additions & 3 deletions PgpCore/PGP.VerifyAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,12 @@ public async Task<bool> VerifyClearAsync(Stream inputStream, Stream outputStream
{
MemoryStream lineOut = new MemoryStream();
byte[] lineSep = LineSeparator;
int lookAhead = ReadInputLine(lineOut, armoredInputStream);
var lookAhead = ReadInputLine(lineOut, armoredInputStream);

// Read past message to signature and store message in stream
if (lookAhead != -1 && armoredInputStream.IsClearText())
{
byte[] line = lineOut.ToArray();
var line = lineOut.ToArray();
await outStream.WriteAsync(line, 0, GetLengthWithoutSeparatorOrTrailingWhitespace(line));
await outStream.WriteAsync(lineSep, 0, lineSep.Length);

Expand All @@ -278,11 +278,14 @@ public async Task<bool> VerifyClearAsync(Stream inputStream, Stream outputStream

line = lineOut.ToArray();
await outStream.WriteAsync(line, 0, GetLengthWithoutSeparatorOrTrailingWhitespace(line));
// Add missing new line
if (lookAhead != 1)
Copy link

Copilot AI Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition lookAhead != 1 is incorrect. The value 1 represents ASCII character 1 (SOH - Start of Heading), not the end of stream. Based on the ReadInputLine implementation and consistent usage throughout the codebase, lookAhead returns -1 when the end of stream is reached. This condition should be lookAhead != -1 to add a line separator for all lines except the last one.

Suggested change
if (lookAhead != 1)
if (lookAhead != -1)

Copilot uses AI. Check for mistakes.
await outStream.WriteAsync(lineSep, 0, lineSep.Length);
}
}
else if (lookAhead != -1)
{
byte[] line = lineOut.ToArray();
var line = lineOut.ToArray();
await outStream.WriteAsync(line, 0, GetLengthWithoutSeparatorOrTrailingWhitespace(line));
}

Expand Down
9 changes: 6 additions & 3 deletions PgpCore/PGP.VerifySync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,12 @@ public bool VerifyClear(Stream inputStream, Stream outputStream = null)
{
MemoryStream lineOut = new MemoryStream();
byte[] lineSep = LineSeparator;
int lookAhead = ReadInputLine(lineOut, armoredInputStream);
var lookAhead = ReadInputLine(lineOut, armoredInputStream);

// Read past message to signature and store message in stream
if (lookAhead != -1 && armoredInputStream.IsClearText())
{
byte[] line = lineOut.ToArray();
var line = lineOut.ToArray();
outStream.Write(line, 0, GetLengthWithoutSeparatorOrTrailingWhitespace(line));
outStream.Write(lineSep, 0, lineSep.Length);

Expand All @@ -273,11 +273,14 @@ public bool VerifyClear(Stream inputStream, Stream outputStream = null)

line = lineOut.ToArray();
outStream.Write(line, 0, GetLengthWithoutSeparatorOrTrailingWhitespace(line));
// Add missing new line
if (lookAhead != 1)
Copy link

Copilot AI Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix for issue #306 (handling consecutive newlines in clear-signed messages) lacks test coverage. Consider adding tests that verify messages containing consecutive newlines such as "foo\nbar\n\n" or "foo\n\nbar" are correctly signed and verified, as these were the failing cases reported in the issue.

Suggested change
if (lookAhead != 1)
if (lookAhead != -1)

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition lookAhead != 1 is incorrect. The value 1 represents ASCII character 1 (SOH - Start of Heading), not the end of stream. Based on the ReadInputLine implementation and consistent usage throughout the codebase, lookAhead returns -1 when the end of stream is reached. This condition should be lookAhead != -1 to add a line separator for all lines except the last one.

Suggested change
if (lookAhead != 1)
if (lookAhead != -1)

Copilot uses AI. Check for mistakes.
outStream.Write(lineSep, 0, lineSep.Length);
}
}
else if (lookAhead != -1)
{
byte[] line = lineOut.ToArray();
var line = lineOut.ToArray();
outStream.Write(line, 0, GetLengthWithoutSeparatorOrTrailingWhitespace(line));
}

Expand Down
6 changes: 3 additions & 3 deletions PgpCore/PgpCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
<PackageProjectUrl>https://github.com/mattosaurus/PgpCore</PackageProjectUrl>
<RepositoryUrl>https://github.com/mattosaurus/PgpCore</RepositoryUrl>
<PackageTags>PGP .NET Core</PackageTags>
<Version>6.5.4.0</Version>
<Version>6.5.5.0</Version>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<FileVersion>6.5.4</FileVersion>
<PackageReleaseNotes>v6.5.4 - Fix clearsign encoding</PackageReleaseNotes>
<FileVersion>6.5.5</FileVersion>
<PackageReleaseNotes>v6.5.5 - Fix missing newlines</PackageReleaseNotes>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<IncludeSymbols>true</IncludeSymbols>
Expand Down