X-Git-Url: https://git.argeo.org/?p=lgpl%2Fargeo-commons.git;a=blobdiff_plain;f=org.argeo.api.uuid%2Fsrc%2Forg%2Fargeo%2Fapi%2Fuuid%2FNodeIdSupplier.java;fp=org.argeo.api.uuid%2Fsrc%2Forg%2Fargeo%2Fapi%2Fuuid%2FNodeIdSupplier.java;h=1a3cd5673e17d1504277c7c1428de4795ed30490;hp=81d368d2c8c651c37ea9ab48f7f048db98351f16;hb=b95462873703848193e56fcbe997693630db6121;hpb=55d88fba80cec198a0f11ba7545e19878c51fc5e diff --git a/org.argeo.api.uuid/src/org/argeo/api/uuid/NodeIdSupplier.java b/org.argeo.api.uuid/src/org/argeo/api/uuid/NodeIdSupplier.java index 81d368d2c..1a3cd5673 100644 --- a/org.argeo.api.uuid/src/org/argeo/api/uuid/NodeIdSupplier.java +++ b/org.argeo.api.uuid/src/org/argeo/api/uuid/NodeIdSupplier.java @@ -25,4 +25,28 @@ public interface NodeIdSupplier extends Supplier { random.nextBytes(nodeId); return nodeId; } + + /** + * Force this node id to be identified as no MAC address. + * + * @see "https://datatracker.ietf.org/doc/html/rfc4122#section-4.5" + */ + static void forceToNoMacAddress(byte[] nodeId, int offset) { + assert nodeId != null && offset < nodeId.length; + nodeId[offset] = (byte) (nodeId[offset] | 1); + } + + /* + * SPI UTILITIES + */ + /** Guarantees that a byte array of length 6 will be returned. */ + static byte[] toNodeIdBytes(byte[] source, int offset) { + if (source == null) + return null; + if (offset < 0 || offset + 6 > source.length) + throw new ArrayIndexOutOfBoundsException(offset); + byte[] nodeId = new byte[6]; + System.arraycopy(source, offset, nodeId, 0, 6); + return nodeId; + } }