@@ -15,6 +15,9 @@ describe("method - zipcrypto decrypt", () => {
1515 md5 : "wYHjota6dQNazueWO9/uDg==" ,
1616 pwdok : "secret" ,
1717 pwdbad : "Secret" ,
18+ flagsencrypted : 0x01 ,
19+ flagsinfozipencrypted : 0x09 ,
20+ timeHighByte : 0xD8 ,
1821 // result
1922 result : Buffer . from ( "test" , "ascii" )
2023 } ;
@@ -40,22 +43,33 @@ describe("method - zipcrypto decrypt", () => {
4043 // is error thrown if invalid password was provided
4144 it ( "should throw if invalid password is provided" , ( ) => {
4245 expect ( function badpassword ( ) {
43- decrypt ( source . data , { crc : source . crc } , source . pwdbad ) ;
46+ decrypt ( source . data , { crc : source . crc , flags : source . flagsencrypted } , source . pwdbad ) ;
4447 } ) . to . throw ( ) ;
4548
4649 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 ) ;
4862 } ) . to . not . throw ( ) ;
4963 } ) ;
5064
5165 // test decryption with both password types
5266 it ( "test decrypted data with password" , ( ) => {
5367 // 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 ) ;
5569 expect ( result1 . compare ( source . result ) ) . to . equal ( 0 ) ;
5670
5771 // 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" ) ) ;
5973 expect ( result2 . compare ( source . result ) ) . to . equal ( 0 ) ;
6074 } ) ;
6175} ) ;
0 commit comments