Make Base58 throw on decode if the input is not valid base58, add test.

Add a decodeChecked method that uses the last 4 bytes as a checksum, for IRC support.
This commit is contained in:
Mike Hearn
2011-05-02 11:44:14 +00:00
parent 3e267f1327
commit 37cb9cb6e5
2 changed files with 38 additions and 5 deletions

View File

@@ -22,7 +22,7 @@ import java.math.BigInteger;
import java.util.Arrays;
public class Base58Test extends TestCase {
public void testEncode() {
public void testEncode() throws Exception {
byte[] testbytes = "Hello World".getBytes();
assertEquals("JxF12TrwUP45BMd", Base58.encode(testbytes));
@@ -30,9 +30,17 @@ public class Base58Test extends TestCase {
assertEquals("16Ho7Hs", Base58.encode(bi.toByteArray()));
}
public void testDecode() {
public void testDecode() throws Exception {
byte[] testbytes = "Hello World".getBytes();
byte[] actualbytes = Base58.decode("JxF12TrwUP45BMd");
assertTrue(new String(actualbytes), Arrays.equals(testbytes, actualbytes));
try {
Base58.decode("This isn't valid base58");
fail();
} catch (AddressFormatException e) {
}
Base58.decodeChecked("4stwEBjT6FYyVV");
}
}