Skip to content

Commit 0af9f15

Browse files
committed
allow legacy usage of ZipAESTransform
1 parent da4baa9 commit 0af9f15

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
@@ -122,18 +122,24 @@ public int TransformBlock(byte[] inputBuffer, int inputOffset, int inputCount, b
122122
public byte[] TransformFinalBlock(byte[] inputBuffer, int inputOffset, int inputCount)
123123
{
124124
var buffer = Array.Empty<byte>();
125-
if (inputCount > ZipAESStream.AUTH_CODE_LENGTH)
126-
{
127-
// At least one byte of data is preceeding the auth code
128-
int finalBlock = inputCount - ZipAESStream.AUTH_CODE_LENGTH;
129-
buffer = new byte[finalBlock];
130-
TransformBlock(inputBuffer, inputOffset, finalBlock, buffer, 0);
131-
}
132-
else if (inputCount < ZipAESStream.AUTH_CODE_LENGTH)
133-
throw new Zip.ZipException("Auth code missing from input stream");
134125

135-
// Read the authcode from the last 10 bytes
136-
_authCode = _hmacsha1.GetHashAndReset();
126+
// FIXME: When used together with `ZipAESStream`, the final block handling is done inside of it instead
127+
// This should not be necessary anymore, and the entire `ZipAESStream` class should be replaced with a plain `CryptoStream`
128+
if (inputCount == 0) {
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");
138+
139+
// Read the authcode from the last 10 bytes
140+
_authCode = _hmacsha1.GetHashAndReset();
141+
}
142+
137143

138144
return buffer;
139145
}

0 commit comments

Comments
 (0)