Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions src/main/java/io/zold/api/Wallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ public interface Wallet {
/**
* This wallet's RSA key.
* @return This wallet's RSA key
* @throws IOException If an IO error occurs
*/
String key();
String key() throws IOException;

/**
* A Fake {@link Wallet}.
Expand Down Expand Up @@ -275,14 +276,19 @@ public Iterable<Transaction> ledger() {
);
}

// @todo #54:30min Implement key method. This should return the
// public RSA key of the wallet owner in Base64. Also add a unit test
// to replace WalletTest.keyIsNotYetImplemented().
@Override
public String key() {
throw new UnsupportedOperationException(
"key() not yet supported"
);
public String key() throws IOException {
// @checkstyle ProhibitLineSeparatorInStringsCheck (10 lines)
return new Checked<>(
() -> new ListOf<>(
new Split(
new TextOf(this.path),
"\n"
)
// @checkstyle MagicNumberCheck (1 line)
).get(3).asString(),
e -> new IOException(e)
).value();
}
}
}
12 changes: 7 additions & 5 deletions src/test/java/io/zold/api/WalletTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,13 @@ public void walletShouldBeAbleToReturnLedger() throws Exception {
}

@Test
public void keyIsNotYetImplemented() throws IOException {
final Path path = this.folder.newFile().toPath();
Assertions.assertThrows(
UnsupportedOperationException.class,
() -> new Wallet.File(path).key()
public void readsPublicKey() throws IOException {
MatcherAssert.assertThat(
new Wallet.File(this.wallet(5_124_095_577_148_911L)).key(),
Matchers.is(
// @checkstyle LineLengthCheck (1 line)
"MIGeMA0GCSqGSIb3DQEBAQUAA4GMADCBiAKBgGZCr/9hBChqsChd4sRAIpKNRinjhSW+J+S7PU5malVMiRHVoKjeooLDpWpij0A6vkzOvjrMldAZT0Fzgp0cJ15TOVwiQanQ5WuQDgRkLoxrdh/qyBApoDvk4OUEozOQPNwfpZOFfaUALPsPnv9995TlY9WcdSKW5dj041p1tJmlAgMBAAE="
)
);
}

Expand Down
Loading