@@ -1115,7 +1115,7 @@ private long TestLocalHeader(ZipEntry entry, HeaderTest tests)
1115
1115
}
1116
1116
1117
1117
var extractVersion = ( short ) ( ReadLEUshort ( ) & 0x00ff ) ;
1118
- var localFlags = ( short ) ReadLEUshort ( ) ;
1118
+ var localFlags = ( GeneralBitFlags ) ReadLEUshort ( ) ;
1119
1119
var compressionMethod = ( short ) ReadLEUshort ( ) ;
1120
1120
var fileTime = ( short ) ReadLEUshort ( ) ;
1121
1121
var fileDate = ( short ) ReadLEUshort ( ) ;
@@ -1142,15 +1142,15 @@ private long TestLocalHeader(ZipEntry entry, HeaderTest tests)
1142
1142
size = localExtraData . ReadLong ( ) ;
1143
1143
compressedSize = localExtraData . ReadLong ( ) ;
1144
1144
1145
- if ( ( localFlags & ( int ) GeneralBitFlags . Descriptor ) != 0 )
1145
+ if ( localFlags . HasAny ( GeneralBitFlags . Descriptor ) )
1146
1146
{
1147
1147
// These may be valid if patched later
1148
- if ( ( size != - 1 ) && ( size != entry . Size ) )
1148
+ if ( ( size > 0 ) && ( size != entry . Size ) )
1149
1149
{
1150
1150
throw new ZipException ( "Size invalid for descriptor" ) ;
1151
1151
}
1152
1152
1153
- if ( ( compressedSize != - 1 ) && ( compressedSize != entry . CompressedSize ) )
1153
+ if ( ( compressedSize > 0 ) && ( compressedSize != entry . CompressedSize ) )
1154
1154
{
1155
1155
throw new ZipException ( "Compressed size invalid for descriptor" ) ;
1156
1156
}
@@ -1181,7 +1181,7 @@ private long TestLocalHeader(ZipEntry entry, HeaderTest tests)
1181
1181
throw new ZipException ( string . Format ( "Version required to extract this entry not supported ({0})" , extractVersion ) ) ;
1182
1182
}
1183
1183
1184
- if ( ( localFlags & ( int ) ( GeneralBitFlags . Patched | GeneralBitFlags . StrongEncryption | GeneralBitFlags . EnhancedCompress | GeneralBitFlags . HeaderMasked ) ) != 0 )
1184
+ if ( localFlags . HasAny ( GeneralBitFlags . Patched | GeneralBitFlags . StrongEncryption | GeneralBitFlags . EnhancedCompress | GeneralBitFlags . HeaderMasked ) )
1185
1185
{
1186
1186
throw new ZipException ( "The library does not support the zip version required to extract this entry" ) ;
1187
1187
}
@@ -1213,21 +1213,21 @@ private long TestLocalHeader(ZipEntry entry, HeaderTest tests)
1213
1213
var localEncoding = _stringCodec . ZipInputEncoding ( localFlags ) ;
1214
1214
1215
1215
// Local entry flags dont have reserved bit set on.
1216
- if ( ( localFlags & ( int ) ( GeneralBitFlags . ReservedPKware4 | GeneralBitFlags . ReservedPkware14 | GeneralBitFlags . ReservedPkware15 ) ) != 0 )
1216
+ if ( localFlags . HasAny ( GeneralBitFlags . ReservedPKware4 | GeneralBitFlags . ReservedPkware14 | GeneralBitFlags . ReservedPkware15 ) )
1217
1217
{
1218
1218
throw new ZipException ( "Reserved bit flags cannot be set." ) ;
1219
1219
}
1220
1220
1221
1221
// Encryption requires extract version >= 20
1222
- if ( ( ( localFlags & ( int ) GeneralBitFlags . Encrypted ) != 0 ) && ( extractVersion < 20 ) )
1222
+ if ( localFlags . HasAny ( GeneralBitFlags . Encrypted ) && extractVersion < 20 )
1223
1223
{
1224
1224
throw new ZipException ( string . Format ( "Version required to extract this entry is too low for encryption ({0})" , extractVersion ) ) ;
1225
1225
}
1226
1226
1227
1227
// Strong encryption requires encryption flag to be set and extract version >= 50.
1228
- if ( ( localFlags & ( int ) GeneralBitFlags . StrongEncryption ) != 0 )
1228
+ if ( localFlags . HasAny ( GeneralBitFlags . StrongEncryption ) )
1229
1229
{
1230
- if ( ( localFlags & ( int ) GeneralBitFlags . Encrypted ) == 0 )
1230
+ if ( ! localFlags . HasAny ( GeneralBitFlags . Encrypted ) )
1231
1231
{
1232
1232
throw new ZipException ( "Strong encryption flag set but encryption flag is not set" ) ;
1233
1233
}
@@ -1239,13 +1239,13 @@ private long TestLocalHeader(ZipEntry entry, HeaderTest tests)
1239
1239
}
1240
1240
1241
1241
// Patched entries require extract version >= 27
1242
- if ( ( ( localFlags & ( int ) GeneralBitFlags . Patched ) != 0 ) && ( extractVersion < 27 ) )
1242
+ if ( localFlags . HasAny ( GeneralBitFlags . Patched ) && extractVersion < 27 )
1243
1243
{
1244
1244
throw new ZipException ( string . Format ( "Patched data requires higher version than ({0})" , extractVersion ) ) ;
1245
1245
}
1246
1246
1247
1247
// Central header flags match local entry flags.
1248
- if ( localFlags != entry . Flags )
1248
+ if ( ( int ) localFlags != entry . Flags )
1249
1249
{
1250
1250
throw new ZipException ( "Central header/local header flags mismatch" ) ;
1251
1251
}
@@ -1262,23 +1262,23 @@ private long TestLocalHeader(ZipEntry entry, HeaderTest tests)
1262
1262
}
1263
1263
1264
1264
// Strong encryption and extract version match
1265
- if ( ( localFlags & ( int ) GeneralBitFlags . StrongEncryption ) != 0 )
1265
+ if ( localFlags . HasAny ( GeneralBitFlags . StrongEncryption ) )
1266
1266
{
1267
1267
if ( extractVersion < 62 )
1268
1268
{
1269
1269
throw new ZipException ( "Strong encryption flag set but version not high enough" ) ;
1270
1270
}
1271
1271
}
1272
1272
1273
- if ( ( localFlags & ( int ) GeneralBitFlags . HeaderMasked ) != 0 )
1273
+ if ( localFlags . HasAny ( GeneralBitFlags . HeaderMasked ) )
1274
1274
{
1275
1275
if ( ( fileTime != 0 ) || ( fileDate != 0 ) )
1276
1276
{
1277
1277
throw new ZipException ( "Header masked set but date/time values non-zero" ) ;
1278
1278
}
1279
1279
}
1280
1280
1281
- if ( ( localFlags & ( int ) GeneralBitFlags . Descriptor ) == 0 )
1281
+ if ( ! localFlags . HasAny ( GeneralBitFlags . Descriptor ) )
1282
1282
{
1283
1283
if ( crcValue != ( uint ) entry . Crc )
1284
1284
{
@@ -1348,7 +1348,7 @@ private long TestLocalHeader(ZipEntry entry, HeaderTest tests)
1348
1348
1349
1349
// Size can be verified only if it is known in the local header.
1350
1350
// it will always be known in the central header.
1351
- if ( ( ( localFlags & ( int ) GeneralBitFlags . Descriptor ) == 0 ) ||
1351
+ if ( ! localFlags . HasAny ( GeneralBitFlags . Descriptor ) ||
1352
1352
( ( size > 0 || compressedSize > 0 ) && entry . Size > 0 ) )
1353
1353
{
1354
1354
if ( ( size != 0 )
@@ -2507,7 +2507,7 @@ private void CopyBytes(ZipUpdate update, Stream destination, Stream source,
2507
2507
/// <returns>The descriptor size, zero if there isn't one.</returns>
2508
2508
private static int GetDescriptorSize ( ZipUpdate update , bool includingSignature )
2509
2509
{
2510
- if ( ! ( ( GeneralBitFlags ) update . Entry . Flags ) . HasFlag ( GeneralBitFlags . Descriptor ) )
2510
+ if ( ! ( ( GeneralBitFlags ) update . Entry . Flags ) . HasAny ( GeneralBitFlags . Descriptor ) )
2511
2511
return 0 ;
2512
2512
2513
2513
var descriptorWithSignature = update . Entry . LocalHeaderRequiresZip64
0 commit comments