Fixed hex representation of KademliaID

This commit is contained in:
ChronosX88 2019-03-01 18:49:31 +04:00
parent d72e0065e1
commit 4b617c249a
No known key found for this signature in database
GPG Key ID: 8F92E090A87804AA
2 changed files with 4 additions and 5 deletions

View File

@ -20,7 +20,6 @@ android {
dependencies {
def room_version = "2.1.0-alpha04"
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
@ -30,4 +29,5 @@ dependencies {
implementation 'com.google.code.gson:gson:2.8.5'
implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"
implementation 'javax.xml.bind:jaxb-api:2.4.0-b180830.0359'
}

View File

@ -14,6 +14,7 @@ import java.util.Arrays;
import java.util.BitSet;
import java.util.Random;
import io.github.chronosx88.influence.kademlia.message.Streamable;
import javax.xml.bind.DatatypeConverter;
public class KademliaId implements Streamable, Serializable
{
@ -28,7 +29,7 @@ public class KademliaId implements Streamable, Serializable
*/
public KademliaId(String data)
{
keyBytes = data.getBytes();
keyBytes = DatatypeConverter.parseHexBinary(data);
if (keyBytes.length != ID_LENGTH / 8)
{
throw new IllegalArgumentException("Specified Data need to be " + (ID_LENGTH / 8) + " characters long.");
@ -249,9 +250,7 @@ public class KademliaId implements Streamable, Serializable
public String hexRepresentation()
{
/* Returns the hex format of this NodeId */
BigInteger bi = new BigInteger(1, this.keyBytes);
return String.format("%0" + (this.keyBytes.length << 1) + "X", bi);
return DatatypeConverter.printHexBinary(this.keyBytes);
}
@Override