File tree Expand file tree Collapse file tree 2 files changed +15
-0
lines changed
Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Original file line number Diff line number Diff line change 44import java .security .NoSuchAlgorithmException ;
55
66public class Hasher {
7+ public boolean matches (byte [] input , String hash ) {
8+ return getHash (input ).equals (hash );
9+ }
10+
711 public String getHash (byte [] input ) {
812 MessageDigest messageDigest = null ;
913 try {
Original file line number Diff line number Diff line change @@ -12,4 +12,15 @@ public void returnsHashForBytes() throws Exception {
1212 assertEquals ("dc50a0d27dda2eee9f65644cd7e4c9cf11de8bec" ,
1313 hasher .getHash (input ));
1414 }
15+
16+ @ Test
17+ public void matchesBytesToHash () throws Exception {
18+ Hasher hasher = new Hasher ();
19+ byte [] input = "default content" .getBytes ();
20+ String hash = "dc50a0d27dda2eee9f65644cd7e4c9cf11de8bec" ;
21+ String bad_hash = "5c36acad75b78b82be6d9cbbd6143ab7e0cc04b0" ;
22+
23+ assertTrue (hasher .matches (input , hash ));
24+ assertFalse (hasher .matches (input , bad_hash ));
25+ }
1526}
You can’t perform that action at this time.
0 commit comments