mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 22:11:36 -05:00
refactor: use HexFormat for digest encoding (#772)
This commit is contained in:
1 parent
15db990b39
commit
c87abb082e
2 files changed
+7
-12
No files matched your search
@@ -29,6 +29,7 @@ import java.time.Instant;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HexFormat;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
@@ -51,7 +52,8 @@ public class SnsService {
|
||||
private final String baseUrl;
|
||||
private final ObjectMapper objectMapper;
|
||||
private final Map<String, Instant> fifoDeduplicationCache = new ConcurrentHashMap<>();
|
||||
|
||||
private static final HexFormat HEX = HexFormat.of();
|
||||
|
||||
@Inject
|
||||
public SnsService(StorageFactory storageFactory, EmulatorConfig config,
|
||||
RegionResolver regionResolver, SqsService sqsService,
|
||||
@@ -768,13 +770,9 @@ public class SnsService {
|
||||
|
||||
private static String sha256(String message) {
|
||||
try {
|
||||
MessageDigest md = MessageDigest.getInstance("SHA-256");
|
||||
MessageDigest md = MessageDigest.getInstance("SHA-256");
|
||||
byte[] hash = md.digest(message.getBytes(StandardCharsets.UTF_8));
|
||||
var sb = new StringBuilder();
|
||||
for (byte b : hash) {
|
||||
sb.append(String.format("%02x", b));
|
||||
}
|
||||
return sb.toString();
|
||||
return HEX.formatHex(hash);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
return UUID.randomUUID().toString();
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ public class SqsService {
|
||||
private final ConcurrentHashMap<String, RedrivePolicy> redrivePolicyCache = new ConcurrentHashMap<>();
|
||||
private final ConcurrentHashMap<String, ConcurrentHashMap<String, Instant>> deduplicationCache = new ConcurrentHashMap<>();
|
||||
private final AtomicLong sequenceCounter = new AtomicLong(0);
|
||||
private static final HexFormat HEX = HexFormat.of();
|
||||
|
||||
private record RedrivePolicy(int maxReceiveCount, String deadLetterTargetArn) {
|
||||
}
|
||||
@@ -483,11 +484,7 @@ public class SqsService {
|
||||
try {
|
||||
var md = java.security.MessageDigest.getInstance("MD5");
|
||||
byte[] digest = md.digest(input.getBytes(java.nio.charset.StandardCharsets.UTF_8));
|
||||
var sb = new StringBuilder();
|
||||
for (byte b : digest) {
|
||||
sb.append(String.format("%02x", b));
|
||||
}
|
||||
return sb.toString();
|
||||
return HEX.formatHex(digest);
|
||||
} catch (java.security.NoSuchAlgorithmException e) {
|
||||
return "";
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user