package p.packer.repositories;

import p.packer.models.PackerFileProbe;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.HexFormat;

final class PackerFileFingerprint {
    private PackerFileFingerprint() {
    }

    static String sha256(final PackerFileProbe fileProbe) {
        try {
            final MessageDigest digest = MessageDigest.getInstance("SHA-256");
            return HexFormat.of().formatHex(digest.digest(fileProbe.content()));
        } catch (NoSuchAlgorithmException exception) {
            throw new IllegalStateException("SHA-256 fingerprint is unavailable", exception);
        }
    }
}
