[#1] Add additional security

Signed-off-by: Ori Bruk <o.bruk@yadro.com>
This commit is contained in:
Ori Bruk 2024-07-24 14:41:42 +03:00
parent bf2f19f08d
commit 1be65c63ae
62 changed files with 670 additions and 281 deletions

View file

@ -3,19 +3,33 @@ package info.frostfs.sdk;
import java.nio.ByteBuffer;
import java.util.UUID;
import static java.util.Objects.isNull;
public class UUIDExtension {
private static final int UUID_BYTE_ARRAY_LENGTH = 16;
private UUIDExtension() {
}
public static UUID asUuid(byte[] bytes) {
if (isNull(bytes) || bytes.length != UUID_BYTE_ARRAY_LENGTH) {
throw new IllegalArgumentException("Uuid byte array length must be " + UUID_BYTE_ARRAY_LENGTH);
}
ByteBuffer bb = ByteBuffer.wrap(bytes);
long firstLong = bb.getLong();
long secondLong = bb.getLong();
return new UUID(firstLong, secondLong);
}
public static byte[] asBytes(UUID id) {
public static byte[] asBytes(UUID uuid) {
if (isNull(uuid)) {
throw new IllegalArgumentException("Uuid is not present");
}
ByteBuffer bb = ByteBuffer.allocate(16);
bb.putLong(id.getMostSignificantBits());
bb.putLong(id.getLeastSignificantBits());
bb.putLong(uuid.getMostSignificantBits());
bb.putLong(uuid.getLeastSignificantBits());
return bb.array();
}
}