From 2e888501d641ef7c04b1a4647f8c497ca2e7ab40 Mon Sep 17 00:00:00 2001 From: zzz Date: Sat, 2 Dec 2017 14:28:03 +0000 Subject: [PATCH] Core tests: Remove or suppress deprecation warnings Remove unchecked warnings Fix HMACSHA256Test and HMACSHA256Bench? --- core/java/src/net/i2p/data/Lease.java | 4 ---- .../test/junit/net/i2p/crypto/AES256Test.java | 1 + .../test/junit/net/i2p/crypto/ElGamalTest.java | 12 ++++++------ .../junit/net/i2p/crypto/HMACSHA256Bench.java | 17 +++++++++-------- .../junit/net/i2p/crypto/HMACSHA256Test.java | 3 ++- .../test/junit/net/i2p/data/BooleanTest.java | 3 ++- .../test/junit/net/i2p/data/DataHelperTest.java | 1 + .../junit/net/i2p/kademlia/KBucketSetTest.java | 2 +- .../junit/net/i2p/stat/SimpleStatDumper.java | 3 ++- 9 files changed, 24 insertions(+), 22 deletions(-) diff --git a/core/java/src/net/i2p/data/Lease.java b/core/java/src/net/i2p/data/Lease.java index 93be652fd..562dd9417 100644 --- a/core/java/src/net/i2p/data/Lease.java +++ b/core/java/src/net/i2p/data/Lease.java @@ -72,7 +72,6 @@ public class Lease extends DataStructureImpl { * Transient attribute of the lease, used to note how many times messages sent * to the destination through the current lease were successful. * - * @deprecated unused */ /**** public int getNumSuccess() { @@ -80,7 +79,6 @@ public class Lease extends DataStructureImpl { } ****/ - /** @deprecated unused */ /**** public void setNumSuccess(int num) { _numSuccess = num; @@ -91,7 +89,6 @@ public class Lease extends DataStructureImpl { * Transient attribute of the lease, used to note how many times messages sent * to the destination through the current lease failed. * - * @deprecated unused */ /**** public int getNumFailure() { @@ -99,7 +96,6 @@ public class Lease extends DataStructureImpl { } ****/ - /** @deprecated unused */ /**** public void setNumFailure(int num) { _numFailure = num; diff --git a/core/java/test/junit/net/i2p/crypto/AES256Test.java b/core/java/test/junit/net/i2p/crypto/AES256Test.java index eae3a0ec9..9ed4ccef6 100644 --- a/core/java/test/junit/net/i2p/crypto/AES256Test.java +++ b/core/java/test/junit/net/i2p/crypto/AES256Test.java @@ -45,6 +45,7 @@ public class AES256Test extends TestCase{ } } + @SuppressWarnings("deprecation") public void testLong(){ I2PAppContext ctx = new I2PAppContext(); SessionKey key = ctx.keyGenerator().generateSessionKey(); diff --git a/core/java/test/junit/net/i2p/crypto/ElGamalTest.java b/core/java/test/junit/net/i2p/crypto/ElGamalTest.java index 46b5da7b6..912b6636e 100644 --- a/core/java/test/junit/net/i2p/crypto/ElGamalTest.java +++ b/core/java/test/junit/net/i2p/crypto/ElGamalTest.java @@ -180,10 +180,10 @@ public class ElGamalTest extends TestCase{ SessionKey key = _context.sessionKeyManager().getCurrentKey(pubKey); if (key == null) key = _context.sessionKeyManager().createSession(pubKey); - byte[] encrypted = _context.elGamalAESEngine().encrypt(DataHelper.getASCII(msg), pubKey, key, 64); + byte[] encrypted = _context.elGamalAESEngine().encrypt(DataHelper.getASCII(msg), pubKey, key, null, null, 64); byte[] decrypted = null; try{ - decrypted = _context.elGamalAESEngine().decrypt(encrypted, privKey); + decrypted = _context.elGamalAESEngine().decrypt(encrypted, privKey, _context.sessionKeyManager()); }catch(DataFormatException dfe){ dfe.printStackTrace(); fail(); @@ -267,10 +267,10 @@ public class ElGamalTest extends TestCase{ if (key == null) key = _context.sessionKeyManager().createSession(pubKey); - byte[] encrypted = _context.elGamalAESEngine().encrypt(msg, pubKey, key, 1024); + byte[] encrypted = _context.elGamalAESEngine().encrypt(msg, pubKey, key, null, null, 1024); byte[] decrypted = null; try{ - decrypted = _context.elGamalAESEngine().decrypt(encrypted, privKey); + decrypted = _context.elGamalAESEngine().decrypt(encrypted, privKey, _context.sessionKeyManager()); }catch(DataFormatException dfe){ dfe.printStackTrace(); fail(); @@ -343,8 +343,8 @@ public class ElGamalTest extends TestCase{ for (int j = 0; j < 5; j++) tags.add(new SessionTag(true)); } - byte encrypted[] = e.encrypt(DataHelper.getASCII("blah"), pubKey, sessionKey, tags, 1024); - byte decrypted[] = e.decrypt(encrypted, privKey); + byte encrypted[] = e.encrypt(DataHelper.getASCII("blah"), pubKey, sessionKey, tags, null, 1024); + byte decrypted[] = e.decrypt(encrypted, privKey, _context.sessionKeyManager()); assertEquals("blah", new String(decrypted)); ctx.sessionKeyManager().tagsDelivered(pubKey, sessionKey, tags); diff --git a/core/java/test/junit/net/i2p/crypto/HMACSHA256Bench.java b/core/java/test/junit/net/i2p/crypto/HMACSHA256Bench.java index dd5ff0b9e..ade938766 100644 --- a/core/java/test/junit/net/i2p/crypto/HMACSHA256Bench.java +++ b/core/java/test/junit/net/i2p/crypto/HMACSHA256Bench.java @@ -47,7 +47,8 @@ public class HMACSHA256Bench { } private static void runTest(I2PAppContext ctx) { SessionKey key = ctx.keyGenerator().generateSessionKey(); - Hash asdfs = ctx.hmac().calculate(key, "qwerty".getBytes()); + byte[] output = new byte[32]; + ctx.hmac().calculate(key, "qwerty".getBytes(), 0, 6, output, 0); int times = 100000; long shorttime = 0; @@ -70,7 +71,7 @@ public class HMACSHA256Bench { long minLong1 = 0; long maxLong1 = 0; - byte[] smess = new String("abc").getBytes(); + byte[] smess = "abc".getBytes(); StringBuilder buf = new StringBuilder(); for (int x = 0; x < 2*1024; x++) { buf.append("a"); @@ -83,27 +84,27 @@ public class HMACSHA256Bench { byte[] lmess = DataHelper.getASCII(buf.toString()); // warm up the engines - ctx.hmac().calculate(key, smess); - ctx.hmac().calculate(key, mmess); - ctx.hmac().calculate(key, lmess); + ctx.hmac().calculate(key, smess, 0, smess.length, output, 0); + ctx.hmac().calculate(key, mmess, 0, mmess.length, output, 0); + ctx.hmac().calculate(key, lmess, 0, lmess.length, output, 0); long before = System.currentTimeMillis(); for (int x = 0; x < times; x++) - ctx.hmac().calculate(key, smess); + ctx.hmac().calculate(key, smess, 0, smess.length, output, 0); long after = System.currentTimeMillis(); display(times, before, after, smess.length, "3 byte"); before = System.currentTimeMillis(); for (int x = 0; x < times; x++) - ctx.hmac().calculate(key, mmess); + ctx.hmac().calculate(key, mmess, 0, mmess.length, output, 0); after = System.currentTimeMillis(); display(times, before, after, mmess.length, "2KB"); before = System.currentTimeMillis(); for (int x = 0; x < times; x++) - ctx.hmac().calculate(key, lmess); + ctx.hmac().calculate(key, lmess, 0, lmess.length, output, 0); after = System.currentTimeMillis(); display(times, before, after, lmess.length, "10KB"); diff --git a/core/java/test/junit/net/i2p/crypto/HMACSHA256Test.java b/core/java/test/junit/net/i2p/crypto/HMACSHA256Test.java index 74bd75453..9d896ecca 100644 --- a/core/java/test/junit/net/i2p/crypto/HMACSHA256Test.java +++ b/core/java/test/junit/net/i2p/crypto/HMACSHA256Test.java @@ -28,7 +28,8 @@ public class HMACSHA256Test extends TestCase{ size*=2; _context.random().nextBytes(message); - _context.hmac().calculate(key, message); + byte[] output = new byte[32]; + _context.hmac().calculate(key, message, 0, message.length, output, 0); } } } diff --git a/core/java/test/junit/net/i2p/data/BooleanTest.java b/core/java/test/junit/net/i2p/data/BooleanTest.java index b5613afa7..b0d449e5e 100644 --- a/core/java/test/junit/net/i2p/data/BooleanTest.java +++ b/core/java/test/junit/net/i2p/data/BooleanTest.java @@ -20,6 +20,7 @@ import junit.framework.TestCase; */ public class BooleanTest extends TestCase{ + @SuppressWarnings("deprecation") public void testBoolean() throws Exception{ byte[] temp = null; @@ -37,4 +38,4 @@ public class BooleanTest extends TestCase{ assertEquals(Boolean.TRUE, b); } -} \ No newline at end of file +} diff --git a/core/java/test/junit/net/i2p/data/DataHelperTest.java b/core/java/test/junit/net/i2p/data/DataHelperTest.java index 4c4c8f18e..ea2d2dd87 100644 --- a/core/java/test/junit/net/i2p/data/DataHelperTest.java +++ b/core/java/test/junit/net/i2p/data/DataHelperTest.java @@ -106,6 +106,7 @@ public class DataHelperTest extends TestCase{ assertTrue(error); } + @SuppressWarnings("deprecation") private void checkDate(Date when) throws Exception{ byte buf[] = new byte[DataHelper.DATE_LENGTH]; DataHelper.toDate(buf, 0, when.getTime()); diff --git a/core/java/test/junit/net/i2p/kademlia/KBucketSetTest.java b/core/java/test/junit/net/i2p/kademlia/KBucketSetTest.java index 1be61d44e..efaa4fc08 100644 --- a/core/java/test/junit/net/i2p/kademlia/KBucketSetTest.java +++ b/core/java/test/junit/net/i2p/kademlia/KBucketSetTest.java @@ -129,7 +129,7 @@ public class KBucketSetTest extends TestCase{ /** @since 0.9.10 */ public void testGenRandom() { int errors = 0; - for (KBucket b : set.getBuckets()) { + for (KBucket b : set.getBuckets()) { for (int j = 0; j < 4000; j++) { Hash rand = set.generateRandomKey(b); int range = set.getRange(rand); diff --git a/core/java/test/junit/net/i2p/stat/SimpleStatDumper.java b/core/java/test/junit/net/i2p/stat/SimpleStatDumper.java index 889820477..cb84ebcb5 100644 --- a/core/java/test/junit/net/i2p/stat/SimpleStatDumper.java +++ b/core/java/test/junit/net/i2p/stat/SimpleStatDumper.java @@ -19,6 +19,7 @@ public class SimpleStatDumper { _log.log(logLevel, buf.toString()); } + @SuppressWarnings("deprecation") private static void dumpFrequencies(I2PAppContext ctx, StringBuilder buf) { Set frequencies = new TreeSet(ctx.statManager().getFrequencyNames()); for (String name : frequencies) { @@ -59,4 +60,4 @@ public class SimpleStatDumper { static void dumpRate(Rate curRate, StringBuilder buf) { buf.append(curRate.toString()); } -} \ No newline at end of file +}