@@ -15,6 +15,9 @@ describe("method - zipcrypto decrypt", () => {
15
15
md5 : "wYHjota6dQNazueWO9/uDg==" ,
16
16
pwdok : "secret" ,
17
17
pwdbad : "Secret" ,
18
+ flagsencrypted : 0x01 ,
19
+ flagsinfozipencrypted : 0x09 ,
20
+ timeHighByte : 0xD8 ,
18
21
// result
19
22
result : Buffer . from ( "test" , "ascii" )
20
23
} ;
@@ -40,22 +43,33 @@ describe("method - zipcrypto decrypt", () => {
40
43
// is error thrown if invalid password was provided
41
44
it ( "should throw if invalid password is provided" , ( ) => {
42
45
expect ( function badpassword ( ) {
43
- decrypt ( source . data , { crc : source . crc } , source . pwdbad ) ;
46
+ decrypt ( source . data , { crc : source . crc , flags : source . flagsencrypted } , source . pwdbad ) ;
44
47
} ) . to . throw ( ) ;
45
48
46
49
expect ( function okpassword ( ) {
47
- decrypt ( source . data , { crc : source . crc } , source . pwdok ) ;
50
+ decrypt ( source . data , { crc : source . crc , flags : source . flagsencrypted } , source . pwdok ) ;
51
+ } ) . to . not . throw ( ) ;
52
+ } ) ;
53
+
54
+ // is error thrown if invalid password was provided
55
+ it ( "should throw if invalid password is provided for Info-Zip bit 3 flag" , ( ) => {
56
+ expect ( function badpassword ( ) {
57
+ decrypt ( source . data , { crc : source . crc , flags : source . flagsinfozipencrypted , timeHighByte : source . timeHighByte } , source . pwdbad ) ;
58
+ } ) . to . throw ( ) ;
59
+
60
+ expect ( function okpassword ( ) {
61
+ decrypt ( source . data , { crc : source . crc , flags : source . flagsinfozipencrypted , timeHighByte : source . timeHighByte } , source . pwdok ) ;
48
62
} ) . to . not . throw ( ) ;
49
63
} ) ;
50
64
51
65
// test decryption with both password types
52
66
it ( "test decrypted data with password" , ( ) => {
53
67
// test password, string
54
- const result1 = decrypt ( source . data , { crc : source . crc } , source . pwdok ) ;
68
+ const result1 = decrypt ( source . data , { crc : source . crc , flags : source . flagsencrypted } , source . pwdok ) ;
55
69
expect ( result1 . compare ( source . result ) ) . to . equal ( 0 ) ;
56
70
57
71
// test password, buffer
58
- const result2 = decrypt ( source . data , { crc : source . crc } , Buffer . from ( source . pwdok , "ascii" ) ) ;
72
+ const result2 = decrypt ( source . data , { crc : source . crc , flags : source . flagsencrypted } , Buffer . from ( source . pwdok , "ascii" ) ) ;
59
73
expect ( result2 . compare ( source . result ) ) . to . equal ( 0 ) ;
60
74
} ) ;
61
75
} ) ;
0 commit comments