Changeset c60f397


Ignore:
Timestamp:
Dec 20, 2015 1:18:38 AM (4 years ago)
Author:
z3r0fox <z3r0fox@…>
Branches:
master
Children:
2246e21
Parents:
0b94d86
Message:

Replaces instances of getBytes() in core classes

Location:
core/java
Files:
26 edited

Legend:

Unmodified
Added
Removed
  • core/java/src/com/nettgryppa/security/HashCash.java

    r0b94d86 rc60f397  
    99import java.text.SimpleDateFormat;
    1010import java.security.NoSuchAlgorithmException;
     11
     12import net.i2p.data.DataHelper;
    1113
    1214/**
     
    6264           
    6365            MessageDigest md = MessageDigest.getInstance("SHA1");
    64             md.update(cash.getBytes());
     66            md.update(DataHelper.getUTF8(cash));
    6567            byte[] tempBytes = md.digest();
    6668            int tempValue = numberOfLeadingZeros(tempBytes);
     
    191193        result.myToken = generateCash(prefix, value, md);
    192194        md.reset();
    193         md.update(result.myToken.getBytes());
     195        md.update(DataHelper.getUTF8(result.myToken));
    194196        result.myValue = numberOfLeadingZeros(md.digest());
    195197        break;
     
    295297      temp = prefix + Long.toHexString(counter);
    296298      md.reset();
    297       md.update(temp.getBytes());
     299      md.update(DataHelper.getUTF8(temp));
    298300      bArray = md.digest();
    299301      tempValue = numberOfLeadingZeros(bArray);
  • core/java/src/net/i2p/client/naming/EepGetAndAddNamingService.java

    r0b94d86 rc60f397  
    1111
    1212import net.i2p.I2PAppContext;
     13import net.i2p.data.DataHelper;
    1314import net.i2p.data.Destination;
    1415
     
    5859                            fos = new FileOutputStream(f, true);
    5960                            String line = hostname + '=' + rv.toBase64() + System.getProperty("line.separator");
    60                             fos.write(line.getBytes());
     61                            fos.write(DataHelper.getASCII(line));
    6162                        } catch (IOException ioe) {
    6263                            System.err.println("Error appending: " + ioe);
  • core/java/src/net/i2p/data/Base32.java

    r0b94d86 rc60f397  
    7373        String cmd = args[0].toLowerCase(Locale.US);
    7474        if ("encodestring".equals(cmd)) {
    75             System.out.println(encode(args[1].getBytes()));
     75            System.out.println(encode(DataHelper.getUTF8(args[1])));
    7676            return;
    7777        }
     
    144144     */
    145145    public static String encode(String source) {
    146         return (source != null ? encode(source.getBytes()) : "");
     146        return (source != null ? encode(DataHelper.getUTF8(source)) : "");
    147147    }
    148148
     
    211211     */
    212212    public static byte[] decode(String s) {
    213         return decode(s.getBytes());
     213        return decode(DataHelper.getASCII(s));
    214214    }
    215215
  • core/java/src/net/i2p/data/PrivateKeyFile.java

    r0b94d86 rc60f397  
    386386        System.out.println("Short Hashcash is: " + hcs);
    387387
    388         c.setPayload(hcs.getBytes());
     388        c.setPayload(DataHelper.getUTF8(hcs));
    389389        return c;
    390390    }
  • core/java/src/net/i2p/util/HexDump.java

    r0b94d86 rc60f397  
    115115            }
    116116
    117             out.write(" |".getBytes());
     117            out.write(DataHelper.getASCII(" |"));
    118118
    119119            for (i = 0; i < FORMAT_BYTES_PER_ROW; ++i) {
  • core/java/test/junit/net/i2p/client/datagram/DatagramTest.java

    r0b94d86 rc60f397  
    4444
    4545        I2PDatagramMaker dm = new I2PDatagramMaker(session);
    46         byte[] dg = dm.makeI2PDatagram("What's the deal with 42?".getBytes());
     46        byte[] dg = dm.makeI2PDatagram(DataHelper.getASCII("What's the deal with 42?"));
    4747
    4848        I2PDatagramDissector dd = new I2PDatagramDissector();
    4949        dd.loadI2PDatagram(dg);
    5050        byte[] x = dd.getPayload();
    51         assertTrue(DataHelper.eq(x, "What's the deal with 42?".getBytes()));
     51        assertTrue(DataHelper.eq(x, DataHelper.getASCII("What's the deal with 42?")));
    5252
    5353        x = dd.extractPayload();
    54         assertTrue(DataHelper.eq(x, "What's the deal with 42?".getBytes()));
     54        assertTrue(DataHelper.eq(x, DataHelper.getASCII("What's the deal with 42?")));
    5555
    5656        assertEquals(d, dd.getSender());
     
    6868        d.writeBytes(dout);
    6969        dsaEng.sign(Hash.FAKE_HASH.toByteArray(), session.getPrivateKey()).writeBytes(dout);
    70         dout.write("blah".getBytes());
     70        dout.write(DataHelper.getASCII("blah"));
    7171
    7272        byte[] data = dout.toByteArray();
  • core/java/test/junit/net/i2p/client/impl/I2PSessionTest.java

    r0b94d86 rc60f397  
    2020import net.i2p.client.I2PSessionException;
    2121import net.i2p.client.I2PSessionListener;
     22import net.i2p.data.DataHelper;
    2223import net.i2p.data.Destination;
    2324
     
    6768        _s.add("d");
    6869       
    69         session.sendMessage(d, "a".getBytes());
    70         session.sendMessage(d, "b".getBytes());
    71         session.sendMessage(d, "c".getBytes());
    72         session.sendMessage(d, "d".getBytes());
     70        session.sendMessage(d, DataHelper.getASCII("a"));
     71        session.sendMessage(d, DataHelper.getASCII("b"));
     72        session.sendMessage(d, DataHelper.getASCII("c"));
     73        session.sendMessage(d, DataHelper.getASCII("d"));
    7374       
    7475        for(int i = 0; (i < 20)&&(!_s.isEmpty()); i++){
  • core/java/test/junit/net/i2p/crypto/AES256Bench.java

    r0b94d86 rc60f397  
    8787        if (!same) throw new RuntimeException("moo");
    8888       
    89         plain = "1234567890123456".getBytes();
     89        plain = DataHelper.getASCII("1234567890123456");
    9090        e = new byte[plain.length];
    9191        _context.aes().encrypt(plain, 0, e, 0, key, iv, plain.length);
  • core/java/test/junit/net/i2p/crypto/AESInputStream.java

    r0b94d86 rc60f397  
    288288        byte orig[] = new byte[1024 * 32];
    289289        RandomSource.getInstance().nextBytes(orig);
    290         //byte orig[] = "you are my sunshine, my only sunshine".getBytes();
     290        //byte orig[] = DataHelper.getASCII("you are my sunshine, my only sunshine");
    291291        SessionKey key = KeyGenerator.getInstance().generateSessionKey();
    292         byte iv[] = "there once was a".getBytes();
     292        byte iv[] = DataHelper.getASCII("there once was a");
    293293
    294294        for (int i = 0; i < 20; i++) {
  • core/java/test/junit/net/i2p/crypto/AESInputStreamTest.java

    r0b94d86 rc60f397  
    2424    public void testMultiple() throws Exception{
    2525        SessionKey key = KeyGenerator.getInstance().generateSessionKey();
    26         byte iv[] = "there once was a".getBytes();
     26        byte iv[] = DataHelper.getASCII("there once was a");
    2727       
    2828        int[] sizes = {1024 * 32, 20, 3, 0};
     
    7171       
    7272        SessionKey key = KeyGenerator.getInstance().generateSessionKey();
    73         byte iv[] = "there once was a".getBytes();
     73        byte iv[] = DataHelper.getASCII("there once was a");
    7474       
    7575        ByteArrayOutputStream origStream = new ByteArrayOutputStream(512);
  • core/java/test/junit/net/i2p/crypto/ElGamalTest.java

    r0b94d86 rc60f397  
    137137       
    138138        String msg = "Hello world01234012345678901234501234567890123450123456789012345";
    139         h = SHA256Generator.getInstance().calculateHash(msg.getBytes());
    140        
    141         byte aesEncr[] = new byte[msg.getBytes().length];
     139        h = SHA256Generator.getInstance().calculateHash(DataHelper.getASCII(msg));
     140       
     141        byte aesEncr[] = new byte[DataHelper.getASCII(msg).length];
    142142        byte aesDecr[] = new byte[aesEncr.length];
    143         _context.aes().encrypt(msg.getBytes(), 0, aesEncr, 0, sessionKey, iv, aesEncr.length);
     143        _context.aes().encrypt(DataHelper.getASCII(msg), 0, aesEncr, 0, sessionKey, iv, aesEncr.length);
    144144        _context.aes().decrypt(aesEncr, 0, aesDecr, 0, sessionKey, iv, aesEncr.length);
    145145        h = SHA256Generator.getInstance().calculateHash(aesDecr);
     
    156156        String msg = "Hello world";
    157157       
    158         byte encrypted[] = _context.elGamalAESEngine().encryptAESBlock(msg.getBytes(), sessionKey, iv, null, null, 64);
     158        byte encrypted[] = _context.elGamalAESEngine().encryptAESBlock(DataHelper.getASCII(msg), sessionKey, iv, null, null, 64);
    159159        Set<SessionTag> foundTags = new HashSet<SessionTag>();
    160160        SessionKey foundKey = new SessionKey();
     
    181181        if (key == null)
    182182            key = _context.sessionKeyManager().createSession(pubKey);
    183         byte[] encrypted = _context.elGamalAESEngine().encrypt(msg.getBytes(), pubKey, key, 64);
     183        byte[] encrypted = _context.elGamalAESEngine().encrypt(DataHelper.getASCII(msg), pubKey, key, 64);
    184184        byte[] decrypted = null;
    185185        try{
     
    287287
    288288        for (int i = 0; i < UNENCRYPTED.length; i++) {
    289             byte orig[] = UNENCRYPTED[i].getBytes();
     289            byte orig[] = DataHelper.getASCII(UNENCRYPTED[i]);
    290290
    291291            byte encrypted[] = _context.elGamalEngine().encrypt(orig, pub);
     
    311311            byte decrypted[] = _context.elGamalEngine().decrypt(enc, priv);
    312312
    313             assertTrue(DataHelper.eq(decrypted, UNENCRYPTED[i].getBytes()));
     313            assertTrue(DataHelper.eq(decrypted, DataHelper.getASCII(UNENCRYPTED[i])));
    314314        }
    315315    }
     
    344344                    tags.add(new SessionTag(true));
    345345            }
    346             byte encrypted[] = e.encrypt("blah".getBytes(), pubKey, sessionKey, tags, 1024);
     346            byte encrypted[] = e.encrypt(DataHelper.getASCII("blah"), pubKey, sessionKey, tags, 1024);
    347347            byte decrypted[] = e.decrypt(encrypted, privKey);
    348348            assertEquals("blah", new String(decrypted));
  • core/java/test/junit/net/i2p/crypto/HMACSHA256Bench.java

    r0b94d86 rc60f397  
    3333
    3434import net.i2p.I2PAppContext;
     35import net.i2p.data.DataHelper;
    3536import net.i2p.data.Hash;
    3637import net.i2p.data.SessionKey;
     
    7576                        buf.append("a");
    7677                }
    77                 byte[] mmess = buf.toString().getBytes(); // new String("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq").getBytes();
     78                byte[] mmess = DataHelper.getASCII(buf.toString()); // new String("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq").getBytes();
    7879                buf = new StringBuilder();
    7980                for (int x = 0; x < 10000; x++) {
    8081                        buf.append("a");
    8182                }
    82                 byte[] lmess = buf.toString().getBytes();
     83                byte[] lmess = DataHelper.getASCII(buf.toString());
    8384
    8485                // warm up the engines
  • core/java/test/junit/net/i2p/crypto/SHA256Bench.java

    r0b94d86 rc60f397  
    3030 */
    3131
     32import net.i2p.data.DataHelper;
    3233import net.i2p.data.Hash;
    3334
    3435public class SHA256Bench {
    3536        public static void main(String args[]) {
    36                 Hash asdfs = SHA256Generator.getInstance().calculateHash("qwerty".getBytes());
     37                Hash asdfs = SHA256Generator.getInstance().calculateHash(DataHelper.getASCII("qwerty"));
    3738                       
    3839                int times = 100;
     
    5758                long maxLong1 = 0;
    5859       
    59                 byte[] smess = new String("abc").getBytes();
     60                byte[] smess = DataHelper.getASCII(new String("abc"));
    6061                StringBuilder buf = new StringBuilder();
    6162                for (int x = 0; x < 10*1024; x++) {
    6263                        buf.append("a");
    6364                }
    64                 byte[] mmess = buf.toString().getBytes(); // new String("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq").getBytes();
     65                byte[] mmess = DataHelper.getASCII(buf.toString()); // new String("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq").getBytes();
    6566                buf = new StringBuilder();
    6667                for (int x = 0; x < 1000000; x++) {
    6768                        buf.append("a");
    6869                }
    69                 byte[] lmess = buf.toString().getBytes();
     70                byte[] lmess = DataHelper.getASCII(buf.toString());
    7071       
    7172                // warm up the engines
  • core/java/test/junit/net/i2p/crypto/SHA256Test.java

    r0b94d86 rc60f397  
    1111import junit.framework.TestCase;
    1212import net.i2p.I2PAppContext;
     13import net.i2p.data.DataHelper;
    1314import net.i2p.data.Hash;
    1415/**
     
    3738     */
    3839    public void testMultipleEquality(){
    39         byte[] data = "blahblah".getBytes();
     40        byte[] data = DataHelper.getASCII("blahblah");
    4041
    4142        Hash firstHash = SHA256Generator.getInstance().calculateHash(data);
  • core/java/test/junit/net/i2p/data/Base64Test.java

    r0b94d86 rc60f397  
    1414    public void testBase64(){
    1515        String orig = "you smell";
    16         String encoded = Base64.encode(orig.getBytes());
     16        String encoded = Base64.encode(DataHelper.getASCII(orig));
    1717        byte decoded[] = Base64.decode(encoded);
    1818        String transformed = new String(decoded);
  • core/java/test/junit/net/i2p/data/DataStructureImplTest.java

    r0b94d86 rc60f397  
    6161        boolean error = false;
    6262        try{
    63             _struct.fromByteArray("water is poison".getBytes());
     63            _struct.fromByteArray(DataHelper.getASCII("water is poison"));
    6464        }catch(DataFormatException dfe){
    6565            error = true;
  • core/java/test/junit/net/i2p/data/PayloadTest.java

    r0b94d86 rc60f397  
    2121        SessionKey key = (SessionKey)(new SessionKeyTest()).createDataStructure();
    2222       
    23         byte data[] = "Hello, I2P".getBytes();
     23        byte data[] = DataHelper.getASCII("Hello, I2P");
    2424        // This causes equals() to fail unless we override the test
    2525        // to set the unencrypted data after reading.
  • core/java/test/junit/net/i2p/data/PrivateKeyTest.java

    r0b94d86 rc60f397  
    8282    public void testShortRead() throws Exception{
    8383        PrivateKey privateKey = new PrivateKey();
    84         ByteArrayInputStream in = new ByteArrayInputStream("six times nine equals forty-two".getBytes());
     84        ByteArrayInputStream in = new ByteArrayInputStream(DataHelper.getASCII("six times nine equals forty-two"));
    8585        boolean error = false;
    8686        try{
  • core/java/test/junit/net/i2p/data/PublicKeyTest.java

    r0b94d86 rc60f397  
    8282    public void testShortRead() throws Exception{
    8383        PublicKey publicKey = new PublicKey();
    84         ByteArrayInputStream in = new ByteArrayInputStream("six times nine equals forty-two".getBytes());
     84        ByteArrayInputStream in = new ByteArrayInputStream(DataHelper.getASCII("six times nine equals forty-two"));
    8585        boolean error = false;
    8686        try{
  • core/java/test/junit/net/i2p/data/SigningPrivateKeyTest.java

    r0b94d86 rc60f397  
    8282    public void testShortRead() throws Exception{
    8383        SigningPrivateKey signingPrivateKey = new SigningPrivateKey();
    84         ByteArrayInputStream in = new ByteArrayInputStream("short".getBytes());
     84        ByteArrayInputStream in = new ByteArrayInputStream(DataHelper.getASCII("short"));
    8585        boolean error = false;
    8686        try{
  • core/java/test/junit/net/i2p/data/SigningPublicKeyTest.java

    r0b94d86 rc60f397  
    8383    public void testShortRead() throws Exception{
    8484        SigningPublicKey publicKey = new SigningPublicKey();
    85         ByteArrayInputStream in = new ByteArrayInputStream("six times nine equals forty-two".getBytes());
     85        ByteArrayInputStream in = new ByteArrayInputStream(DataHelper.getASCII("six times nine equals forty-two"));
    8686        boolean error = false;
    8787        try{
  • core/java/test/junit/net/i2p/stat/RateTest.java

    r0b94d86 rc60f397  
    33import java.io.ByteArrayInputStream;
    44import java.util.Properties;
     5import net.i2p.data.DataHelper;
    56
    67import org.junit.Test;
     
    2223       
    2324        rate.store("rate.test", buf);
    24         byte data[] = buf.toString().getBytes();
     25        byte data[] = DataHelper.getUTF8(buf.toString());
    2526
    2627        Properties props = new Properties();
  • core/java/test/junit/net/i2p/util/ResettableGZIPInputStreamTest.java

    r0b94d86 rc60f397  
    4646        }
    4747       
    48         byte orig[] = "ho ho ho, merry christmas".getBytes();
     48        byte orig[] = DataHelper.getASCII("ho ho ho, merry christmas");
    4949        ByteArrayOutputStream baos = new ByteArrayOutputStream(64);
    5050        GZIPOutputStream o = new GZIPOutputStream(baos);
  • core/java/test/junit/net/i2p/util/ResettableGZIPOutputStreamTest.java

    r0b94d86 rc60f397  
    1919public class ResettableGZIPOutputStreamTest extends TestCase {
    2020    public void testResettableGZIPOutputStream() throws Exception{
    21         byte b[] = "hi, how are you today?".getBytes();
     21        byte b[] = DataHelper.getASCII("hi, how are you today?");
    2222        ByteArrayOutputStream baos = new ByteArrayOutputStream();
    2323        ResettableGZIPOutputStream o = new ResettableGZIPOutputStream(baos);
  • core/java/test/junit/net/i2p/util/ReusableGZIPInputStreamTest.java

    r0b94d86 rc60f397  
    2121    public void testReusableGZIPInputStream() throws Exception{
    2222        {
    23             byte b[] = "hi, how are you today?".getBytes();
     23            byte b[] = DataHelper.getASCII("hi, how are you today?");
    2424            ByteArrayOutputStream baos = new ByteArrayOutputStream(64);
    2525            GZIPOutputStream o = new GZIPOutputStream(baos);
  • core/java/test/junit/net/i2p/util/ReusableGZIPOutputStreamTest.java

    r0b94d86 rc60f397  
    2020    public void testReusableGZIPOutputStream() throws Exception{
    2121        {
    22             byte b[] = "hi, how are you today?".getBytes();
     22            byte b[] = DataHelper.getASCII("hi, how are you today?");
    2323            ReusableGZIPOutputStream o = ReusableGZIPOutputStream.acquire();
    2424            o.write(b);
Note: See TracChangeset for help on using the changeset viewer.