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

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

View File

@ -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);

View File

@ -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");

View File

@ -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);
}
}
}

View File

@ -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);
}
}
}

View File

@ -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());

View File

@ -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<Hash> b : set.getBuckets()) {
for (int j = 0; j < 4000; j++) {
Hash rand = set.generateRandomKey(b);
int range = set.getRange(rand);

View File

@ -19,6 +19,7 @@ public class SimpleStatDumper {
_log.log(logLevel, buf.toString());
}
@SuppressWarnings("deprecation")
private static void dumpFrequencies(I2PAppContext ctx, StringBuilder buf) {
Set<String> frequencies = new TreeSet<String>(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());
}
}
}