Skip to content

Commit

Permalink
api/module-info,ByteArray: stop leaking HEX_FORMAT
Browse files Browse the repository at this point in the history
Create nested ByteArrayBase abstract class.  (Will be flushed-out
later with more methods) 

Move HEX_FORMAT inside ByteArrayBase so it can be `private`.

module-info: stop exporting o.b.s.api.internal
  • Loading branch information
msgilligan committed Sep 3, 2024
1 parent 1a80a69 commit 42b7ea6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
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

0 comments on commit 42b7ea6

Please sign in to comment.