Removed hex-string lib and scala class, can do it in 1 line of pure java.

Also synchronized around md, since it can be accessed by multiple threads, right?
This commit is contained in:
Travis Burtrum 2012-03-17 23:56:04 -04:00
parent 0bf23d8807
commit 57a8bdff9f
3 changed files with 10 additions and 11 deletions

View File

@ -12,7 +12,6 @@ import java.util.Random;
import org.moparscape.msc.gs.connection.RSCPacket; import org.moparscape.msc.gs.connection.RSCPacket;
import org.moparscape.msc.gs.core.GameEngine; import org.moparscape.msc.gs.core.GameEngine;
import org.moparscape.msc.gs.model.Point; import org.moparscape.msc.gs.model.Point;
import org.moparscape.msc.gs.util.HexString;
import org.moparscape.msc.gs.util.Logger; import org.moparscape.msc.gs.util.Logger;
public final class DataConversions { public final class DataConversions {
@ -258,9 +257,16 @@ public final class DataConversions {
* returns the md5 hash of a string * returns the md5 hash of a string
*/ */
public static String md5(String s) { public static String md5(String s) {
synchronized (md){
md.reset(); md.reset();
md.update(s.getBytes()); md.update(s.getBytes());
return new HexString(md.digest()).toString(); return toHex(md.digest());
}
}
public static String toHex(byte[] bytes) {
// change below to lower or uppercase X to control case of output
return String.format("%0" + (bytes.length << 1) + "x", new BigInteger(1, bytes));
} }
/** /**

View File

@ -1,7 +0,0 @@
package org.moparscape.msc.gs.util
class HexString(bytes: Array[Byte]) {
lazy val string = bytes.map(0xFF & _).map { "%02x".format(_) }.foldLeft("") { _ + _ }
override def toString = string
}

Binary file not shown.