From a7a7e9618872327bb375c8f2cccdee0f85757ab1 Mon Sep 17 00:00:00 2001 From: str4d <str4d@mail.i2p> Date: Wed, 20 Nov 2013 09:15:12 +0000 Subject: [PATCH] Findbugs in imported core code --- .../src/com/nettgryppa/security/HashCash.java | 16 ++++++++++++---- .../src/gnu/crypto/hash/Sha256Standalone.java | 4 ++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/core/java/src/com/nettgryppa/security/HashCash.java b/core/java/src/com/nettgryppa/security/HashCash.java index 56bc35861c..be8d92a471 100644 --- a/core/java/src/com/nettgryppa/security/HashCash.java +++ b/core/java/src/com/nettgryppa/security/HashCash.java @@ -212,7 +212,6 @@ public class HashCash implements Comparable<HashCash> { /** * Two objects are considered equal if they are both of type HashCash and have an identical string representation */ - /* FIXME missing hashCode() method FIXME */ @Override public boolean equals(Object obj) { if(obj instanceof HashCash) @@ -220,6 +219,14 @@ public class HashCash implements Comparable<HashCash> { else return super.equals(obj); } + + /** + * Implemented based on definition of equals() + */ + @Override + public int hashCode() { + return ("HashCash:"+toString()).hashCode(); + } /** * Returns the canonical string representation of the HashCash @@ -330,14 +337,15 @@ private static long bytesToLong(byte[] b) { List<String> tempList; boolean first = true; - for(String key: extensions.keySet()) { + for(Map.Entry<String, List<String>> entry: extensions.entrySet()) { + String key = entry.getKey(); if(key.contains(":") || key.contains(";") || key.contains("=")) throw new IllegalArgumentException("Extension key contains an illegal character. " + key); if(!first) result.append(";"); first = false; result.append(key); - tempList = extensions.get(key); + tempList = entry.getValue(); if(null != tempList) { result.append("="); @@ -442,7 +450,7 @@ private static long bytesToLong(byte[] b) { public static int estimateValue(int secs) throws NoSuchAlgorithmException { initEstimates(); int result = 0; - long millis = secs * 1000 * 65536; + long millis = secs * 1000L * 65536; millis /= milliFor16; while(millis > 1) { diff --git a/core/java/src/gnu/crypto/hash/Sha256Standalone.java b/core/java/src/gnu/crypto/hash/Sha256Standalone.java index cb1e7eaabe..465675cd33 100644 --- a/core/java/src/gnu/crypto/hash/Sha256Standalone.java +++ b/core/java/src/gnu/crypto/hash/Sha256Standalone.java @@ -95,7 +95,7 @@ public class Sha256Standalone extends BaseHashStandalone { private static final int[] w = new int[64]; /** caches the result of the correctness test, once executed. */ - private static Boolean valid; + private static volatile Boolean valid; /** 256-bit interim result. */ private int h0, h1, h2, h3, h4, h5, h6, h7; @@ -218,7 +218,7 @@ public class Sha256Standalone extends BaseHashStandalone { md.update((byte) 0x62); // b md.update((byte) 0x63); // c String result = "broken"; //Util.toString(md.digest()); - valid = new Boolean(DIGEST0.equals(result)); + valid = Boolean.valueOf(DIGEST0.equals(result)); } return valid.booleanValue(); -- GitLab