From 5d6484cdf3beaa8a8082795cd9cfeb059aa01f2d Mon Sep 17 00:00:00 2001 From: Christian Basler Date: Wed, 6 May 2015 20:36:42 +0200 Subject: [PATCH] Pubkey import now works properly (well theoretically - practically we still need client support to store them) --- .../ch/dissem/bitmessage/utils/Bytes.java | 2 +- .../entity/BitmessageAddressTest.java | 42 ++++++++---------- domain/src/test/resources/V3Pubkey.payload | Bin 232 -> 232 bytes 3 files changed, 20 insertions(+), 24 deletions(-) diff --git a/domain/src/main/java/ch/dissem/bitmessage/utils/Bytes.java b/domain/src/main/java/ch/dissem/bitmessage/utils/Bytes.java index 4b3e888..f82b2d2 100644 --- a/domain/src/main/java/ch/dissem/bitmessage/utils/Bytes.java +++ b/domain/src/main/java/ch/dissem/bitmessage/utils/Bytes.java @@ -127,7 +127,7 @@ public class Bytes { for (int i = 0; i < bytes.length; i++) { if (bytes[i] != 0) { byte[] result = new byte[bytes.length - i]; - System.arraycopy(bytes, i, result, i, bytes.length - i); + System.arraycopy(bytes, i, result, 0, bytes.length - i); return result; } } diff --git a/domain/src/test/java/ch/dissem/bitmessage/entity/BitmessageAddressTest.java b/domain/src/test/java/ch/dissem/bitmessage/entity/BitmessageAddressTest.java index ea1022f..1020121 100644 --- a/domain/src/test/java/ch/dissem/bitmessage/entity/BitmessageAddressTest.java +++ b/domain/src/test/java/ch/dissem/bitmessage/entity/BitmessageAddressTest.java @@ -16,16 +16,13 @@ package ch.dissem.bitmessage.entity; -import ch.dissem.bitmessage.entity.payload.ObjectType; import ch.dissem.bitmessage.entity.payload.Pubkey; import ch.dissem.bitmessage.entity.payload.V3Pubkey; import ch.dissem.bitmessage.entity.valueobject.PrivateKey; -import ch.dissem.bitmessage.inventory.JdbcInventory; import ch.dissem.bitmessage.utils.*; import org.junit.Test; import java.io.IOException; -import java.util.List; import static org.junit.Assert.*; @@ -60,33 +57,32 @@ public class BitmessageAddressTest { } @Test - public void testV3() { -// ripe 007402be6e76c3cb87caa946d0c003a3d4d8e1d5 -// publicSigningKey in hex: 0435e3f10f4884ec42f11f1a815ace8c7c4575cad455ca98db19a245c4c57baebdce990919b647f2657596b75aa939b858bd70c55a03492dd95119bef009cf9eea -// publicEncryptionKey in hex: 04bf30a7ee7854f9381332a6285659215a6a4b2ab3479fa87fe996f7cd11710367748371d8d2545f8466964dd3140ab80508b2b18e45616ef6cc4d8e54db923761 - BitmessageAddress address = new BitmessageAddress("BM-2D9Vc5rFxxR5vTi53T9gkLfemViHRMVLQZ"); - V3Pubkey pubkey = new V3Pubkey.Builder() - .stream(1) - .publicSigningKey(Bytes.fromHex("0435e3f10f4884ec42f11f1a815ace8c7c4575cad455ca98db19a245c4c57baebdce990919b647f2657596b75aa939b858bd70c55a03492dd95119bef009cf9eea")) - .publicEncryptionKey(Bytes.fromHex("04bf30a7ee7854f9381332a6285659215a6a4b2ab3479fa87fe996f7cd11710367748371d8d2545f8466964dd3140ab80508b2b18e45616ef6cc4d8e54db923761")) - .build(); + public void testV2PubkeyImport() throws IOException { + ObjectMessage object = TestUtils.loadObjectMessage(2, "V2Pubkey.payload"); + Pubkey pubkey = (Pubkey) object.getPayload(); + BitmessageAddress address = new BitmessageAddress("BM-opWQhvk9xtMFvQA2Kvetedpk8LkbraWHT"); address.setPubkey(pubkey); - assertArrayEquals(Bytes.fromHex("007402be6e76c3cb87caa946d0c003a3d4d8e1d5"), address.getRipe()); } - @Test - public void testV2PubkeyImport() throws IOException { - ObjectMessage object = TestUtils.loadObjectMessage(2, "V2Pubkey.payload"); - V3Pubkey pubkey = (V3Pubkey) object.getPayload(); - BitmessageAddress address = new BitmessageAddress("BM-2DAjcCFrqFrp88FUxExhJ9kPqHdunQmiyn"); // TODO: find address - address.setPubkey(pubkey); - } @Test public void testV3PubkeyImport() throws IOException { + BitmessageAddress address = new BitmessageAddress("BM-2D9Vc5rFxxR5vTi53T9gkLfemViHRMVLQZ"); + assertArrayEquals(Bytes.fromHex("7402be6e76c3cb87caa946d0c003a3d4d8e1d5"), address.getRipe()); + ObjectMessage object = TestUtils.loadObjectMessage(3, "V3Pubkey.payload"); - V3Pubkey pubkey = (V3Pubkey) object.getPayload(); - BitmessageAddress address = new BitmessageAddress("BM-2DAjcCFrqFrp88FUxExhJ9kPqHdunQmiyn"); + Pubkey pubkey = (Pubkey) object.getPayload(); address.setPubkey(pubkey); + + assertArrayEquals(Bytes.fromHex("7402be6e76c3cb87caa946d0c003a3d4d8e1d5"), pubkey.getRipe()); + } + + @Test + public void testV4PubkeyImport() throws IOException { + // TODO +// ObjectMessage object = TestUtils.loadObjectMessage(3, "V4Pubkey.payload"); +// Pubkey pubkey = (Pubkey) object.getPayload(); +// BitmessageAddress address = new BitmessageAddress("BM-2D9Vc5rFxxR5vTi53T9gkLfemViHRMVLQZ"); +// address.setPubkey(pubkey); } @Test diff --git a/domain/src/test/resources/V3Pubkey.payload b/domain/src/test/resources/V3Pubkey.payload index 0f474008db2d62d53ec8e11e3d4ca5c7f8fa14df..f0c4e7e93679acc9d6b3f97acebab2e12cba4c0c 100644 GIT binary patch literal 232 zcmZQz0D{%3!XPR%!#EvCF)}lPNYlq3`8`_RIDM3tYK%J9Q{!5C>PqOT8Mh@DxgI%M zy>9QhnVgc_+&`t3PTL-}(sD<{-h!i1%$~Y8110x;;5yVyNaGx}V(QP?x%UCWx!3n68R`0T8VA~5e`^H*