Skip to content

Commit 83f3b64

Browse files
committed
Change hasher interface
1 parent 63129ae commit 83f3b64

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/main/java/httpserver/Hasher.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
import java.security.NoSuchAlgorithmException;
55

66
public 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 {

src/test/java/httpserver/HasherTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)