Skip to content

Commit

Permalink
Merge pull request #271 from mattosaurus/chore/improve-tests-decrypt
Browse files Browse the repository at this point in the history
Chore/improve tests decrypt
  • Loading branch information
mattosaurus authored Jan 12, 2024
2 parents 85c698f + b15720c commit aee754a
Show file tree
Hide file tree
Showing 21 changed files with 3,865 additions and 40 deletions.
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

0 comments on commit aee754a

Please sign in to comment.