Added iteration upgrading for streams
This commit is contained in:
1 parent
36001d0f70
commit
83850f318e
3 files changed
+125
No files matched your search
@@ -168,6 +168,81 @@ namespace Encrypter_Tests
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestUpgradedIterationsBehaviourStreaming()
|
||||
{
|
||||
var tempFileInput = Path.GetTempFileName();
|
||||
var tempFileEncryptedPrevious = Path.GetTempFileName();
|
||||
var tempFileReEncrypted = Path.GetTempFileName();
|
||||
var tempFileDecrypted = Path.GetTempFileName();
|
||||
|
||||
try
|
||||
{
|
||||
var message = "This is a test with umlauts äüö.";
|
||||
await File.WriteAllTextAsync(tempFileInput, message);
|
||||
|
||||
var password = "test password";
|
||||
var previousIterations = 1_000;
|
||||
var upgradedIterations = 1_000_000;
|
||||
|
||||
await using (var outputStream = File.OpenWrite(tempFileEncryptedPrevious))
|
||||
{
|
||||
await using var inputStream = File.OpenRead(tempFileInput);
|
||||
await CryptoProcessor.Encrypt(inputStream, outputStream, password, previousIterations);
|
||||
}
|
||||
|
||||
await using (var outputStream = File.OpenWrite(tempFileReEncrypted))
|
||||
{
|
||||
await using var inputStream = File.OpenRead(tempFileEncryptedPrevious);
|
||||
await CryptoProcessor.UpgradeIterations(inputStream, outputStream, password, previousIterations, upgradedIterations);
|
||||
}
|
||||
|
||||
Assert.That(await File.ReadAllBytesAsync(tempFileEncryptedPrevious), Is.Not.EqualTo(await File.ReadAllBytesAsync(tempFileReEncrypted)));
|
||||
|
||||
await using (var outputStream = File.OpenWrite(tempFileDecrypted))
|
||||
{
|
||||
await using var inputStream = File.OpenRead(tempFileReEncrypted);
|
||||
await CryptoProcessor.Decrypt(inputStream, outputStream, password, upgradedIterations);
|
||||
}
|
||||
|
||||
Assert.That(await File.ReadAllTextAsync(tempFileDecrypted), Is.EqualTo(message));
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Delete(tempFileInput);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
File.Delete(tempFileDecrypted);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
File.Delete(tempFileEncryptedPrevious);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
File.Delete(tempFileReEncrypted);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestChangedPasswordBehaviour()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user