Skip to content

Commit

Permalink
Implement configurable algorithm with sys prop
Browse files Browse the repository at this point in the history
  • Loading branch information
kusalk committed Dec 24, 2024
1 parent d8d2013 commit 0072fe8
Showing 1 changed file with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,31 @@

public class HashGenerator {

public enum HashAlgorithm {

MURMUR(Murmur::from),
SHA256(Sha256::from),
MD5(Md5::from);

private final Function<String, String> hashFunction;

HashAlgorithm(Function<String, String> hashFunction) {
this.hashFunction = hashFunction;
}

public String hash(String signature) {
return hashFunction.apply(signature);
}
}

public static class DefaultHash {
private static final String SELECTED_ALGORITHM_PROP = "hash.algorithm";
private static final HashAlgorithm DEFAULT_ALGORITHM = HashAlgorithm.MD5;
private static final HashAlgorithm SELECTED_ALGORITHM =
HashAlgorithm.valueOf(System.getProperty(SELECTED_ALGORITHM_PROP, DEFAULT_ALGORITHM.name()).toUpperCase());

public static String from(String signature) {
return Murmur.from(signature);
return SELECTED_ALGORITHM.hash(signature);
}
}

Expand Down

0 comments on commit 0072fe8

Please sign in to comment.