aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-10-26 12:54:56 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2015-10-26 12:54:56 +1300
commitfbdd359d223579173b4e0076563df296f5492e3c (patch)
treefaacb0f61e284d17f942cb73d3a85f0dd3496d28
parentd938e1e4d8d54fec6aab26246b6b804d34addf66 (diff)
downloadtrackermap-server-fbdd359d223579173b4e0076563df296f5492e3c.tar.gz
trackermap-server-fbdd359d223579173b4e0076563df296f5492e3c.tar.bz2
trackermap-server-fbdd359d223579173b4e0076563df296f5492e3c.zip
Rename hex conversion methods
-rw-r--r--src/org/traccar/helper/ChannelBufferTools.java4
-rw-r--r--src/org/traccar/helper/Hashing.java8
-rw-r--r--test/org/traccar/ProtocolDecoderTest.java2
-rw-r--r--test/org/traccar/helper/ChannelBufferToolsTest.java8
-rw-r--r--test/org/traccar/protocol/CityeasyProtocolEncoderTest.java2
-rw-r--r--test/org/traccar/protocol/Gt06ProtocolEncoderTest.java2
-rw-r--r--test/org/traccar/protocol/KhdProtocolEncoderTest.java2
7 files changed, 13 insertions, 15 deletions
diff --git a/src/org/traccar/helper/ChannelBufferTools.java b/src/org/traccar/helper/ChannelBufferTools.java
index d8d74b6ea..99da43b54 100644
--- a/src/org/traccar/helper/ChannelBufferTools.java
+++ b/src/org/traccar/helper/ChannelBufferTools.java
@@ -89,7 +89,7 @@ public final class ChannelBufferTools {
return value;
}
- public static byte[] convertHexString(String in) {
+ public static byte[] hexToBytes(String in) {
int count = in.length() / 2;
byte[] out = new byte[count];
for (int i = 0; i < count; i++) {
@@ -98,7 +98,7 @@ public final class ChannelBufferTools {
return out;
}
- public static String convertByteArray(byte[] in) {
+ public static String bytesToHex(byte[] in) {
StringBuilder out = new StringBuilder();
Formatter formatter = new Formatter(out);
for (byte b : in) {
diff --git a/src/org/traccar/helper/Hashing.java b/src/org/traccar/helper/Hashing.java
index 1f01d9102..cdc5c7ae5 100644
--- a/src/org/traccar/helper/Hashing.java
+++ b/src/org/traccar/helper/Hashing.java
@@ -65,13 +65,13 @@ public final class Hashing {
RANDOM.nextBytes(salt);
byte[] hash = function(password.toCharArray(), salt);
return new HashingResult(
- ChannelBufferTools.convertByteArray(hash),
- ChannelBufferTools.convertByteArray(salt));
+ ChannelBufferTools.bytesToHex(hash),
+ ChannelBufferTools.bytesToHex(salt));
}
public static boolean validatePassword(String password, String hashHex, String saltHex) {
- byte[] hash = ChannelBufferTools.convertHexString(hashHex);
- byte[] salt = ChannelBufferTools.convertHexString(saltHex);
+ byte[] hash = ChannelBufferTools.hexToBytes(hashHex);
+ byte[] salt = ChannelBufferTools.hexToBytes(saltHex);
return slowEquals(hash, function(password.toCharArray(), salt));
}
diff --git a/test/org/traccar/ProtocolDecoderTest.java b/test/org/traccar/ProtocolDecoderTest.java
index 3eb42a0f6..992ade8f8 100644
--- a/test/org/traccar/ProtocolDecoderTest.java
+++ b/test/org/traccar/ProtocolDecoderTest.java
@@ -104,7 +104,7 @@ public class ProtocolDecoderTest {
protected ChannelBuffer binary(ByteOrder endianness, String... data) {
return ChannelBuffers.wrappedBuffer(
- endianness, ChannelBufferTools.convertHexString(concatenateStrings(data)));
+ endianness, ChannelBufferTools.hexToBytes(concatenateStrings(data)));
}
protected String text(String... data) {
diff --git a/test/org/traccar/helper/ChannelBufferToolsTest.java b/test/org/traccar/helper/ChannelBufferToolsTest.java
index 3d065a8d7..d34dfe9f7 100644
--- a/test/org/traccar/helper/ChannelBufferToolsTest.java
+++ b/test/org/traccar/helper/ChannelBufferToolsTest.java
@@ -1,9 +1,7 @@
package org.traccar.helper;
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.buffer.ChannelBufferFactory;
import org.jboss.netty.buffer.ChannelBuffers;
-import org.jboss.netty.buffer.HeapChannelBufferFactory;
+
import static org.junit.Assert.*;
import org.junit.Test;
@@ -30,12 +28,12 @@ public class ChannelBufferToolsTest {
@Test
public void convertHexStringTest() {
- assertArrayEquals(new byte[] {0x12, 0x34}, ChannelBufferTools.convertHexString("1234"));
+ assertArrayEquals(new byte[] {0x12, 0x34}, ChannelBufferTools.hexToBytes("1234"));
}
@Test
public void convertHexByteArray() {
- assertEquals("1234", ChannelBufferTools.convertByteArray(new byte[] {0x12, 0x34}));
+ assertEquals("1234", ChannelBufferTools.bytesToHex(new byte[]{0x12, 0x34}));
}
}
diff --git a/test/org/traccar/protocol/CityeasyProtocolEncoderTest.java b/test/org/traccar/protocol/CityeasyProtocolEncoderTest.java
index 4d94e9c69..e2bfbb19a 100644
--- a/test/org/traccar/protocol/CityeasyProtocolEncoderTest.java
+++ b/test/org/traccar/protocol/CityeasyProtocolEncoderTest.java
@@ -18,7 +18,7 @@ public class CityeasyProtocolEncoderTest {
command.setType(Command.TYPE_SET_TIMEZONE);
command.set(Command.KEY_TIMEZONE, 6 * 3600);
- Assert.assertEquals(encoder.encodeCommand(command), ChannelBuffers.wrappedBuffer(ChannelBufferTools.convertHexString(
+ Assert.assertEquals(encoder.encodeCommand(command), ChannelBuffers.wrappedBuffer(ChannelBufferTools.hexToBytes(
"5353001100080001680000000B60820D0A")));
}
diff --git a/test/org/traccar/protocol/Gt06ProtocolEncoderTest.java b/test/org/traccar/protocol/Gt06ProtocolEncoderTest.java
index 7f616d9df..1041e65af 100644
--- a/test/org/traccar/protocol/Gt06ProtocolEncoderTest.java
+++ b/test/org/traccar/protocol/Gt06ProtocolEncoderTest.java
@@ -17,7 +17,7 @@ public class Gt06ProtocolEncoderTest {
command.setDeviceId(1);
command.setType(Command.TYPE_ENGINE_STOP);
- Assert.assertEquals(encoder.encodeCommand(command), ChannelBuffers.wrappedBuffer(ChannelBufferTools.convertHexString(
+ Assert.assertEquals(encoder.encodeCommand(command), ChannelBuffers.wrappedBuffer(ChannelBufferTools.hexToBytes(
"787812800c0000000052656c61792c312300009dee0d0a")));
}
diff --git a/test/org/traccar/protocol/KhdProtocolEncoderTest.java b/test/org/traccar/protocol/KhdProtocolEncoderTest.java
index ec620aa60..872997d7f 100644
--- a/test/org/traccar/protocol/KhdProtocolEncoderTest.java
+++ b/test/org/traccar/protocol/KhdProtocolEncoderTest.java
@@ -17,7 +17,7 @@ public class KhdProtocolEncoderTest {
command.setDeviceId(1);
command.setType(Command.TYPE_ENGINE_STOP);
- Assert.assertEquals(encoder.encodeCommand(command), ChannelBuffers.wrappedBuffer(ChannelBufferTools.convertHexString(
+ Assert.assertEquals(encoder.encodeCommand(command), ChannelBuffers.wrappedBuffer(ChannelBufferTools.hexToBytes(
"2929390006000000003F0D")));
}