Core tests: Remove or suppress deprecation warnings

Remove unchecked warnings
Fix HMACSHA256Test and HMACSHA256Bench?
This commit is contained in:
zzz
2017-12-02 14:28:03 +00:00
parent e6f17ec1ab
commit 2e888501d6
9 changed files with 24 additions and 22 deletions

View File

@ -72,7 +72,6 @@ public class Lease extends DataStructureImpl {
* Transient attribute of the lease, used to note how many times messages sent * Transient attribute of the lease, used to note how many times messages sent
* to the destination through the current lease were successful. * to the destination through the current lease were successful.
* *
* @deprecated unused
*/ */
/**** /****
public int getNumSuccess() { public int getNumSuccess() {
@ -80,7 +79,6 @@ public class Lease extends DataStructureImpl {
} }
****/ ****/
/** @deprecated unused */
/**** /****
public void setNumSuccess(int num) { public void setNumSuccess(int num) {
_numSuccess = 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 * Transient attribute of the lease, used to note how many times messages sent
* to the destination through the current lease failed. * to the destination through the current lease failed.
* *
* @deprecated unused
*/ */
/**** /****
public int getNumFailure() { public int getNumFailure() {
@ -99,7 +96,6 @@ public class Lease extends DataStructureImpl {
} }
****/ ****/
/** @deprecated unused */
/**** /****
public void setNumFailure(int num) { public void setNumFailure(int num) {
_numFailure = num; _numFailure = num;

View File

@ -45,6 +45,7 @@ public class AES256Test extends TestCase{
} }
} }
@SuppressWarnings("deprecation")
public void testLong(){ public void testLong(){
I2PAppContext ctx = new I2PAppContext(); I2PAppContext ctx = new I2PAppContext();
SessionKey key = ctx.keyGenerator().generateSessionKey(); SessionKey key = ctx.keyGenerator().generateSessionKey();

View File

@ -180,10 +180,10 @@ public class ElGamalTest extends TestCase{
SessionKey key = _context.sessionKeyManager().getCurrentKey(pubKey); SessionKey key = _context.sessionKeyManager().getCurrentKey(pubKey);
if (key == null) if (key == null)
key = _context.sessionKeyManager().createSession(pubKey); 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; byte[] decrypted = null;
try{ try{
decrypted = _context.elGamalAESEngine().decrypt(encrypted, privKey); decrypted = _context.elGamalAESEngine().decrypt(encrypted, privKey, _context.sessionKeyManager());
}catch(DataFormatException dfe){ }catch(DataFormatException dfe){
dfe.printStackTrace(); dfe.printStackTrace();
fail(); fail();
@ -267,10 +267,10 @@ public class ElGamalTest extends TestCase{
if (key == null) if (key == null)
key = _context.sessionKeyManager().createSession(pubKey); 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; byte[] decrypted = null;
try{ try{
decrypted = _context.elGamalAESEngine().decrypt(encrypted, privKey); decrypted = _context.elGamalAESEngine().decrypt(encrypted, privKey, _context.sessionKeyManager());
}catch(DataFormatException dfe){ }catch(DataFormatException dfe){
dfe.printStackTrace(); dfe.printStackTrace();
fail(); fail();
@ -343,8 +343,8 @@ public class ElGamalTest extends TestCase{
for (int j = 0; j < 5; j++) for (int j = 0; j < 5; j++)
tags.add(new SessionTag(true)); tags.add(new SessionTag(true));
} }
byte encrypted[] = e.encrypt(DataHelper.getASCII("blah"), pubKey, sessionKey, tags, 1024); byte encrypted[] = e.encrypt(DataHelper.getASCII("blah"), pubKey, sessionKey, tags, null, 1024);
byte decrypted[] = e.decrypt(encrypted, privKey); byte decrypted[] = e.decrypt(encrypted, privKey, _context.sessionKeyManager());
assertEquals("blah", new String(decrypted)); assertEquals("blah", new String(decrypted));
ctx.sessionKeyManager().tagsDelivered(pubKey, sessionKey, tags); ctx.sessionKeyManager().tagsDelivered(pubKey, sessionKey, tags);

View File

@ -47,7 +47,8 @@ public class HMACSHA256Bench {
} }
private static void runTest(I2PAppContext ctx) { private static void runTest(I2PAppContext ctx) {
SessionKey key = ctx.keyGenerator().generateSessionKey(); 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; int times = 100000;
long shorttime = 0; long shorttime = 0;
@ -70,7 +71,7 @@ public class HMACSHA256Bench {
long minLong1 = 0; long minLong1 = 0;
long maxLong1 = 0; long maxLong1 = 0;
byte[] smess = new String("abc").getBytes(); byte[] smess = "abc".getBytes();
StringBuilder buf = new StringBuilder(); StringBuilder buf = new StringBuilder();
for (int x = 0; x < 2*1024; x++) { for (int x = 0; x < 2*1024; x++) {
buf.append("a"); buf.append("a");
@ -83,27 +84,27 @@ public class HMACSHA256Bench {
byte[] lmess = DataHelper.getASCII(buf.toString()); byte[] lmess = DataHelper.getASCII(buf.toString());
// warm up the engines // warm up the engines
ctx.hmac().calculate(key, smess); ctx.hmac().calculate(key, smess, 0, smess.length, output, 0);
ctx.hmac().calculate(key, mmess); ctx.hmac().calculate(key, mmess, 0, mmess.length, output, 0);
ctx.hmac().calculate(key, lmess); ctx.hmac().calculate(key, lmess, 0, lmess.length, output, 0);
long before = System.currentTimeMillis(); long before = System.currentTimeMillis();
for (int x = 0; x < times; x++) 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(); long after = System.currentTimeMillis();
display(times, before, after, smess.length, "3 byte"); display(times, before, after, smess.length, "3 byte");
before = System.currentTimeMillis(); before = System.currentTimeMillis();
for (int x = 0; x < times; x++) 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(); after = System.currentTimeMillis();
display(times, before, after, mmess.length, "2KB"); display(times, before, after, mmess.length, "2KB");
before = System.currentTimeMillis(); before = System.currentTimeMillis();
for (int x = 0; x < times; x++) 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(); after = System.currentTimeMillis();
display(times, before, after, lmess.length, "10KB"); display(times, before, after, lmess.length, "10KB");

View File

@ -28,7 +28,8 @@ public class HMACSHA256Test extends TestCase{
size*=2; size*=2;
_context.random().nextBytes(message); _context.random().nextBytes(message);
_context.hmac().calculate(key, message); byte[] output = new byte[32];
_context.hmac().calculate(key, message, 0, message.length, output, 0);
} }
} }
} }

View File

@ -20,6 +20,7 @@ import junit.framework.TestCase;
*/ */
public class BooleanTest extends TestCase{ public class BooleanTest extends TestCase{
@SuppressWarnings("deprecation")
public void testBoolean() throws Exception{ public void testBoolean() throws Exception{
byte[] temp = null; byte[] temp = null;
@ -37,4 +38,4 @@ public class BooleanTest extends TestCase{
assertEquals(Boolean.TRUE, b); assertEquals(Boolean.TRUE, b);
} }
} }

View File

@ -106,6 +106,7 @@ public class DataHelperTest extends TestCase{
assertTrue(error); assertTrue(error);
} }
@SuppressWarnings("deprecation")
private void checkDate(Date when) throws Exception{ private void checkDate(Date when) throws Exception{
byte buf[] = new byte[DataHelper.DATE_LENGTH]; byte buf[] = new byte[DataHelper.DATE_LENGTH];
DataHelper.toDate(buf, 0, when.getTime()); DataHelper.toDate(buf, 0, when.getTime());

View File

@ -129,7 +129,7 @@ public class KBucketSetTest extends TestCase{
/** @since 0.9.10 */ /** @since 0.9.10 */
public void testGenRandom() { public void testGenRandom() {
int errors = 0; int errors = 0;
for (KBucket b : set.getBuckets()) { for (KBucket<Hash> b : set.getBuckets()) {
for (int j = 0; j < 4000; j++) { for (int j = 0; j < 4000; j++) {
Hash rand = set.generateRandomKey(b); Hash rand = set.generateRandomKey(b);
int range = set.getRange(rand); int range = set.getRange(rand);

View File

@ -19,6 +19,7 @@ public class SimpleStatDumper {
_log.log(logLevel, buf.toString()); _log.log(logLevel, buf.toString());
} }
@SuppressWarnings("deprecation")
private static void dumpFrequencies(I2PAppContext ctx, StringBuilder buf) { private static void dumpFrequencies(I2PAppContext ctx, StringBuilder buf) {
Set<String> frequencies = new TreeSet<String>(ctx.statManager().getFrequencyNames()); Set<String> frequencies = new TreeSet<String>(ctx.statManager().getFrequencyNames());
for (String name : frequencies) { for (String name : frequencies) {
@ -59,4 +60,4 @@ public class SimpleStatDumper {
static void dumpRate(Rate curRate, StringBuilder buf) { static void dumpRate(Rate curRate, StringBuilder buf) {
buf.append(curRate.toString()); buf.append(curRate.toString());
} }
} }