diff --git a/scavenger-model/src/main/java/com/navercorp/scavenger/util/HashGenerator.java b/scavenger-model/src/main/java/com/navercorp/scavenger/util/HashGenerator.java index 82d8295..823275b 100644 --- a/scavenger-model/src/main/java/com/navercorp/scavenger/util/HashGenerator.java +++ b/scavenger-model/src/main/java/com/navercorp/scavenger/util/HashGenerator.java @@ -10,9 +10,31 @@ public class HashGenerator { + public enum HashAlgorithm { + + MURMUR(Murmur::from), + SHA256(Sha256::from), + MD5(Md5::from); + + private final Function hashFunction; + + HashAlgorithm(Function 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); } }