File tree Expand file tree Collapse file tree
src/test/java/org/apache/commons/codec/digest Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1616 */
1717package org .apache .commons .codec .digest ;
1818
19+ import static org .junit .jupiter .api .Assertions .assertArrayEquals ;
1920import static org .junit .jupiter .api .Assertions .assertEquals ;
2021import static org .junit .jupiter .api .Assertions .assertNotNull ;
2122import static org .junit .jupiter .api .Assertions .assertThrows ;
2223import static org .junit .jupiter .api .Assertions .assertTrue ;
2324
2425import java .nio .charset .StandardCharsets ;
26+ import java .util .Arrays ;
2527import java .util .concurrent .ThreadLocalRandom ;
2628
2729import org .junit .jupiter .api .Test ;
@@ -83,4 +85,14 @@ public void testMd5CryptNullData() {
8385 public void testMd5CryptWithEmptySalt () {
8486 assertThrows (IllegalArgumentException .class , () -> Md5Crypt .md5Crypt ("secret" .getBytes (), "" ));
8587 }
88+
89+ @ Test
90+ public void testZeroOutInput () {
91+ final byte [] buffer = new byte [200 ];
92+ Arrays .fill (buffer , (byte ) 'A' );
93+ Md5Crypt .md5Crypt (buffer );
94+ // input password is 0-filled on return
95+ assertArrayEquals (new byte [buffer .length ], buffer );
96+ }
97+
8698}
Original file line number Diff line number Diff line change @@ -93,4 +93,14 @@ public void testSha256LargestThanBlocksize() {
9393 // input password is 0-filled on return
9494 assertArrayEquals (new byte [buffer .length ], buffer );
9595 }
96+
97+ @ Test
98+ public void testZeroOutInput () {
99+ final byte [] buffer = new byte [200 ];
100+ Arrays .fill (buffer , (byte ) 'A' );
101+ Sha2Crypt .sha256Crypt (buffer );
102+ // input password is 0-filled on return
103+ assertArrayEquals (new byte [buffer .length ], buffer );
104+ }
105+
96106}
Original file line number Diff line number Diff line change @@ -102,4 +102,14 @@ public void testSha256LargetThanBlocksize() {
102102 // input password is 0-filled on return
103103 assertArrayEquals (new byte [buffer .length ], buffer );
104104 }
105+
106+ @ Test
107+ public void testZeroOutInput () {
108+ final byte [] buffer = new byte [200 ];
109+ Arrays .fill (buffer , (byte ) 'A' );
110+ Sha2Crypt .sha512Crypt (buffer );
111+ // input password is 0-filled on return
112+ assertArrayEquals (new byte [buffer .length ], buffer );
113+ }
114+
105115}
You can’t perform that action at this time.
0 commit comments