Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/improve tests decrypt #271

Merged
merged 12 commits into from
Jan 12, 2024
2 changes: 1 addition & 1 deletion PgpCore.Tests/TestFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public void Arrange(FileType fileType)
{
using (StreamWriter streamWriter = ContentFileInfo.CreateText())
{
streamWriter.WriteLine(Constants.CONTENT);
streamWriter.Write(Constants.CONTENT);
}
}
else if (fileType == FileType.GeneratedMedium)
Expand Down
46 changes: 46 additions & 0 deletions PgpCore.Tests/TestHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using Org.BouncyCastle.Bcpg.OpenPgp;
using Org.BouncyCastle.Bcpg;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PgpCore.Tests
{
internal static class TestHelper
{
internal static PgpPublicKey ReadPublicKey(Stream inputStream)
{
PgpPublicKeyRingBundle pgpPub = new PgpPublicKeyRingBundle(PgpUtilities.GetDecoderStream(inputStream));
foreach (PgpPublicKeyRing kRing in pgpPub.GetKeyRings())
{
foreach (PgpPublicKey k in kRing.GetPublicKeys())
{
if (k.IsEncryptionKey)
return k;
}
}
throw new ArgumentException("No encryption key found in public key ring.");
}

internal static IEnumerable<T> GetEnumValues<T>() where T : struct, IConvertible
{
foreach (T enumValue in Enum.GetValues(typeof(T)))
{
yield return enumValue;
}
}

internal static IEnumerable<object[]> GetAllCombinations()
{
foreach (CompressionAlgorithmTag compressionAlgorithmTag in GetEnumValues<CompressionAlgorithmTag>())
foreach (HashAlgorithmTag hashAlgorithmTag in GetEnumValues<HashAlgorithmTag>())
foreach (SymmetricKeyAlgorithmTag symmetricKeyAlgorithmTag in GetEnumValues<SymmetricKeyAlgorithmTag>())
{
yield return new object[] { compressionAlgorithmTag, hashAlgorithmTag, symmetricKeyAlgorithmTag };
}
}
}
}
539 changes: 539 additions & 0 deletions PgpCore.Tests/UnitTests/Decrypt/DecryptAsync.File.cs

Large diffs are not rendered by default.

588 changes: 588 additions & 0 deletions PgpCore.Tests/UnitTests/Decrypt/DecryptAsync.Stream.cs

Large diffs are not rendered by default.

Loading
Loading