Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api/module-info,ByteArray: stop leaking HEX_FORMAT #90

Merged
merged 1 commit into from
Sep 3, 2024
Merged
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
1 change: 0 additions & 1 deletion secp-api/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
requires org.jspecify;

exports org.bitcoinj.secp.api;
exports org.bitcoinj.secp.api.internal; /* TEMPORARY */

uses org.bitcoinj.secp.api.Secp256k1Provider;
}
15 changes: 12 additions & 3 deletions secp-api/src/main/java/org/bitcoinj/secp/api/ByteArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
* An effectively-immutable byte array.
*/
public interface ByteArray extends Comparable<ByteArray> {
HexFormat HEX_FORMAT = new HexFormat();

/**
* @return the bytes as an array
Expand All @@ -35,7 +34,7 @@ public interface ByteArray extends Comparable<ByteArray> {
* @return the bytes as a hex-formatted string
*/
default String formatHex() {
return HEX_FORMAT.formatHex(bytes());
return toHexString(bytes());
}

/**
Expand All @@ -55,6 +54,16 @@ default int compareTo(ByteArray o) {
* @return hex-formatted String
*/
static String toHexString(byte[] bytes) {
return HEX_FORMAT.formatHex(bytes);
return ByteArrayBase.HEX_FORMAT.formatHex(bytes);
}

/**
* Abstract Base Class for creating ByteArray Implementations
*/
abstract class ByteArrayBase implements ByteArray {
private static final HexFormat HEX_FORMAT = new HexFormat();

@Override
public abstract byte[] bytes();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public byte[] getEncoded() {

@Override
public String toString() {
return ByteArray.HEX_FORMAT.formatHex(bytes());
return ByteArray.toHexString(bytes());
}

@Override
Expand Down