import java.util.HexFormat; /** Tiny helpers shared by the demos: hex, a self-checking assert that prints PASS/FAIL, section headers. */ final class Fx { private static final HexFormat HEX = HexFormat.of(); static int failures = 0; static String hex(byte[] b) { return HEX.formatHex(b); } static byte[] unhex(String s) { return HEX.parseHex(s.replaceAll("\\s+", "")); } /** Bytes 0x00..n-1 starting at {@code from} (RFC 5869 test case 2 uses such ranges). */ static byte[] range(int from, int count) { byte[] b = new byte[count]; for (int i = 0; i < count; i++) b[i] = (byte) (from + i); return b; } static byte[] fill(int value, int count) { byte[] b = new byte[count]; java.util.Arrays.fill(b, (byte) value); return b; } static void check(String what, boolean ok) { System.out.println((ok ? "PASS " : "FAIL ") + what); if (!ok) failures++; } static void checkEq(String what, byte[] expected, byte[] actual) { check(what, java.util.Arrays.equals(expected, actual)); if (!java.util.Arrays.equals(expected, actual)) { System.out.println(" expected " + hex(expected)); System.out.println(" actual " + hex(actual)); } } static void header(String s) { System.out.println("== " + s); } /** Exit non-zero if any check failed, so run.sh and CI notice. */ static void done() { System.out.println(failures == 0 ? "ALL CHECKS PASSED" : failures + " CHECK(S) FAILED"); if (failures != 0) System.exit(1); } }