diff options
author | Amadornes <amadornes@gmail.com> | 2018-08-19 00:17:29 +0200 |
---|---|---|
committer | Amadornes <amadornes@gmail.com> | 2018-08-19 00:17:29 +0200 |
commit | 9109a6fe1b4de3f758be0a5bacf8258313d84ecc (patch) | |
tree | 236d2e75bc604e9f3258a2a4451a1b67fe1d7d11 /src | |
parent | dcf33551be719282d7569e6c0c48011a8275b543 (diff) | |
download | Artifactural-9109a6fe1b4de3f758be0a5bacf8258313d84ecc.tar.gz Artifactural-9109a6fe1b4de3f758be0a5bacf8258313d84ecc.tar.bz2 Artifactural-9109a6fe1b4de3f758be0a5bacf8258313d84ecc.zip |
Fixed artifact metadata hash output
Diffstat (limited to 'src')
-rw-r--r-- | src/shared/java/com/amadornes/artifactural/base/artifact/SimpleArtifactMetadata.java | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/src/shared/java/com/amadornes/artifactural/base/artifact/SimpleArtifactMetadata.java b/src/shared/java/com/amadornes/artifactural/base/artifact/SimpleArtifactMetadata.java index e08cd7b..860a655 100644 --- a/src/shared/java/com/amadornes/artifactural/base/artifact/SimpleArtifactMetadata.java +++ b/src/shared/java/com/amadornes/artifactural/base/artifact/SimpleArtifactMetadata.java @@ -2,16 +2,16 @@ package com.amadornes.artifactural.base.artifact; import com.amadornes.artifactural.api.artifact.ArtifactMetadata; -import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; -import java.util.Base64; import java.util.LinkedList; +import java.util.List; import java.util.stream.Collectors; public class SimpleArtifactMetadata implements ArtifactMetadata { - private final LinkedList<Entry> entries = new LinkedList<>(); + private final List<Entry> entries = new LinkedList<>(); + private String hash = null; public SimpleArtifactMetadata() { } @@ -28,11 +28,16 @@ public class SimpleArtifactMetadata implements ArtifactMetadata { @Override public String getHash() { + if (hash != null) return hash; try { - String str = entries.stream().map(Entry::toString).collect(Collectors.joining(";;")); - MessageDigest digest = MessageDigest.getInstance("SHA-256"); - byte[] hash = digest.digest(str.getBytes(StandardCharsets.UTF_8)); - return Base64.getEncoder().encodeToString(hash); + String str = entries.stream().map(Entry::toString).collect(Collectors.joining("\n")); + MessageDigest digest = MessageDigest.getInstance("SHA-1"); + byte[] hashBytes = digest.digest(str.getBytes()); + StringBuilder hashBuilder = new StringBuilder(); + for (byte b : hashBytes) { + hashBuilder.append(String.format("%02x", b)); + } + return hash = hashBuilder.toString(); } catch (NoSuchAlgorithmException ex) { throw new RuntimeException(ex); } |