diff --git a/benchmark/ICSharpCode.SharpZipLib.Benchmark/ICSharpCode.SharpZipLib.Benchmark.csproj b/benchmark/ICSharpCode.SharpZipLib.Benchmark/ICSharpCode.SharpZipLib.Benchmark.csproj
index 7fa26f80f..a6d73c8db 100644
--- a/benchmark/ICSharpCode.SharpZipLib.Benchmark/ICSharpCode.SharpZipLib.Benchmark.csproj
+++ b/benchmark/ICSharpCode.SharpZipLib.Benchmark/ICSharpCode.SharpZipLib.Benchmark.csproj
@@ -3,6 +3,7 @@
Exe
net462;net6.0
+ 8.0
diff --git a/benchmark/ICSharpCode.SharpZipLib.Benchmark/Tar/TarInputStream.cs b/benchmark/ICSharpCode.SharpZipLib.Benchmark/Tar/TarInputStream.cs
index b59a217ab..08116bfe5 100644
--- a/benchmark/ICSharpCode.SharpZipLib.Benchmark/Tar/TarInputStream.cs
+++ b/benchmark/ICSharpCode.SharpZipLib.Benchmark/Tar/TarInputStream.cs
@@ -27,7 +27,7 @@ public TarInputStream()
tarEntry.Size = 1024 * 1024;
zipOutputStream.PutNextEntry(tarEntry);
- var rng = RandomNumberGenerator.Create();
+ using var rng = RandomNumberGenerator.Create();
var inputBuffer = new byte[1024];
rng.GetBytes(inputBuffer);
diff --git a/benchmark/ICSharpCode.SharpZipLib.Benchmark/Zip/ZipOutputStream.cs b/benchmark/ICSharpCode.SharpZipLib.Benchmark/Zip/ZipOutputStream.cs
index c4e8620e3..b6789afb5 100644
--- a/benchmark/ICSharpCode.SharpZipLib.Benchmark/Zip/ZipOutputStream.cs
+++ b/benchmark/ICSharpCode.SharpZipLib.Benchmark/Zip/ZipOutputStream.cs
@@ -27,7 +27,7 @@ public long WriteZipOutputStream()
{
using (var memoryStream = new MemoryStream(outputBuffer))
{
- var zipOutputStream = new SharpZipLib.Zip.ZipOutputStream(memoryStream);
+ using var zipOutputStream = new SharpZipLib.Zip.ZipOutputStream(memoryStream);
zipOutputStream.PutNextEntry(new SharpZipLib.Zip.ZipEntry("0"));
for (int i = 0; i < ChunkCount; i++)
diff --git a/src/ICSharpCode.SharpZipLib/Encryption/ZipAESStream.cs b/src/ICSharpCode.SharpZipLib/Encryption/ZipAESStream.cs
index 346b5484b..d255db3a9 100644
--- a/src/ICSharpCode.SharpZipLib/Encryption/ZipAESStream.cs
+++ b/src/ICSharpCode.SharpZipLib/Encryption/ZipAESStream.cs
@@ -48,7 +48,7 @@ public ZipAESStream(Stream stream, ZipAESTransform transform, CryptoStreamMode m
// total length of block + auth code
private const int BLOCK_AND_AUTH = CRYPTO_BLOCK_SIZE + AUTH_CODE_LENGTH;
- private Stream _stream;
+ private readonly Stream _stream;
private ZipAESTransform _transform;
private byte[] _slideBuffer;
private int _slideBufStartPos;
diff --git a/src/ICSharpCode.SharpZipLib/Encryption/ZipAESTransform.cs b/src/ICSharpCode.SharpZipLib/Encryption/ZipAESTransform.cs
index 32c7b8156..6f7c0ba15 100644
--- a/src/ICSharpCode.SharpZipLib/Encryption/ZipAESTransform.cs
+++ b/src/ICSharpCode.SharpZipLib/Encryption/ZipAESTransform.cs
@@ -51,11 +51,11 @@ public ZipAESTransform(string key, byte[] saltBytes, int blockSize, bool writeMo
// Performs the equivalent of derive_key in Dr Brian Gladman's pwd2key.c
#if NET472_OR_GREATER || NETSTANDARD2_1_OR_GREATER || NETCOREAPP2_0_OR_GREATER
- var pdb = new Rfc2898DeriveBytes(key, saltBytes, KEY_ROUNDS, HashAlgorithmName.SHA1);
+ using var pdb = new Rfc2898DeriveBytes(key, saltBytes, KEY_ROUNDS, HashAlgorithmName.SHA1);
#else
- var pdb = new Rfc2898DeriveBytes(key, saltBytes, KEY_ROUNDS);
+ using var pdb = new Rfc2898DeriveBytes(key, saltBytes, KEY_ROUNDS);
#endif
- var rm = Aes.Create();
+ using var rm = Aes.Create();
rm.Mode = CipherMode.ECB; // No feedback from cipher for CTR mode
_counterNonce = new byte[_blockSize];
byte[] key1bytes = pdb.GetBytes(_blockSize);
@@ -171,7 +171,11 @@ public byte[] TransformFinalBlock(byte[] inputBuffer, int inputOffset, int input
///
/// Cleanup internal state.
///
- public void Dispose() => _encryptor.Dispose();
+ public void Dispose()
+ {
+ _encryptor.Dispose();
+ _hmacsha1.Dispose();
+ }
#endregion ICryptoTransform Members
}
diff --git a/src/ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib.csproj b/src/ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib.csproj
index 49a1cd5cd..26c168f68 100644
--- a/src/ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib.csproj
+++ b/src/ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib.csproj
@@ -2,6 +2,7 @@
netstandard2.0;netstandard2.1;net6.0
+ 8.0
true
true
true
diff --git a/src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs b/src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs
index 7fc1c5592..5b839dd01 100644
--- a/src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs
+++ b/src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs
@@ -863,7 +863,7 @@ public int FindEntry(string name, bool ignoreCase)
// TODO: This will be slow as the next ice age for huge archives!
for (int i = 0; i < entries_.Length; i++)
{
- if (string.Compare(name, entries_[i].Name, ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal) == 0)
+ if (string.Equals(name, entries_[i].Name, ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal))
{
return i;
}
@@ -1208,7 +1208,7 @@ private long TestLocalHeader(ZipEntry entry, HeaderTest tests)
byte[] extraData = new byte[extraDataLength];
StreamUtils.ReadFully(baseStream_, extraData);
- var localExtraData = new ZipExtraData(extraData);
+ using var localExtraData = new ZipExtraData(extraData);
// Extra data / zip64 checks
if (localExtraData.Find(headerID: 1))
@@ -2249,7 +2249,7 @@ private void WriteLocalEntryHeader(ZipUpdate update)
throw new ZipException("Entry name too long.");
}
- var ed = new ZipExtraData(entry.ExtraData);
+ using var ed = new ZipExtraData(entry.ExtraData);
if (entry.LocalHeaderRequiresZip64)
{
@@ -2360,7 +2360,7 @@ private int WriteCentralDirectoryHeader(ZipEntry entry)
WriteLEShort(name.Length);
// Central header extra data is different to local header version so regenerate.
- var ed = new ZipExtraData(entry.ExtraData);
+ using var ed = new ZipExtraData(entry.ExtraData);
if (entry.CentralHeaderRequiresZip64)
{
@@ -3795,7 +3795,7 @@ private Stream CreateAndInitDecryptionStream(Stream baseStream, ZipEntry entry)
{
if (entry.Version < ZipConstants.VersionStrongEncryption || !entry.HasFlag(GeneralBitFlags.StrongEncryption))
{
- var classicManaged = new PkzipClassicManaged();
+ using var classicManaged = new PkzipClassicManaged();
OnKeysRequired(entry.Name);
if (HaveKeys == false)
@@ -3821,7 +3821,7 @@ private Stream CreateAndInitEncryptionStream(Stream baseStream, ZipEntry entry)
if (entry.Version >= ZipConstants.VersionStrongEncryption &&
entry.HasFlag(GeneralBitFlags.StrongEncryption)) return null;
- var classicManaged = new PkzipClassicManaged();
+ using var classicManaged = new PkzipClassicManaged();
OnKeysRequired(entry.Name);
if (HaveKeys == false)
diff --git a/src/ICSharpCode.SharpZipLib/Zip/ZipOutputStream.cs b/src/ICSharpCode.SharpZipLib/Zip/ZipOutputStream.cs
index 2cc36df22..e2908aa4a 100644
--- a/src/ICSharpCode.SharpZipLib/Zip/ZipOutputStream.cs
+++ b/src/ICSharpCode.SharpZipLib/Zip/ZipOutputStream.cs
@@ -766,7 +766,7 @@ private byte[] CreateZipCryptoHeader(long crcValue)
/// The password.
private void InitializeZipCryptoPassword(string password)
{
- var pkManaged = new PkzipClassicManaged();
+ using var pkManaged = new PkzipClassicManaged();
byte[] key = PkzipClassic.GenerateKeys(ZipCryptoEncoding.GetBytes(password));
cryptoTransform_ = pkManaged.CreateEncryptor(key, null);
}