package be.naaturel.boardmateapi.configurations;

import java.io.BufferedInputStream;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.security.MessageDigest;

public class BuildHasher {

    public static String get() throws Exception {
        MessageDigest digest = MessageDigest.getInstance("SHA-256");

        try (InputStream is =
                     BuildHasher.class.getProtectionDomain()
                             .getCodeSource()
                             .getLocation()
                             .openStream()) {

            digest.update(is.readAllBytes());
        }

        byte[] hashBytes = digest.digest();

        StringBuilder hex = new StringBuilder(hashBytes.length * 2);
        for (byte b : hashBytes) hex.append(String.format("%02x", b));
        return hex.toString();
    }

}
