From 2246e21340fdbfd1f570c386c1d7f1de53adfb4b Mon Sep 17 00:00:00 2001
From: z3r0fox <z3r0fox@mail.i2p>
Date: Sun, 20 Dec 2015 01:26:33 +0000
Subject: [PATCH] Replaces instances of getBytes() in router classes

---
 .../src/net/i2p/router/MessageHistory.java    |  5 ++--
 .../router/crypto/SessionEncryptionTest.java  | 26 +++++++++----------
 .../crypto/DHSessionKeyBuilderTest.java       |  3 ++-
 3 files changed, 18 insertions(+), 16 deletions(-)

diff --git a/router/java/src/net/i2p/router/MessageHistory.java b/router/java/src/net/i2p/router/MessageHistory.java
index 16403996fb..82d1af9df1 100644
--- a/router/java/src/net/i2p/router/MessageHistory.java
+++ b/router/java/src/net/i2p/router/MessageHistory.java
@@ -10,6 +10,7 @@ import java.util.Queue;
 import java.util.TimeZone;
 import java.util.concurrent.LinkedBlockingQueue;
 
+import net.i2p.data.DataHelper;
 import net.i2p.data.Hash;
 import net.i2p.data.TunnelId;
 import net.i2p.data.i2np.I2NPMessage;
@@ -40,7 +41,7 @@ public class MessageHistory {
     //private SubmitMessageHistoryJob _submitMessageHistoryJob;
     private volatile boolean _firstPass;
     
-    private final static byte[] NL = System.getProperty("line.separator").getBytes();
+    private final static byte[] NL = DataHelper.getUTF8(System.getProperty("line.separator"));
     private final static int FLUSH_SIZE = 1000; // write out at least once every 1000 entries
         
     /** config property determining whether we want to debug with the message history - default false */
@@ -636,7 +637,7 @@ public class MessageHistory {
             fos = new SecureFileOutputStream(f, true);
             String entry;
             while ((entry = _unwrittenEntries.poll()) != null) {
-                fos.write(entry.getBytes());
+                fos.write(DataHelper.getUTF8(entry));
                 fos.write(NL);
             }
         } catch (IOException ioe) {
diff --git a/router/java/test/junit/net/i2p/router/crypto/SessionEncryptionTest.java b/router/java/test/junit/net/i2p/router/crypto/SessionEncryptionTest.java
index fe2b1d9efe..9f2b041806 100644
--- a/router/java/test/junit/net/i2p/router/crypto/SessionEncryptionTest.java
+++ b/router/java/test/junit/net/i2p/router/crypto/SessionEncryptionTest.java
@@ -46,7 +46,7 @@ public class SessionEncryptionTest extends TestCase{
         SessionKeyManager skm = new TransientSessionKeyManager(_context);
         SessionKey curKey = skm.createSession(pubKey);
         
-        byte[] msg = "msg 1".getBytes();
+        byte[] msg = DataHelper.getASCII("msg 1");
         
         byte emsg[] = _context.elGamalAESEngine().encrypt(msg, pubKey, curKey, 64);
         byte dmsg[] = _context.elGamalAESEngine().decrypt(emsg, privKey, skm);
@@ -60,7 +60,7 @@ public class SessionEncryptionTest extends TestCase{
         SessionKeyManager skm = new TransientSessionKeyManager(_context);
         SessionKey curKey = skm.createSession(pubKey);
         
-        byte[] msg = "msg 2".getBytes();
+        byte[] msg = DataHelper.getASCII("msg 2");
         
         byte emsg[] = _context.elGamalAESEngine().encrypt(msg, pubKey, curKey, 64);
         byte dmsg[] = _context.elGamalAESEngine().decrypt(emsg, privKey, skm);
@@ -95,11 +95,11 @@ public class SessionEncryptionTest extends TestCase{
         secondTags.add(tag3);
         secondTags.add(tag4);
         
-        byte[] msg1 = "msg 1".getBytes();
-        byte[] msg2 = "msg 2".getBytes();
-        byte[] msg3 = "msg 3".getBytes();
-        byte[] msg4 = "msg 4".getBytes();
-        byte[] msg5 = "msg 5".getBytes();
+        byte[] msg1 = DataHelper.getASCII("msg 1");
+        byte[] msg2 = DataHelper.getASCII("msg 2");
+        byte[] msg3 = DataHelper.getASCII("msg 3");
+        byte[] msg4 = DataHelper.getASCII("msg 4");
+        byte[] msg5 = DataHelper.getASCII("msg 5");
         
         byte emsg1[] = _context.elGamalAESEngine().encrypt(msg1, pubKey, curKey, firstTags, 64);
         
@@ -195,11 +195,11 @@ public class SessionEncryptionTest extends TestCase{
         secondTags.add(tag3);
         secondTags.add(tag4);
         
-        byte[] msg1 = "msg 1".getBytes();
-        byte[] msg2 = "msg 2".getBytes();
-        byte[] msg3 = "msg 3".getBytes();
-        byte[] msg4 = "msg 4".getBytes();
-        byte[] msg5 = "msg 5".getBytes();
+        byte[] msg1 = DataHelper.getASCII("msg 1");
+        byte[] msg2 = DataHelper.getASCII("msg 2");
+        byte[] msg3 = DataHelper.getASCII("msg 3");
+        byte[] msg4 = DataHelper.getASCII("msg 4");
+        byte[] msg5 = DataHelper.getASCII("msg 5");
         
         byte emsg1[] = _context.elGamalAESEngine().encrypt(msg1, pubKey, curKey, firstTags, 64);
         
@@ -291,7 +291,7 @@ public class SessionEncryptionTest extends TestCase{
             if (i % 50 == 0)
                 nextKey = KeyGenerator.getInstance().generateSessionKey();
             
-            byte[] msg = ("msg " + i).getBytes();
+            byte[] msg = DataHelper.getASCII("msg " + i);
             
             byte emsg[] = _context.elGamalAESEngine().encrypt(msg, pubKey, curKey, tags, curTag, nextKey, 64);
             
diff --git a/router/java/test/junit/net/i2p/router/transport/crypto/DHSessionKeyBuilderTest.java b/router/java/test/junit/net/i2p/router/transport/crypto/DHSessionKeyBuilderTest.java
index 44a43d3e92..190e048d62 100644
--- a/router/java/test/junit/net/i2p/router/transport/crypto/DHSessionKeyBuilderTest.java
+++ b/router/java/test/junit/net/i2p/router/transport/crypto/DHSessionKeyBuilderTest.java
@@ -13,6 +13,7 @@ import java.math.BigInteger;
 
 import junit.framework.TestCase;
 import net.i2p.I2PAppContext;
+import net.i2p.data.DataHelper;
 import net.i2p.data.SessionKey;
 import net.i2p.util.RandomSource;
 
@@ -40,7 +41,7 @@ public class DHSessionKeyBuilderTest extends TestCase {
             String origVal = "1234567890123456"; // 16 bytes max using AESEngine
             byte enc[] = new byte[16];
             byte dec[] = new byte[16];
-            ctx.aes().encrypt(origVal.getBytes(), 0, enc, 0, key1, iv, 16);
+            ctx.aes().encrypt(DataHelper.getASCII(origVal), 0, enc, 0, key1, iv, 16);
             ctx.aes().decrypt(enc, 0, dec, 0, key2, iv, 16);
             String tranVal = new String(dec);
             assertEquals(origVal, tranVal);
-- 
GitLab