Skip to content

Commit cea8b0d

Browse files
authored
prepare for v1.4.0 (#755)
changes needed for the upcoming release, mainly related to .NET 6 compatibility
1 parent b314d3d commit cea8b0d

File tree

6 files changed

+54
-110
lines changed

6 files changed

+54
-110
lines changed

.github/workflows/build-test.yml

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,8 @@ jobs:
1818
strategy:
1919
fail-fast: false
2020
matrix:
21-
os: [ubuntu-latest, windows-2019, macos-latest]
22-
target: [netstandard2.0, netstandard2.1]
23-
include:
24-
- os: windows-2019
25-
target: net45
21+
os: [ubuntu-latest, windows-latest, macos-latest]
22+
target: [netstandard2.0, netstandard2.1, net6.0]
2623
env:
2724
LIB_PROJ: src/ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib.csproj
2825
steps:
@@ -31,10 +28,10 @@ jobs:
3128
ref: ${{ github.events.inputs.tag }}
3229
fetch-depth: 0
3330

34-
- name: Setup .NET Core
31+
- name: Setup .NET
3532
uses: actions/setup-dotnet@v1
3633
with:
37-
dotnet-version: '3.1.x'
34+
dotnet-version: '6.0.x'
3835

3936
- name: Show .NET info
4037
run: dotnet --info
@@ -52,17 +49,17 @@ jobs:
5249
matrix:
5350
# Windows testing is combined with code coverage
5451
os: [ubuntu, macos]
55-
target: [netcoreapp3.1]
52+
target: [net6.0]
5653
steps:
5754
- uses: actions/checkout@v2
5855
with:
5956
fetch-depth: 0
6057

6158
- name: Setup .NET Core
62-
if: matrix.target == 'netcoreapp3.1'
59+
if: matrix.target == 'net6.0'
6360
uses: actions/setup-dotnet@v1
6461
with:
65-
dotnet-version: '3.1.x'
62+
dotnet-version: '6.0.x'
6663

6764
- name: Restore test dependencies
6865
run: dotnet restore
@@ -89,7 +86,7 @@ jobs:
8986
- name: Setup .NET
9087
uses: actions/setup-dotnet@v1
9188
with:
92-
dotnet-version: '3.1.x'
89+
dotnet-version: '6.0.x'
9390

9491
# NOTE: This is the temporary fix for https://github.com/actions/virtual-environments/issues/1090
9592
- name: Cleanup before restore
@@ -120,7 +117,7 @@ jobs:
120117

121118
Pack:
122119
needs: [Build, Test, CodeCov]
123-
runs-on: windows-2019
120+
runs-on: windows-latest
124121
env:
125122
PKG_SUFFIX: ''
126123
PKG_PROJ: src/ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib.csproj
@@ -135,14 +132,14 @@ jobs:
135132
- name: Setup .NET Core
136133
uses: actions/setup-dotnet@v1
137134
with:
138-
dotnet-version: '5.0.x'
135+
dotnet-version: '6.0.x'
139136

140137
- name: Build library for .NET Standard 2.0
141138
run: dotnet build -c Release -f netstandard2.0 ${{ env.PKG_PROPS }} ${{ env.PKG_PROJ }}
142139
- name: Build library for .NET Standard 2.1
143140
run: dotnet build -c Release -f netstandard2.1 ${{ env.PKG_PROPS }} ${{ env.PKG_PROJ }}
144-
- name: Build library for .NET Framework 4.5
145-
run: dotnet build -c Release -f net45 ${{ env.PKG_PROPS }} ${{ env.PKG_PROJ }}
141+
- name: Build library for .NET 6.0
142+
run: dotnet build -c Release -f net6.0 ${{ env.PKG_PROPS }} ${{ env.PKG_PROJ }}
146143

147144
- name: Add PR suffix to package
148145
if: ${{ github.event_name == 'pull_request' }}

benchmark/ICSharpCode.SharpZipLib.Benchmark/ICSharpCode.SharpZipLib.Benchmark.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFrameworks>netcoreapp2.1;netcoreapp3.1;net461</TargetFrameworks>
5+
<TargetFrameworks>net6.0;netcoreapp3.1;net462</TargetFrameworks>
66
</PropertyGroup>
77

88
<ItemGroup>

src/ICSharpCode.SharpZipLib/Encryption/ZipAESStream.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public ZipAESStream(Stream stream, ZipAESTransform transform, CryptoStreamMode m
4040
}
4141

4242
// The final n bytes of the AES stream contain the Auth Code.
43-
private const int AUTH_CODE_LENGTH = 10;
43+
public const int AUTH_CODE_LENGTH = 10;
4444

4545
// Blocksize is always 16 here, even for AES-256 which has transform.InputBlockSize of 32.
4646
private const int CRYPTO_BLOCK_SIZE = 16;

src/ICSharpCode.SharpZipLib/Encryption/ZipAESTransform.cs

Lines changed: 28 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Security.Cryptography;
3-
using ICSharpCode.SharpZipLib.Core;
43

54
namespace ICSharpCode.SharpZipLib.Encryption
65
{
@@ -9,31 +8,6 @@ namespace ICSharpCode.SharpZipLib.Encryption
98
/// </summary>
109
internal class ZipAESTransform : ICryptoTransform
1110
{
12-
#if NET45
13-
class IncrementalHash : HMACSHA1
14-
{
15-
bool _finalised;
16-
public IncrementalHash(byte[] key) : base(key) { }
17-
public static IncrementalHash CreateHMAC(string n, byte[] key) => new IncrementalHash(key);
18-
public void AppendData(byte[] buffer, int offset, int count) => TransformBlock(buffer, offset, count, buffer, offset);
19-
public byte[] GetHashAndReset()
20-
{
21-
if (!_finalised)
22-
{
23-
byte[] dummy = new byte[0];
24-
TransformFinalBlock(dummy, 0, 0);
25-
_finalised = true;
26-
}
27-
return Hash;
28-
}
29-
}
30-
31-
static class HashAlgorithmName
32-
{
33-
public static string SHA1 = null;
34-
}
35-
#endif
36-
3711
private const int PWD_VER_LENGTH = 2;
3812

3913
// WinZip use iteration count of 1000 for PBKDF2 key generation
@@ -137,91 +111,67 @@ public int TransformBlock(byte[] inputBuffer, int inputOffset, int inputCount, b
137111
/// <summary>
138112
/// Returns the 2 byte password verifier
139113
/// </summary>
140-
public byte[] PwdVerifier
141-
{
142-
get
143-
{
144-
return _pwdVerifier;
145-
}
146-
}
114+
public byte[] PwdVerifier => _pwdVerifier;
147115

148116
/// <summary>
149117
/// Returns the 10 byte AUTH CODE to be checked or appended immediately following the AES data stream.
150118
/// </summary>
151-
public byte[] GetAuthCode()
152-
{
153-
if (_authCode == null)
154-
{
155-
_authCode = _hmacsha1.GetHashAndReset();
156-
}
157-
return _authCode;
158-
}
119+
public byte[] GetAuthCode() => _authCode ?? (_authCode = _hmacsha1.GetHashAndReset());
159120

160121
#region ICryptoTransform Members
161122

162123
/// <summary>
163-
/// Not implemented.
124+
/// Transform final block and read auth code
164125
/// </summary>
165126
public byte[] TransformFinalBlock(byte[] inputBuffer, int inputOffset, int inputCount)
166127
{
167-
if (inputCount > 0)
168-
{
169-
throw new NotImplementedException("TransformFinalBlock is not implemented and inputCount is greater than 0");
128+
var buffer = Array.Empty<byte>();
129+
130+
// FIXME: When used together with `ZipAESStream`, the final block handling is done inside of it instead
131+
// This should not be necessary anymore, and the entire `ZipAESStream` class should be replaced with a plain `CryptoStream`
132+
if (inputCount != 0) {
133+
if (inputCount > ZipAESStream.AUTH_CODE_LENGTH)
134+
{
135+
// At least one byte of data is preceeding the auth code
136+
int finalBlock = inputCount - ZipAESStream.AUTH_CODE_LENGTH;
137+
buffer = new byte[finalBlock];
138+
TransformBlock(inputBuffer, inputOffset, finalBlock, buffer, 0);
139+
}
140+
else if (inputCount < ZipAESStream.AUTH_CODE_LENGTH)
141+
throw new Zip.ZipException("Auth code missing from input stream");
142+
143+
// Read the authcode from the last 10 bytes
144+
_authCode = _hmacsha1.GetHashAndReset();
170145
}
171-
return Empty.Array<byte>();
146+
147+
148+
return buffer;
172149
}
173150

174151
/// <summary>
175152
/// Gets the size of the input data blocks in bytes.
176153
/// </summary>
177-
public int InputBlockSize
178-
{
179-
get
180-
{
181-
return _blockSize;
182-
}
183-
}
154+
public int InputBlockSize => _blockSize;
184155

185156
/// <summary>
186157
/// Gets the size of the output data blocks in bytes.
187158
/// </summary>
188-
public int OutputBlockSize
189-
{
190-
get
191-
{
192-
return _blockSize;
193-
}
194-
}
159+
public int OutputBlockSize => _blockSize;
195160

196161
/// <summary>
197162
/// Gets a value indicating whether multiple blocks can be transformed.
198163
/// </summary>
199-
public bool CanTransformMultipleBlocks
200-
{
201-
get
202-
{
203-
return true;
204-
}
205-
}
164+
public bool CanTransformMultipleBlocks => true;
206165

207166
/// <summary>
208167
/// Gets a value indicating whether the current transform can be reused.
209168
/// </summary>
210-
public bool CanReuseTransform
211-
{
212-
get
213-
{
214-
return true;
215-
}
216-
}
169+
public bool CanReuseTransform => true;
217170

218171
/// <summary>
219172
/// Cleanup internal state.
220173
/// </summary>
221-
public void Dispose()
222-
{
223-
_encryptor.Dispose();
224-
}
174+
public void Dispose() => _encryptor.Dispose();
225175

226176
#endregion ICryptoTransform Members
227177
}

src/ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib.csproj

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>netstandard2.0;netstandard2.1;net45</TargetFrameworks>
5-
<SignAssembly>True</SignAssembly>
4+
<TargetFrameworks>netstandard2.0;netstandard2.1;net6.0</TargetFrameworks>
5+
<IsTrimmable>true</IsTrimmable>
6+
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
7+
<SignAssembly>true</SignAssembly>
68
<AssemblyOriginatorKeyFile>../../assets/ICSharpCode.SharpZipLib.snk</AssemblyOriginatorKeyFile>
79
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
810
<GenerateDocumentationFile>true</GenerateDocumentationFile>
@@ -11,8 +13,8 @@
1113

1214
<!-- Nuget specific tags -->
1315
<PropertyGroup>
14-
<Version>1.3.3</Version>
15-
<FileVersion>$(Version).11</FileVersion>
16+
<Version>1.4.0</Version>
17+
<FileVersion>$(Version).12</FileVersion>
1618
<AssemblyVersion>$(FileVersion)</AssemblyVersion>
1719
<PackageId>SharpZipLib</PackageId>
1820
<Company>ICSharpCode</Company>
@@ -22,23 +24,18 @@
2224
<PackageProjectUrl>http://icsharpcode.github.io/SharpZipLib/</PackageProjectUrl>
2325
<PackageIcon>images/sharpziplib-nuget-256x256.png</PackageIcon>
2426
<RepositoryUrl>https://github.com/icsharpcode/SharpZipLib</RepositoryUrl>
25-
<Copyright>Copyright © 2000-2021 SharpZipLib Contributors</Copyright>
27+
<Copyright>Copyright © 2000-2022 SharpZipLib Contributors</Copyright>
2628
<PackageTags>Compression Library Zip GZip BZip2 LZW Tar</PackageTags>
2729
<NeutralLanguage>en-US</NeutralLanguage>
2830
<PackageReleaseNotes>
29-
Please see https://github.com/icsharpcode/SharpZipLib/wiki/Release-1.3.3 for more information.</PackageReleaseNotes>
31+
Please see https://github.com/icsharpcode/SharpZipLib/wiki/Release-1.4.0 for more information.</PackageReleaseNotes>
3032
<PackageProjectUrl>https://github.com/icsharpcode/SharpZipLib</PackageProjectUrl>
3133
</PropertyGroup>
3234

3335
<ItemGroup>
3436
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
3537
</ItemGroup>
3638

37-
<ItemGroup Condition=" '$(TargetFramework)' == 'net45' ">
38-
<PackageReference Include="System.Memory" Version="4.5.4" />
39-
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.2" />
40-
</ItemGroup>
41-
4239
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
4340
<PackageReference Include="System.Memory" Version="4.5.4" />
4441
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.2" />

test/ICSharpCode.SharpZipLib.Tests/ICSharpCode.SharpZipLib.Tests.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Library</OutputType>
5-
<TargetFrameworks>netcoreapp3.1;net46</TargetFrameworks>
5+
<TargetFrameworks>net6.0;net462</TargetFrameworks>
66
<ApplicationIcon />
77
<StartupObject />
88
<SignAssembly>true</SignAssembly>
@@ -13,9 +13,9 @@
1313

1414
<ItemGroup>
1515
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.1" />
16-
<PackageReference Include="nunit" Version="3.13.1" />
17-
<PackageReference Include="nunit.console" Version="3.12.0" />
18-
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
16+
<PackageReference Include="nunit" Version="3.13.3" />
17+
<PackageReference Include="nunit.console" Version="3.15.0" />
18+
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
1919
<PackageReference Include="System.Text.Encoding.CodePages" Version="4.4.0" />
2020
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
2121
</ItemGroup>

0 commit comments

Comments
 (0)