forked from TrueCloudLab/frostfs-sdk-java
[#1] Add additional security
Signed-off-by: Ori Bruk <o.bruk@yadro.com>
This commit is contained in:
parent
bf2f19f08d
commit
1be65c63ae
62 changed files with 670 additions and 281 deletions
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue