Skip to content

Commit e76dc02

Browse files
committed
allow legacy usage of ZipAESTransform
1 parent 9f5f656 commit e76dc02

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

src/ICSharpCode.SharpZipLib/Encryption/ZipAESTransform.cs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -126,18 +126,24 @@ public int TransformBlock(byte[] inputBuffer, int inputOffset, int inputCount, b
126126
public byte[] TransformFinalBlock(byte[] inputBuffer, int inputOffset, int inputCount)
127127
{
128128
var buffer = Array.Empty<byte>();
129-
if (inputCount > ZipAESStream.AUTH_CODE_LENGTH)
130-
{
131-
// At least one byte of data is preceeding the auth code
132-
int finalBlock = inputCount - ZipAESStream.AUTH_CODE_LENGTH;
133-
buffer = new byte[finalBlock];
134-
TransformBlock(inputBuffer, inputOffset, finalBlock, buffer, 0);
135-
}
136-
else if (inputCount < ZipAESStream.AUTH_CODE_LENGTH)
137-
throw new Zip.ZipException("Auth code missing from input stream");
138129

139-
// Read the authcode from the last 10 bytes
140-
_authCode = _hmacsha1.GetHashAndReset();
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();
145+
}
146+
141147

142148
return buffer;
143149
}

0 commit comments

Comments
 (0)