more async fixes
This commit is contained in:
parent
62b8fc92d1
commit
46e2ea8507
2 changed files with 16 additions and 13 deletions
|
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using SharpCompress.Common;
|
||||
using SharpCompress.Crypto;
|
||||
|
||||
namespace SharpCompress.Common.Rar;
|
||||
|
|
@ -81,23 +82,25 @@ internal sealed class RarCryptoWrapper : Stream
|
|||
var alignedSize = sizeToRead + ((~sizeToRead + 1) & 0xf);
|
||||
byte[] cipherText = new byte[16];
|
||||
|
||||
for (var i = 0; i < alignedSize / 16; i++)
|
||||
try
|
||||
{
|
||||
var bytesRead = await _actualStream
|
||||
.ReadAsync(cipherText, 0, 16, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
if (bytesRead == 0)
|
||||
for (var i = 0; i < alignedSize / 16; i++)
|
||||
{
|
||||
break;
|
||||
}
|
||||
await _actualStream
|
||||
.ReadExactAsync(cipherText, 0, 16, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
var readBytes = _rijndael.ProcessBlock(cipherText.AsSpan(0, bytesRead));
|
||||
foreach (var readByte in readBytes)
|
||||
{
|
||||
_data.Enqueue(readByte);
|
||||
var readBytes = _rijndael.ProcessBlock(cipherText);
|
||||
foreach (var readByte in readBytes)
|
||||
{
|
||||
_data.Enqueue(readByte);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (EndOfStreamException e)
|
||||
{
|
||||
throw new InvalidFormatException("Unexpected end of encrypted stream", e);
|
||||
}
|
||||
}
|
||||
|
||||
var bytesToReturn = Math.Min(count, _data.Count);
|
||||
|
|
|
|||
|
|
@ -131,7 +131,7 @@ public class GZipArchiveAsyncTests : ArchiveTests
|
|||
await using (var entryStream = await archiveEntry.OpenEntryStreamAsync())
|
||||
#endif
|
||||
{
|
||||
var result = TarArchive.IsTarFile(entryStream);
|
||||
var result = await TarArchive.IsTarFileAsync(entryStream);
|
||||
Assert.True(result);
|
||||
}
|
||||
Assert.Equal(size, tarStream.Length);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue