Skip to content

Commit

Permalink
Merge pull request #290 from mattosaurus/chore/package-updates
Browse files Browse the repository at this point in the history
Chore/package updates
  • Loading branch information
mattosaurus authored May 30, 2024
2 parents 86df3a0 + e04bfa8 commit c95cf17
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 44 deletions.
6 changes: 3 additions & 3 deletions PgpCore.Tests/PgpCore.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="xunit" Version="2.6.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.4">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="xunit" Version="2.8.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
4 changes: 2 additions & 2 deletions PgpCore.Tests/UnitTests/TestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ namespace PgpCore.Tests.UnitTests
public abstract class TestBase
{
#if NETFRAMEWORK
public const string VERSION = "BouncyCastle.NET Cryptography (net461) v2.1.1+851feee009";
public const string VERSION = "BouncyCastle.NET Cryptography (net461) v2.4.0+83ebf4a805";
#else
public const string VERSION = "BouncyCastle.NET Cryptography (net6.0) v2.1.1+851feee009";
public const string VERSION = "BouncyCastle.NET Cryptography (net6.0) v2.4.0+83ebf4a805";
#endif
public const string DEFAULTNAME = "name";
public const string TESTNAME = "Test Name";
Expand Down
2 changes: 1 addition & 1 deletion PgpCore/Abstractions/IPGP.VerifyAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public interface IVerifyAsync : IDisposable
Task<bool> VerifyAsync(string input, bool throwIfEncrypted = false);
Task<bool> VerifyClearAsync(FileInfo inputFile, FileInfo outputFile = null);
Task<bool> VerifyClearAsync(Stream inputStream, Stream outputStream = null);
Task<bool> VerifyClearAsync(string input, string output = null);
Task<bool> VerifyClearAsync(string input);

Task<bool> VerifyFileAsync(FileInfo inputFile, bool throwIfEncrypted = false);
Task<bool> VerifyStreamAsync(Stream inputStream, bool throwIfEncrypted = false);
Expand Down
20 changes: 1 addition & 19 deletions PgpCore/PGP.VerifyAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public async Task<bool> VerifyAsync(Stream inputStream, Stream outputStream = nu
else
throw new PgpException("Message is not a encrypted and signed file or simple signed file.");

outputStream.Flush();
await outputStream.FlushAsync();
outputStream.Seek(0, SeekOrigin.Begin);

return (verified);
Expand Down Expand Up @@ -333,24 +333,6 @@ public async Task<bool> VerifyClearAsync(string input)
return await VerifyClearAsync(inputStream, null);
}

/// <summary>
/// PGP verify a given string.
/// </summary>
/// <param name="input">Plain string to be verified</param>
/// <param name="output">String to write the decrypted data to</param>
public async Task<bool> VerifyClearAsync(string input, string output)
{
using (Stream inputStream = await input.GetStreamAsync())
using (Stream outputStream = new MemoryStream())
{
bool verified = await VerifyClearAsync(inputStream, outputStream);

outputStream.Seek(0, SeekOrigin.Begin);
output = await outputStream.GetStringAsync();
return verified;
}
}

public async Task<bool> VerifyClearFileAsync(FileInfo inputFile) => await VerifyClearAsync(inputFile, null);

public async Task<bool> VerifyClearStreamAsync(Stream inputStream) => await VerifyClearAsync(inputStream, null);
Expand Down
27 changes: 12 additions & 15 deletions PgpCore/PGP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private async Task OutputEncryptedAsync(Stream inputStream, Stream outputStream,
using (Stream compressedOut = ChainCompressedOut(encryptedOut))
{
PgpSignatureGenerator signatureGenerator = InitSignatureGenerator(compressedOut);
using (Stream literalOut = ChainLiteralStreamOut(compressedOut, inputStream, name, oldFormat))
using (Stream literalOut = ChainLiteralOut(compressedOut, inputStream, name, oldFormat))
{
await WriteOutputAndSignAsync(compressedOut, literalOut, inputStream, signatureGenerator);
}
Expand Down Expand Up @@ -117,7 +117,7 @@ private void OutputEncrypted(Stream inputStream, Stream outputStream, bool withI
using (Stream compressedOut = ChainCompressedOut(encryptedOut))
{
PgpSignatureGenerator signatureGenerator = InitSignatureGenerator(compressedOut);
using (Stream literalOut = ChainLiteralStreamOut(compressedOut, inputStream, name, oldFormat))
using (Stream literalOut = ChainLiteralOut(compressedOut, inputStream, name, oldFormat))
{
WriteOutputAndSign(compressedOut, literalOut, inputStream, signatureGenerator);
}
Expand Down Expand Up @@ -150,7 +150,7 @@ private async Task OutputSignedAsync(Stream inputStream, Stream outputStream,
using (Stream compressedOut = ChainCompressedOut(outputStream))
{
PgpSignatureGenerator signatureGenerator = InitSignatureGenerator(compressedOut);
using (Stream literalOut = ChainLiteralStreamOut(compressedOut, inputStream, name, oldFormat))
using (Stream literalOut = ChainLiteralOut(compressedOut, inputStream, name, oldFormat))
{
await WriteOutputAndSignAsync(compressedOut, literalOut, inputStream, signatureGenerator);
}
Expand Down Expand Up @@ -181,7 +181,7 @@ private void OutputSigned(Stream inputStream, Stream outputStream, string name,
using (Stream compressedOut = ChainCompressedOut(outputStream))
{
PgpSignatureGenerator signatureGenerator = InitSignatureGenerator(compressedOut);
using (Stream literalOut = ChainLiteralStreamOut(compressedOut, inputStream, name, oldFormat))
using (Stream literalOut = ChainLiteralOut(compressedOut, inputStream, name, oldFormat))
{
WriteOutputAndSign(compressedOut, literalOut, inputStream, signatureGenerator);
}
Expand Down Expand Up @@ -390,34 +390,31 @@ private Stream ChainCompressedOut(Stream encryptedOut)
private Stream ChainLiteralOut(Stream compressedOut, FileInfo file, string name, bool oldFormat)
{
PgpLiteralDataGenerator pgpLiteralDataGenerator = new PgpLiteralDataGenerator(oldFormat);
return pgpLiteralDataGenerator.Open(compressedOut, FileTypeToChar(), name, file.Length,

return pgpLiteralDataGenerator.Open(compressedOut, FileTypeToChar(), name, file.Length,
DateTime.UtcNow);
}

#endregion ChainLiteralOut

#region ChainLiteralStreamOut

private Stream ChainLiteralStreamOut(Stream compressedOut, Stream inputStream, string name, bool oldFormat)
private Stream ChainLiteralOut(Stream compressedOut, Stream inputStream, string name, bool oldFormat)
{
PgpLiteralDataGenerator pgpLiteralDataGenerator = new PgpLiteralDataGenerator(oldFormat);
return pgpLiteralDataGenerator.Open(compressedOut, FileTypeToChar(), name, inputStream.Length,
DateTime.UtcNow);
}

#endregion ChainLiteralStreamOut
#endregion ChainLiteralOut

#region InitSignatureGenerator
#region InitSignatureGenerator

private PgpSignatureGenerator InitSignatureGenerator(Stream compressedOut)
private PgpSignatureGenerator InitSignatureGenerator(Stream compressedOut)
{
PublicKeyAlgorithmTag tag = EncryptionKeys.SigningSecretKey.PublicKey.Algorithm;
PgpSignatureGenerator pgpSignatureGenerator = new PgpSignatureGenerator(tag, HashAlgorithmTag);
pgpSignatureGenerator.InitSign(PgpSignature.BinaryDocument, EncryptionKeys.SigningPrivateKey);
foreach (string userId in EncryptionKeys.SigningSecretKey.PublicKey.GetUserIds())
{
PgpSignatureSubpacketGenerator subPacketGenerator = new PgpSignatureSubpacketGenerator();
subPacketGenerator.SetSignerUserId(false, userId);
subPacketGenerator.AddSignerUserId(false, userId);
pgpSignatureGenerator.SetHashedSubpackets(subPacketGenerator.Generate());
// Just the first one!
break;
Expand All @@ -440,7 +437,7 @@ private PgpSignatureGenerator InitClearSignatureGenerator(ArmoredOutputStream ar
foreach (string userId in EncryptionKeys.SigningSecretKey.PublicKey.GetUserIds())
{
PgpSignatureSubpacketGenerator subPacketGenerator = new PgpSignatureSubpacketGenerator();
subPacketGenerator.SetSignerUserId(false, userId);
subPacketGenerator.AddSignerUserId(false, userId);
pgpSignatureGenerator.SetHashedSubpackets(subPacketGenerator.Generate());
// Just the first one!
break;
Expand Down
8 changes: 4 additions & 4 deletions PgpCore/PgpCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<PackageTags>PGP .NET Core</PackageTags>
<Version>6.4.0.0</Version>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<FileVersion>6.4.0</FileVersion>
<PackageReleaseNotes>v6.4.0 - Remove armor option from string methods</PackageReleaseNotes>
<FileVersion>6.4.1</FileVersion>
<PackageReleaseNotes>v6.4.1 - Package updates</PackageReleaseNotes>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<IncludeSymbols>true</IncludeSymbols>
Expand Down Expand Up @@ -121,8 +121,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="BouncyCastle.Cryptography" Version="2.1.1" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="BouncyCastle.Cryptography" Version="2.4.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
</ItemGroup>

</Project>

0 comments on commit c95cf17

Please sign in to comment.