From ff5b00778088e7c0303d6ae47146f17ccdd021c3 Mon Sep 17 00:00:00 2001 From: Bruk Ori Date: Tue, 23 Jul 2024 19:30:07 +0300 Subject: [PATCH] [#XX] code cleanup update README.md Signed-off-by: Ori Bruk --- README.md | 18 ++--- .../src/main/java/info/FrostFS/sdk/Main.java | 67 ------------------- .../FrostFS/sdk/constants/CryptoConst.java | 5 ++ .../sdk/{tools => jdo}/ClientEnvironment.java | 2 +- .../sdk/{tools => jdo}/ClientSettings.java | 2 +- .../FrostFS/sdk/{tools => jdo}/ECDsa.java | 2 +- .../sdk/{tools => jdo}/NetworkSettings.java | 2 +- .../{tools => jdo}/PutObjectParameters.java | 2 +- .../FrostFS/sdk/services/ContextAccessor.java | 2 +- .../FrostFS/sdk/services/FrostFSClient.java | 25 ++++--- .../FrostFS/sdk/services/NetmapClient.java | 2 +- .../FrostFS/sdk/services/ObjectClient.java | 2 +- .../sdk/services/impl/ContainerService.java | 14 ++-- .../sdk/services/impl/NetmapService.java | 10 +-- .../sdk/services/impl/ObjectReader.java | 11 +-- .../sdk/services/impl/ObjectService.java | 23 ++++--- .../sdk/services/impl/ObjectTools.java | 8 +-- .../sdk/services/impl/SearchReader.java | 2 +- .../sdk/services/impl/SessionService.java | 6 +- .../FrostFS/sdk/{ => tools}/GrpcClient.java | 6 +- .../info/FrostFS/sdk/tools/MessageHelper.java | 15 +++++ .../sdk/{ => tools}/RequestConstructor.java | 25 +++---- .../sdk/{ => tools}/RequestSigner.java | 58 ++++++++-------- .../FrostFS/sdk/{ => tools}/Verifier.java | 48 ++++++------- cryptography/pom.xml | 4 +- .../main/java/info/FrostFS/sdk/Helper.java | 4 +- models/pom.xml | 4 +- .../FrostFS/sdk/constants/FieldConst.java | 11 +++ 28 files changed, 177 insertions(+), 203 deletions(-) delete mode 100644 client/src/main/java/info/FrostFS/sdk/Main.java create mode 100644 client/src/main/java/info/FrostFS/sdk/constants/CryptoConst.java rename client/src/main/java/info/FrostFS/sdk/{tools => jdo}/ClientEnvironment.java (97%) rename client/src/main/java/info/FrostFS/sdk/{tools => jdo}/ClientSettings.java (97%) rename client/src/main/java/info/FrostFS/sdk/{tools => jdo}/ECDsa.java (95%) rename client/src/main/java/info/FrostFS/sdk/{tools => jdo}/NetworkSettings.java (99%) rename client/src/main/java/info/FrostFS/sdk/{tools => jdo}/PutObjectParameters.java (98%) rename client/src/main/java/info/FrostFS/sdk/{ => tools}/GrpcClient.java (73%) create mode 100644 client/src/main/java/info/FrostFS/sdk/tools/MessageHelper.java rename client/src/main/java/info/FrostFS/sdk/{ => tools}/RequestConstructor.java (61%) rename client/src/main/java/info/FrostFS/sdk/{ => tools}/RequestSigner.java (69%) rename client/src/main/java/info/FrostFS/sdk/{ => tools}/Verifier.java (70%) create mode 100644 models/src/main/java/info/FrostFS/sdk/constants/FieldConst.java diff --git a/README.md b/README.md index 94031a8..fec8945 100644 --- a/README.md +++ b/README.md @@ -21,18 +21,18 @@ neo-go wallet export -w -d ### Container ```java -import info.FrostFS.sdk.enums.BasicAcl; import info.FrostFS.sdk.dto.container.Container; import info.FrostFS.sdk.dto.netmap.PlacementPolicy; import info.FrostFS.sdk.dto.netmap.Replica; +import info.FrostFS.sdk.enums.BasicAcl; +import info.FrostFS.sdk.jdo.ClientSettings; import info.FrostFS.sdk.services.FrostFSClient; public class ContainerExample { public void example() { - Client client = new Client( < your_key >); - GrpcClient grpcClient = new GrpcClient( < your_host >); - FrostFSClient frostFSClient = new FrostFSClient(grpcClient, client); + ClientSettings clientSettings = new ClientSettings(, ); + FrostFSClient frostFSClient = new FrostFSClient(clientSettings); // Create container var placementPolicy = new PlacementPolicy(true, new Replica[]{new Replica(1)}); @@ -58,6 +58,7 @@ import info.FrostFS.sdk.dto.container.ContainerId; import info.FrostFS.sdk.dto.object.ObjectAttribute; import info.FrostFS.sdk.dto.object.ObjectFilter; import info.FrostFS.sdk.dto.object.ObjectHeader; +import info.FrostFS.sdk.jdo.PutObjectParameters; import info.FrostFS.sdk.services.FrostFSClient; import java.io.FileInputStream; @@ -66,9 +67,8 @@ import java.io.IOException; public class ObjectExample { public void example() { - Client client = new Client( < your_key >); - GrpcClient grpcClient = new GrpcClient( < your_host >); - FrostFSClient frostFSClient = new FrostFSClient(grpcClient, client); + ClientSettings clientSettings = new ClientSettings(, ); + FrostFSClient frostFSClient = new FrostFSClient(clientSettings); // Put object info.FrostFS.sdk.dto.object.ObjectId objectId; @@ -76,7 +76,9 @@ public class ObjectExample { var cat = new ObjectHeader( containerId, ObjectType.REGULAR, new ObjectAttribute[]{new ObjectAttribute("Filename", "cat.jpg")} ); - objectId = frostFSClient.putObject(cat, fis); + + var params = new PutObjectParameters(cat, fis); + objectId = frostFSClient.putObject(params); } catch (IOException e) { throw new RuntimeException(e); } diff --git a/client/src/main/java/info/FrostFS/sdk/Main.java b/client/src/main/java/info/FrostFS/sdk/Main.java deleted file mode 100644 index 4c854fe..0000000 --- a/client/src/main/java/info/FrostFS/sdk/Main.java +++ /dev/null @@ -1,67 +0,0 @@ -package info.FrostFS.sdk; - -import info.FrostFS.sdk.dto.container.Container; -import info.FrostFS.sdk.dto.container.ContainerId; -import info.FrostFS.sdk.enums.BasicAcl; -import info.FrostFS.sdk.enums.ObjectType; -import info.FrostFS.sdk.dto.netmap.PlacementPolicy; -import info.FrostFS.sdk.dto.netmap.Replica; -import info.FrostFS.sdk.dto.object.ObjectAttribute; -import info.FrostFS.sdk.dto.object.ObjectFrostFS; -import info.FrostFS.sdk.dto.object.ObjectHeader; -import info.FrostFS.sdk.dto.object.ObjectId; -import info.FrostFS.sdk.services.FrostFSClient; -import info.FrostFS.sdk.tools.ClientSettings; -import info.FrostFS.sdk.tools.PutObjectParameters; - -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.util.Collections; -import java.util.List; - -public class Main { - public static void main(String[] args) throws Exception { - ClientSettings clientSettings = new ClientSettings("KwHDAJ66o8FoLBjVbjP2sWBmgBMGjt7Vv4boA7xQrBoAYBE397Aq", "http://localhost:8080"); - FrostFSClient frostFSClient = new FrostFSClient(clientSettings); -/* - var res2 = frostFSClient.searchObjectsAsync(new ContainerId("EQGx2QeYHJb53uRwYGzcQaW191sZpdNrjutk6veUSV2R")); -*/ - var placementPolicy = new PlacementPolicy(true, new Replica[]{new Replica(1)}); - var containerId = frostFSClient.createContainer(new Container(BasicAcl.PUBLIC_RW, placementPolicy)); - Thread.sleep(1000); - - FileInputStream file = null; - try { - file = new FileInputStream("/home/ori/Desktop/cat.jpg"); - var cat = new ObjectHeader(containerId, ObjectType.REGULAR, Collections.singletonList(new ObjectAttribute("Filename", "cat3.jpg"))); - - var params = new PutObjectParameters(cat, file, false, 1024); - var tty = frostFSClient.putObject(params); - - System.out.println(1); - } catch (FileNotFoundException e) { - throw new RuntimeException(e); - } - - - var res = frostFSClient.searchObjects(containerId); - - ObjectFrostFS res3 = frostFSClient - .getObject(new ContainerId("EQGx2QeYHJb53uRwYGzcQaW191sZpdNrjutk6veUSV2R"), new ObjectId("85orCLKSu3X1jGiTFmwmTUsBU88RBARNwuRwrEy5pyww")); - - - var ttttt = frostFSClient.getNetworkSettings(); - Container container2 = frostFSClient.getContainer(new ContainerId("EQGx2QeYHJb53uRwYGzcQaW191sZpdNrjutk6veUSV2R")); - - - - - Container container = frostFSClient.getContainer(containerId); - List containerIds = frostFSClient.listContainers(); -/* - frostFSClient.deleteContainerAsync(containerId); -*/ - containerIds = frostFSClient.listContainers(); - System.out.println(); - } -} \ No newline at end of file diff --git a/client/src/main/java/info/FrostFS/sdk/constants/CryptoConst.java b/client/src/main/java/info/FrostFS/sdk/constants/CryptoConst.java new file mode 100644 index 0000000..742ef60 --- /dev/null +++ b/client/src/main/java/info/FrostFS/sdk/constants/CryptoConst.java @@ -0,0 +1,5 @@ +package info.FrostFS.sdk.constants; + +public class CryptoConst { + public static final String SIGNATURE_ALGORITHM = "NONEwithECDSAinP1363Format"; +} diff --git a/client/src/main/java/info/FrostFS/sdk/tools/ClientEnvironment.java b/client/src/main/java/info/FrostFS/sdk/jdo/ClientEnvironment.java similarity index 97% rename from client/src/main/java/info/FrostFS/sdk/tools/ClientEnvironment.java rename to client/src/main/java/info/FrostFS/sdk/jdo/ClientEnvironment.java index ee1d8d4..f770057 100644 --- a/client/src/main/java/info/FrostFS/sdk/tools/ClientEnvironment.java +++ b/client/src/main/java/info/FrostFS/sdk/jdo/ClientEnvironment.java @@ -1,4 +1,4 @@ -package info.FrostFS.sdk.tools; +package info.FrostFS.sdk.jdo; import info.FrostFS.sdk.dto.OwnerId; import info.FrostFS.sdk.dto.Version; diff --git a/client/src/main/java/info/FrostFS/sdk/tools/ClientSettings.java b/client/src/main/java/info/FrostFS/sdk/jdo/ClientSettings.java similarity index 97% rename from client/src/main/java/info/FrostFS/sdk/tools/ClientSettings.java rename to client/src/main/java/info/FrostFS/sdk/jdo/ClientSettings.java index 2b25083..c7f5de0 100644 --- a/client/src/main/java/info/FrostFS/sdk/tools/ClientSettings.java +++ b/client/src/main/java/info/FrostFS/sdk/jdo/ClientSettings.java @@ -1,4 +1,4 @@ -package info.FrostFS.sdk.tools; +package info.FrostFS.sdk.jdo; import io.grpc.ChannelCredentials; import org.apache.commons.lang3.StringUtils; diff --git a/client/src/main/java/info/FrostFS/sdk/tools/ECDsa.java b/client/src/main/java/info/FrostFS/sdk/jdo/ECDsa.java similarity index 95% rename from client/src/main/java/info/FrostFS/sdk/tools/ECDsa.java rename to client/src/main/java/info/FrostFS/sdk/jdo/ECDsa.java index 98ccfc0..e3afee7 100644 --- a/client/src/main/java/info/FrostFS/sdk/tools/ECDsa.java +++ b/client/src/main/java/info/FrostFS/sdk/jdo/ECDsa.java @@ -1,4 +1,4 @@ -package info.FrostFS.sdk.tools; +package info.FrostFS.sdk.jdo; import java.security.PrivateKey; diff --git a/client/src/main/java/info/FrostFS/sdk/tools/NetworkSettings.java b/client/src/main/java/info/FrostFS/sdk/jdo/NetworkSettings.java similarity index 99% rename from client/src/main/java/info/FrostFS/sdk/tools/NetworkSettings.java rename to client/src/main/java/info/FrostFS/sdk/jdo/NetworkSettings.java index d6971b3..680d3d3 100644 --- a/client/src/main/java/info/FrostFS/sdk/tools/NetworkSettings.java +++ b/client/src/main/java/info/FrostFS/sdk/jdo/NetworkSettings.java @@ -1,4 +1,4 @@ -package info.FrostFS.sdk.tools; +package info.FrostFS.sdk.jdo; import java.util.HashMap; import java.util.Map; diff --git a/client/src/main/java/info/FrostFS/sdk/tools/PutObjectParameters.java b/client/src/main/java/info/FrostFS/sdk/jdo/PutObjectParameters.java similarity index 98% rename from client/src/main/java/info/FrostFS/sdk/tools/PutObjectParameters.java rename to client/src/main/java/info/FrostFS/sdk/jdo/PutObjectParameters.java index ca62737..51082a3 100644 --- a/client/src/main/java/info/FrostFS/sdk/tools/PutObjectParameters.java +++ b/client/src/main/java/info/FrostFS/sdk/jdo/PutObjectParameters.java @@ -1,4 +1,4 @@ -package info.FrostFS.sdk.tools; +package info.FrostFS.sdk.jdo; import info.FrostFS.sdk.dto.object.ObjectHeader; diff --git a/client/src/main/java/info/FrostFS/sdk/services/ContextAccessor.java b/client/src/main/java/info/FrostFS/sdk/services/ContextAccessor.java index d3880a9..58f9c43 100644 --- a/client/src/main/java/info/FrostFS/sdk/services/ContextAccessor.java +++ b/client/src/main/java/info/FrostFS/sdk/services/ContextAccessor.java @@ -1,6 +1,6 @@ package info.FrostFS.sdk.services; -import info.FrostFS.sdk.tools.ClientEnvironment; +import info.FrostFS.sdk.jdo.ClientEnvironment; public class ContextAccessor { private final ClientEnvironment context; diff --git a/client/src/main/java/info/FrostFS/sdk/services/FrostFSClient.java b/client/src/main/java/info/FrostFS/sdk/services/FrostFSClient.java index 64ba93c..b0c7f1b 100644 --- a/client/src/main/java/info/FrostFS/sdk/services/FrostFSClient.java +++ b/client/src/main/java/info/FrostFS/sdk/services/FrostFSClient.java @@ -1,29 +1,32 @@ package info.FrostFS.sdk.services; import frostFS.session.Types; -import info.FrostFS.sdk.tools.ClientSettings; -import info.FrostFS.sdk.tools.PutObjectParameters; -import info.FrostFS.sdk.dto.container.Container; -import info.FrostFS.sdk.dto.container.ContainerId; import info.FrostFS.sdk.dto.SessionToken; import info.FrostFS.sdk.dto.Version; +import info.FrostFS.sdk.dto.container.Container; +import info.FrostFS.sdk.dto.container.ContainerId; import info.FrostFS.sdk.dto.netmap.NetmapSnapshot; import info.FrostFS.sdk.dto.netmap.NodeInfo; import info.FrostFS.sdk.dto.object.ObjectFilter; import info.FrostFS.sdk.dto.object.ObjectFrostFS; import info.FrostFS.sdk.dto.object.ObjectHeader; import info.FrostFS.sdk.dto.object.ObjectId; +import info.FrostFS.sdk.jdo.ClientEnvironment; +import info.FrostFS.sdk.jdo.ClientSettings; +import info.FrostFS.sdk.jdo.NetworkSettings; +import info.FrostFS.sdk.jdo.PutObjectParameters; import info.FrostFS.sdk.services.impl.*; -import info.FrostFS.sdk.tools.ClientEnvironment; -import info.FrostFS.sdk.tools.NetworkSettings; import io.grpc.Channel; import java.util.List; -import static info.FrostFS.sdk.GrpcClient.initGrpcChannel; +import static info.FrostFS.sdk.tools.GrpcClient.initGrpcChannel; import static java.util.Objects.isNull; public class FrostFSClient implements ContainerClient, ObjectClient, NetmapClient, SessionClient, ToolsClient { + private static final String ERROR_CLIENT_OPTIONS_INIT = "Options must be initialized."; + private static final String ERROR_VERSION_SUPPORT_TEMPLATE = "FrostFS %s is not supported."; + private final ContainerService containerService; private final NetmapService netmapService; private final ObjectService objectService; @@ -32,7 +35,7 @@ public class FrostFSClient implements ContainerClient, ObjectClient, NetmapClien public FrostFSClient(ClientSettings clientSettings) { if (isNull(clientSettings)) { - throw new IllegalArgumentException("Options must be initialized"); + throw new IllegalArgumentException(ERROR_CLIENT_OPTIONS_INIT); } clientSettings.validate(); @@ -53,9 +56,9 @@ public class FrostFSClient implements ContainerClient, ObjectClient, NetmapClien private void checkFrostFsVersionSupport(Version version) { var localNodeInfo = netmapService.getLocalNodeInfo(); if (!localNodeInfo.getVersion().isSupported(version)) { - var msg = String.format("FrostFS %s is not supported.", localNodeInfo.getVersion()); - System.out.println(msg); - throw new IllegalArgumentException(msg); + throw new IllegalArgumentException( + String.format(ERROR_VERSION_SUPPORT_TEMPLATE, localNodeInfo.getVersion()) + ); } } diff --git a/client/src/main/java/info/FrostFS/sdk/services/NetmapClient.java b/client/src/main/java/info/FrostFS/sdk/services/NetmapClient.java index 80bbf1e..f053dfa 100644 --- a/client/src/main/java/info/FrostFS/sdk/services/NetmapClient.java +++ b/client/src/main/java/info/FrostFS/sdk/services/NetmapClient.java @@ -2,7 +2,7 @@ package info.FrostFS.sdk.services; import info.FrostFS.sdk.dto.netmap.NetmapSnapshot; import info.FrostFS.sdk.dto.netmap.NodeInfo; -import info.FrostFS.sdk.tools.NetworkSettings; +import info.FrostFS.sdk.jdo.NetworkSettings; public interface NetmapClient { NetmapSnapshot getNetmapSnapshot(); diff --git a/client/src/main/java/info/FrostFS/sdk/services/ObjectClient.java b/client/src/main/java/info/FrostFS/sdk/services/ObjectClient.java index f19fb61..96ae2a3 100644 --- a/client/src/main/java/info/FrostFS/sdk/services/ObjectClient.java +++ b/client/src/main/java/info/FrostFS/sdk/services/ObjectClient.java @@ -1,11 +1,11 @@ package info.FrostFS.sdk.services; import info.FrostFS.sdk.dto.container.ContainerId; -import info.FrostFS.sdk.tools.PutObjectParameters; import info.FrostFS.sdk.dto.object.ObjectFilter; import info.FrostFS.sdk.dto.object.ObjectFrostFS; import info.FrostFS.sdk.dto.object.ObjectHeader; import info.FrostFS.sdk.dto.object.ObjectId; +import info.FrostFS.sdk.jdo.PutObjectParameters; public interface ObjectClient { ObjectHeader getObjectHead(ContainerId containerId, ObjectId objectId); diff --git a/client/src/main/java/info/FrostFS/sdk/services/impl/ContainerService.java b/client/src/main/java/info/FrostFS/sdk/services/impl/ContainerService.java index 4383579..a1df64c 100644 --- a/client/src/main/java/info/FrostFS/sdk/services/impl/ContainerService.java +++ b/client/src/main/java/info/FrostFS/sdk/services/impl/ContainerService.java @@ -2,23 +2,23 @@ package info.FrostFS.sdk.services.impl; import frostFS.container.ContainerServiceGrpc; import frostFS.container.Service; -import info.FrostFS.sdk.Verifier; import info.FrostFS.sdk.dto.container.Container; import info.FrostFS.sdk.dto.container.ContainerId; -import info.FrostFS.sdk.mappers.container.ContainerIdMapper; -import info.FrostFS.sdk.mappers.container.ContainerMapper; +import info.FrostFS.sdk.jdo.ClientEnvironment; import info.FrostFS.sdk.mappers.OwnerIdMapper; import info.FrostFS.sdk.mappers.VersionMapper; +import info.FrostFS.sdk.mappers.container.ContainerIdMapper; +import info.FrostFS.sdk.mappers.container.ContainerMapper; import info.FrostFS.sdk.services.ContainerClient; import info.FrostFS.sdk.services.ContextAccessor; -import info.FrostFS.sdk.tools.ClientEnvironment; +import info.FrostFS.sdk.tools.Verifier; import java.util.List; import java.util.stream.Collectors; -import static info.FrostFS.sdk.RequestConstructor.addMetaHeader; -import static info.FrostFS.sdk.RequestSigner.sign; -import static info.FrostFS.sdk.RequestSigner.signRFC6979; +import static info.FrostFS.sdk.tools.RequestConstructor.addMetaHeader; +import static info.FrostFS.sdk.tools.RequestSigner.sign; +import static info.FrostFS.sdk.tools.RequestSigner.signRFC6979; public class ContainerService extends ContextAccessor implements ContainerClient { private final ContainerServiceGrpc.ContainerServiceBlockingStub serviceBlockingStub; diff --git a/client/src/main/java/info/FrostFS/sdk/services/impl/NetmapService.java b/client/src/main/java/info/FrostFS/sdk/services/impl/NetmapService.java index e55c655..135e95b 100644 --- a/client/src/main/java/info/FrostFS/sdk/services/impl/NetmapService.java +++ b/client/src/main/java/info/FrostFS/sdk/services/impl/NetmapService.java @@ -3,20 +3,20 @@ package info.FrostFS.sdk.services.impl; import frostFS.netmap.NetmapServiceGrpc; import frostFS.netmap.Service; import frostFS.netmap.Types; -import info.FrostFS.sdk.Verifier; import info.FrostFS.sdk.dto.netmap.NetmapSnapshot; import info.FrostFS.sdk.dto.netmap.NodeInfo; +import info.FrostFS.sdk.jdo.ClientEnvironment; +import info.FrostFS.sdk.jdo.NetworkSettings; import info.FrostFS.sdk.mappers.netmap.NetmapSnapshotMapper; import info.FrostFS.sdk.mappers.netmap.NodeInfoMapper; import info.FrostFS.sdk.services.ContextAccessor; import info.FrostFS.sdk.services.NetmapClient; -import info.FrostFS.sdk.tools.ClientEnvironment; -import info.FrostFS.sdk.tools.NetworkSettings; +import info.FrostFS.sdk.tools.Verifier; import java.nio.charset.StandardCharsets; -import static info.FrostFS.sdk.RequestConstructor.addMetaHeader; -import static info.FrostFS.sdk.RequestSigner.sign; +import static info.FrostFS.sdk.tools.RequestConstructor.addMetaHeader; +import static info.FrostFS.sdk.tools.RequestSigner.sign; import static java.util.Objects.nonNull; public class NetmapService extends ContextAccessor implements NetmapClient { diff --git a/client/src/main/java/info/FrostFS/sdk/services/impl/ObjectReader.java b/client/src/main/java/info/FrostFS/sdk/services/impl/ObjectReader.java index 8350bd7..116b3c2 100644 --- a/client/src/main/java/info/FrostFS/sdk/services/impl/ObjectReader.java +++ b/client/src/main/java/info/FrostFS/sdk/services/impl/ObjectReader.java @@ -2,11 +2,14 @@ package info.FrostFS.sdk.services.impl; import frostFS.object.Service; import frostFS.object.Types; -import info.FrostFS.sdk.Verifier; +import info.FrostFS.sdk.tools.Verifier; import java.util.Iterator; public class ObjectReader { + public static final String ERROR_UNEXPECTED_STREAM = "unexpected end of stream"; + public static final String ERROR_UNEXPECTED_MESSAGE_TYPE = "unexpected message type"; + public Iterator call; public ObjectReader(Iterator call) { @@ -15,14 +18,14 @@ public class ObjectReader { public Types.Object readHeader() { if (!call.hasNext()) { - throw new IllegalArgumentException("unexpected end of stream"); + throw new IllegalArgumentException(ERROR_UNEXPECTED_STREAM); } var response = call.next(); Verifier.checkResponse(response); if (response.getBody().getObjectPartCase().getNumber() != Service.GetResponse.Body.INIT_FIELD_NUMBER) { - throw new IllegalArgumentException("unexpected message type"); + throw new IllegalArgumentException(ERROR_UNEXPECTED_MESSAGE_TYPE); } return Types.Object.newBuilder() @@ -40,7 +43,7 @@ public class ObjectReader { Verifier.checkResponse(response); if (response.getBody().getObjectPartCase().getNumber() != Service.GetResponse.Body.CHUNK_FIELD_NUMBER) { - throw new IllegalArgumentException("unexpected message type"); + throw new IllegalArgumentException(ERROR_UNEXPECTED_MESSAGE_TYPE); } return response.getBody().getChunk().toByteArray(); diff --git a/client/src/main/java/info/FrostFS/sdk/services/impl/ObjectService.java b/client/src/main/java/info/FrostFS/sdk/services/impl/ObjectService.java index 4fbe78d..c9520e3 100644 --- a/client/src/main/java/info/FrostFS/sdk/services/impl/ObjectService.java +++ b/client/src/main/java/info/FrostFS/sdk/services/impl/ObjectService.java @@ -5,21 +5,22 @@ import com.google.protobuf.ByteString; import frostFS.object.ObjectServiceGrpc; import frostFS.object.Service; import frostFS.refs.Types; -import info.FrostFS.sdk.Verifier; import info.FrostFS.sdk.constants.AppConst; -import info.FrostFS.sdk.dto.container.ContainerId; import info.FrostFS.sdk.dto.Split; +import info.FrostFS.sdk.dto.container.ContainerId; import info.FrostFS.sdk.dto.object.*; -import info.FrostFS.sdk.mappers.*; +import info.FrostFS.sdk.jdo.ClientEnvironment; +import info.FrostFS.sdk.jdo.PutObjectParameters; +import info.FrostFS.sdk.mappers.OwnerIdMapper; +import info.FrostFS.sdk.mappers.VersionMapper; import info.FrostFS.sdk.mappers.container.ContainerIdMapper; import info.FrostFS.sdk.mappers.object.ObjectFilterMapper; +import info.FrostFS.sdk.mappers.object.ObjectFrostFSMapper; import info.FrostFS.sdk.mappers.object.ObjectHeaderMapper; import info.FrostFS.sdk.mappers.object.ObjectIdMapper; -import info.FrostFS.sdk.mappers.object.ObjectFrostFSMapper; import info.FrostFS.sdk.services.ContextAccessor; import info.FrostFS.sdk.services.ObjectClient; -import info.FrostFS.sdk.tools.ClientEnvironment; -import info.FrostFS.sdk.tools.PutObjectParameters; +import info.FrostFS.sdk.tools.Verifier; import org.apache.commons.collections4.CollectionUtils; import java.io.FileInputStream; @@ -29,12 +30,14 @@ import java.util.Arrays; import java.util.List; import static info.FrostFS.sdk.Helper.getSha256; -import static info.FrostFS.sdk.RequestConstructor.addMetaHeader; -import static info.FrostFS.sdk.RequestConstructor.addObjectSessionToken; -import static info.FrostFS.sdk.RequestSigner.sign; +import static info.FrostFS.sdk.tools.RequestConstructor.addMetaHeader; +import static info.FrostFS.sdk.tools.RequestConstructor.addObjectSessionToken; +import static info.FrostFS.sdk.tools.RequestSigner.sign; import static java.util.Objects.nonNull; public class ObjectService extends ContextAccessor implements ObjectClient { + private static final String ERROR_PAYLOAD = "PayloadLength must be specified"; + private final ObjectServiceGrpc.ObjectServiceBlockingStub objectServiceBlockingClient; private final ObjectServiceGrpc.ObjectServiceStub objectServiceClient; private final ObjectTools objectTools; @@ -257,7 +260,7 @@ public class ObjectService extends ContextAccessor implements ObjectClient { var objectSize = (int) Math.min(payloadSize, networkSettings.getMaxObjectSize()); var fullLength = header.getPayloadLength() == 0 ? payloadSize : header.getPayloadLength(); if (fullLength == 0) { - throw new IllegalArgumentException("Payload stream must be able to seek or PayloadLength must be specified"); + throw new IllegalArgumentException(ERROR_PAYLOAD); } var buffer = new byte[objectSize]; diff --git a/client/src/main/java/info/FrostFS/sdk/services/impl/ObjectTools.java b/client/src/main/java/info/FrostFS/sdk/services/impl/ObjectTools.java index 31fbebd..412fa66 100644 --- a/client/src/main/java/info/FrostFS/sdk/services/impl/ObjectTools.java +++ b/client/src/main/java/info/FrostFS/sdk/services/impl/ObjectTools.java @@ -5,17 +5,17 @@ import frostFS.object.Types; import info.FrostFS.sdk.dto.object.ObjectFrostFS; import info.FrostFS.sdk.dto.object.ObjectHeader; import info.FrostFS.sdk.dto.object.ObjectId; -import info.FrostFS.sdk.mappers.object.ObjectHeaderMapper; -import info.FrostFS.sdk.mappers.object.ObjectIdMapper; +import info.FrostFS.sdk.jdo.ClientEnvironment; import info.FrostFS.sdk.mappers.OwnerIdMapper; import info.FrostFS.sdk.mappers.VersionMapper; +import info.FrostFS.sdk.mappers.object.ObjectHeaderMapper; +import info.FrostFS.sdk.mappers.object.ObjectIdMapper; import info.FrostFS.sdk.services.ContextAccessor; import info.FrostFS.sdk.services.ToolsClient; -import info.FrostFS.sdk.tools.ClientEnvironment; import org.apache.commons.collections4.ListUtils; import static info.FrostFS.sdk.Helper.getSha256; -import static info.FrostFS.sdk.RequestSigner.signData; +import static info.FrostFS.sdk.tools.RequestSigner.signData; import static java.util.Objects.nonNull; public class ObjectTools extends ContextAccessor implements ToolsClient { diff --git a/client/src/main/java/info/FrostFS/sdk/services/impl/SearchReader.java b/client/src/main/java/info/FrostFS/sdk/services/impl/SearchReader.java index b0d3620..864d6e5 100644 --- a/client/src/main/java/info/FrostFS/sdk/services/impl/SearchReader.java +++ b/client/src/main/java/info/FrostFS/sdk/services/impl/SearchReader.java @@ -1,7 +1,7 @@ package info.FrostFS.sdk.services.impl; import frostFS.object.Service; -import info.FrostFS.sdk.Verifier; +import info.FrostFS.sdk.tools.Verifier; import java.util.Iterator; import java.util.List; diff --git a/client/src/main/java/info/FrostFS/sdk/services/impl/SessionService.java b/client/src/main/java/info/FrostFS/sdk/services/impl/SessionService.java index cae3cb6..35e5967 100644 --- a/client/src/main/java/info/FrostFS/sdk/services/impl/SessionService.java +++ b/client/src/main/java/info/FrostFS/sdk/services/impl/SessionService.java @@ -4,14 +4,14 @@ import frostFS.session.Service; import frostFS.session.SessionServiceGrpc; import frostFS.session.Types; import info.FrostFS.sdk.dto.SessionToken; +import info.FrostFS.sdk.jdo.ClientEnvironment; import info.FrostFS.sdk.mappers.OwnerIdMapper; import info.FrostFS.sdk.mappers.SessionMapper; import info.FrostFS.sdk.services.ContextAccessor; import info.FrostFS.sdk.services.SessionClient; -import info.FrostFS.sdk.tools.ClientEnvironment; -import static info.FrostFS.sdk.RequestConstructor.addMetaHeader; -import static info.FrostFS.sdk.RequestSigner.sign; +import static info.FrostFS.sdk.tools.RequestConstructor.addMetaHeader; +import static info.FrostFS.sdk.tools.RequestSigner.sign; public class SessionService extends ContextAccessor implements SessionClient { private final SessionServiceGrpc.SessionServiceBlockingStub serviceBlockingStub; diff --git a/client/src/main/java/info/FrostFS/sdk/GrpcClient.java b/client/src/main/java/info/FrostFS/sdk/tools/GrpcClient.java similarity index 73% rename from client/src/main/java/info/FrostFS/sdk/GrpcClient.java rename to client/src/main/java/info/FrostFS/sdk/tools/GrpcClient.java index 9062017..61cfee2 100644 --- a/client/src/main/java/info/FrostFS/sdk/GrpcClient.java +++ b/client/src/main/java/info/FrostFS/sdk/tools/GrpcClient.java @@ -1,4 +1,4 @@ -package info.FrostFS.sdk; +package info.FrostFS.sdk.tools; import io.grpc.Channel; import io.grpc.ChannelCredentials; @@ -10,6 +10,7 @@ import java.net.URISyntaxException; import static java.util.Objects.isNull; public class GrpcClient { + private static final String ERROR_INVALID_HOST_TEMPLATE = "Host %s has invalid format. Error: %s"; public static Channel initGrpcChannel(String host, ChannelCredentials creds) { try { @@ -19,8 +20,7 @@ public class GrpcClient { return channelBuilder.usePlaintext().build(); } catch (URISyntaxException exp) { - var message = String.format("Host %s has invalid format. Error: %s", host, exp.getMessage()); - throw new IllegalArgumentException(message); + throw new IllegalArgumentException(String.format(ERROR_INVALID_HOST_TEMPLATE, host, exp.getMessage())); } } } diff --git a/client/src/main/java/info/FrostFS/sdk/tools/MessageHelper.java b/client/src/main/java/info/FrostFS/sdk/tools/MessageHelper.java new file mode 100644 index 0000000..4e11b06 --- /dev/null +++ b/client/src/main/java/info/FrostFS/sdk/tools/MessageHelper.java @@ -0,0 +1,15 @@ +package info.FrostFS.sdk.tools; + +import com.google.protobuf.Message; +import com.google.protobuf.MessageOrBuilder; + +public class MessageHelper { + + public static Message getField(MessageOrBuilder messageOrBuilder, String fieldName) { + return (Message) messageOrBuilder.getField(messageOrBuilder.getDescriptorForType().findFieldByName(fieldName)); + } + + public static void setField(Message.Builder builder, String fieldName, Object value) { + builder.setField(builder.getDescriptorForType().findFieldByName(fieldName), value); + } +} diff --git a/client/src/main/java/info/FrostFS/sdk/RequestConstructor.java b/client/src/main/java/info/FrostFS/sdk/tools/RequestConstructor.java similarity index 61% rename from client/src/main/java/info/FrostFS/sdk/RequestConstructor.java rename to client/src/main/java/info/FrostFS/sdk/tools/RequestConstructor.java index 28daecc..3d8d02a 100644 --- a/client/src/main/java/info/FrostFS/sdk/RequestConstructor.java +++ b/client/src/main/java/info/FrostFS/sdk/tools/RequestConstructor.java @@ -1,36 +1,37 @@ -package info.FrostFS.sdk; +package info.FrostFS.sdk.tools; -import com.google.protobuf.AbstractMessage; +import com.google.protobuf.Message; import frostFS.session.Types; import info.FrostFS.sdk.dto.MetaHeader; +import info.FrostFS.sdk.jdo.ECDsa; import info.FrostFS.sdk.mappers.MetaHeaderMapper; -import info.FrostFS.sdk.tools.ECDsa; -import static info.FrostFS.sdk.RequestSigner.signMessagePart; +import static info.FrostFS.sdk.constants.FieldConst.META_HEADER_FIELD_NAME; +import static info.FrostFS.sdk.tools.MessageHelper.getField; +import static info.FrostFS.sdk.tools.MessageHelper.setField; +import static info.FrostFS.sdk.tools.RequestSigner.signMessagePart; import static java.util.Objects.isNull; public class RequestConstructor { - public static void addMetaHeader(AbstractMessage.Builder request) { + public static void addMetaHeader(Message.Builder request) { addMetaHeader(request, null); } - public static void addMetaHeader(AbstractMessage.Builder request, Types.RequestMetaHeader metaHeader) { + public static void addMetaHeader(Message.Builder request, Types.RequestMetaHeader metaHeader) { if (isNull(metaHeader) || metaHeader.getSerializedSize() == 0) { metaHeader = MetaHeaderMapper.toGrpcMessage(MetaHeader.getDefault()); - var field = request.getDescriptorForType().findFieldByName("meta_header"); - request.setField(field, metaHeader); + setField(request, META_HEADER_FIELD_NAME, metaHeader); } } - public static void addObjectSessionToken(AbstractMessage.Builder request, + public static void addObjectSessionToken(Message.Builder request, Types.SessionToken sessionToken, frostFS.refs.Types.ContainerID cid, frostFS.refs.Types.ObjectID oid, Types.ObjectSessionContext.Verb verb, ECDsa key) { - var headerField = request.getDescriptorForType().findFieldByName("meta_header"); - var header = (Types.RequestMetaHeader) request.getField(headerField); + var header = (Types.RequestMetaHeader) getField(request, META_HEADER_FIELD_NAME); if (header.getSessionToken().getSerializedSize() > 0) { return; } @@ -46,6 +47,6 @@ public class RequestConstructor { .setBody(body) .build(); - request.setField(headerField, header.toBuilder().setSessionToken(sessionToken).build()); + setField(request, META_HEADER_FIELD_NAME, header.toBuilder().setSessionToken(sessionToken).build()); } } diff --git a/client/src/main/java/info/FrostFS/sdk/RequestSigner.java b/client/src/main/java/info/FrostFS/sdk/tools/RequestSigner.java similarity index 69% rename from client/src/main/java/info/FrostFS/sdk/RequestSigner.java rename to client/src/main/java/info/FrostFS/sdk/tools/RequestSigner.java index a26dadf..daca2cc 100644 --- a/client/src/main/java/info/FrostFS/sdk/RequestSigner.java +++ b/client/src/main/java/info/FrostFS/sdk/tools/RequestSigner.java @@ -1,9 +1,9 @@ -package info.FrostFS.sdk; +package info.FrostFS.sdk.tools; -import com.google.protobuf.AbstractMessage; import com.google.protobuf.ByteString; +import com.google.protobuf.Message; import frostFS.session.Types; -import info.FrostFS.sdk.tools.ECDsa; +import info.FrostFS.sdk.jdo.ECDsa; import org.apache.commons.codec.digest.DigestUtils; import org.bouncycastle.asn1.sec.SECNamedCurves; import org.bouncycastle.asn1.sec.SECObjectIdentifiers; @@ -15,17 +15,22 @@ import org.bouncycastle.crypto.signers.HMacDSAKCalculator; import java.math.BigInteger; import java.security.Signature; +import static info.FrostFS.sdk.constants.CryptoConst.SIGNATURE_ALGORITHM; +import static info.FrostFS.sdk.constants.FieldConst.*; +import static info.FrostFS.sdk.tools.MessageHelper.getField; +import static info.FrostFS.sdk.tools.MessageHelper.setField; import static org.bouncycastle.crypto.util.DigestFactory.createSHA256; import static org.bouncycastle.util.BigIntegers.asUnsignedByteArray; public class RequestSigner { + public static final String ERROR_UNSUPPORTED_TYPE_TEMPLATE = "Unsupported message type: %s"; public static final int RFC6979_SIGNATURE_SIZE = 64; public static byte[] signData(ECDsa key, byte[] data) { var hash = new byte[65]; hash[0] = 0x04; try { - Signature signature = Signature.getInstance("NONEwithECDSAinP1363Format"); + Signature signature = Signature.getInstance(SIGNATURE_ALGORITHM); signature.initSign(key.getPrivateKey()); signature.update(DigestUtils.sha512(data)); byte[] sig = signature.sign(); @@ -62,7 +67,7 @@ public class RequestSigner { return signature; } - public static frostFS.refs.Types.SignatureRFC6979 signRFC6979(ECDsa key, AbstractMessage message) { + public static frostFS.refs.Types.SignatureRFC6979 signRFC6979(ECDsa key, Message message) { return frostFS.refs.Types.SignatureRFC6979.newBuilder() .setKey(ByteString.copyFrom(key.getPublicKeyByte())) .setSign(ByteString.copyFrom(signRFC6979(key, message.toByteArray()))) @@ -76,7 +81,7 @@ public class RequestSigner { .build(); } - public static frostFS.refs.Types.Signature signMessagePart(ECDsa key, AbstractMessage data) { + public static frostFS.refs.Types.Signature signMessagePart(ECDsa key, Message data) { var data2Sign = data.getSerializedSize() == 0 ? new byte[]{} : data.toByteArray(); return frostFS.refs.Types.Signature.newBuilder() .setKey(ByteString.copyFrom(key.getPublicKeyByte())) @@ -84,39 +89,32 @@ public class RequestSigner { .build(); } - public static void sign(AbstractMessage.Builder request, ECDsa key) { - var meta = (AbstractMessage) request.getField(request.getDescriptorForType().findFieldByName("meta_header")); - var body = (AbstractMessage) request.getField(request.getDescriptorForType().findFieldByName("body")); - var verify = (AbstractMessage) request.getField(request.getDescriptorForType().findFieldByName("verify_header")); + public static void sign(Message.Builder request, ECDsa key) { + var meta = getField(request, META_HEADER_FIELD_NAME); + var body = getField(request, BODY_FIELD_NAME); + var verify = getField(request, VERIFY_HEADER_FIELD_NAME); + var verifyOrigin = getField(verify, ORIGIN_FIELD_NAME); - AbstractMessage.Builder verifyBuilder; + Message.Builder verifyBuilder; if (verify instanceof Types.RequestVerificationHeader) { verifyBuilder = Types.RequestVerificationHeader.newBuilder(); } else if (verify instanceof Types.ResponseVerificationHeader) { verifyBuilder = Types.ResponseVerificationHeader.newBuilder(); } else { - throw new IllegalArgumentException("Unsopported message type"); - } - - var verifyOrigin = (AbstractMessage) verify.getField(verify.getDescriptorForType().findFieldByName("origin")); - if (verifyOrigin.getSerializedSize() == 0) { - verifyBuilder.setField( - verifyBuilder.getDescriptorForType().findFieldByName("body_signature"), - signMessagePart(key, body) + throw new IllegalArgumentException( + String.format(ERROR_UNSUPPORTED_TYPE_TEMPLATE, verify.getClass().getName()) ); - } else { - verifyBuilder.setField(verifyBuilder.getDescriptorForType().findFieldByName("origin"), verifyOrigin); } - verifyBuilder.setField( - verifyBuilder.getDescriptorForType().findFieldByName("meta_signature"), - signMessagePart(key, meta) - ); - verifyBuilder.setField( - verifyBuilder.getDescriptorForType().findFieldByName("origin_signature"), - signMessagePart(key, verifyOrigin) - ); + if (verifyOrigin.getSerializedSize() == 0) { + setField(verifyBuilder, BODY_SIGNATURE_FIELD_NAME, signMessagePart(key, body)); + } else { + setField(verifyBuilder, ORIGIN_FIELD_NAME, verifyOrigin); + } - request.setField(request.getDescriptorForType().findFieldByName("verify_header"), verifyBuilder.build()); + setField(verifyBuilder, META_SIGNATURE_FIELD_NAME, signMessagePart(key, meta)); + setField(verifyBuilder, ORIGIN_SIGNATURE_FIELD_NAME, signMessagePart(key, verifyOrigin)); + setField(request, VERIFY_HEADER_FIELD_NAME, verifyBuilder.build()); } + } diff --git a/client/src/main/java/info/FrostFS/sdk/Verifier.java b/client/src/main/java/info/FrostFS/sdk/tools/Verifier.java similarity index 70% rename from client/src/main/java/info/FrostFS/sdk/Verifier.java rename to client/src/main/java/info/FrostFS/sdk/tools/Verifier.java index e0c37ec..14e7327 100644 --- a/client/src/main/java/info/FrostFS/sdk/Verifier.java +++ b/client/src/main/java/info/FrostFS/sdk/tools/Verifier.java @@ -1,7 +1,7 @@ -package info.FrostFS.sdk; +package info.FrostFS.sdk.tools; -import com.google.protobuf.AbstractMessage; -import frostFS.refs.Types; +import com.google.protobuf.Message; +import frostFS.session.Types; import info.FrostFS.sdk.mappers.StatusMapper; import org.apache.commons.codec.digest.DigestUtils; import org.bouncycastle.asn1.sec.SECNamedCurves; @@ -17,17 +17,20 @@ import java.security.Signature; import java.util.Arrays; import static info.FrostFS.sdk.KeyExtension.getPublicKeyFromBytes; +import static info.FrostFS.sdk.constants.CryptoConst.SIGNATURE_ALGORITHM; +import static info.FrostFS.sdk.constants.FieldConst.*; +import static info.FrostFS.sdk.tools.MessageHelper.getField; import static java.util.Objects.isNull; import static org.bouncycastle.crypto.util.DigestFactory.createSHA256; import static org.bouncycastle.util.BigIntegers.fromUnsignedByteArray; public class Verifier { + public static final String ERROR_WRONG_SIG_SIZE_TEMPLATE = "Wrong signature size. Expected length=%s, actual=%s"; + public static final String ERROR_INVALID_RESPONSE = "Invalid response"; public static final int RFC6979_SIG_SIZE = 64; - public static boolean verifyRFC6979(Types.SignatureRFC6979 signature, AbstractMessage message) { - return verifyRFC6979( - signature.getKey().toByteArray(), message.toByteArray(), signature.getSign().toByteArray() - ); + public static boolean verifyRFC6979(frostFS.refs.Types.SignatureRFC6979 signature, Message data) { + return verifyRFC6979(signature.getKey().toByteArray(), data.toByteArray(), signature.getSign().toByteArray()); } public static boolean verifyRFC6979(byte[] publicKey, byte[] data, byte[] sig) { @@ -49,8 +52,7 @@ public class Verifier { private static BigInteger[] decodeSignature(byte[] sig) { if (sig.length != RFC6979_SIG_SIZE) { throw new IllegalArgumentException( - String.format("Wrong signature size. Expected length=%s, actual=%s", - RFC6979_SIG_SIZE, sig.length) + String.format(ERROR_WRONG_SIG_SIZE_TEMPLATE, RFC6979_SIG_SIZE, sig.length) ); } @@ -61,42 +63,40 @@ public class Verifier { return rs; } - public static void checkResponse(AbstractMessage response) { + public static void checkResponse(Message response) { if (!verify(response)) { - throw new IllegalArgumentException("Invalid response"); + throw new IllegalArgumentException(ERROR_INVALID_RESPONSE); } - var metaHeader = (frostFS.session.Types.ResponseMetaHeader) response - .getField(response.getDescriptorForType().findFieldByName("meta_header")); + + var metaHeader = (Types.ResponseMetaHeader) getField(response, META_HEADER_FIELD_NAME); var status = StatusMapper.toModel(metaHeader.getStatus()); if (!status.isSuccess()) { throw new IllegalArgumentException(status.toString()); } } - public static boolean verify(AbstractMessage message) { - var body = (AbstractMessage) message.getField(message.getDescriptorForType().findFieldByName("body")); - var metaHeader = (frostFS.session.Types.ResponseMetaHeader) - message.getField(message.getDescriptorForType().findFieldByName("meta_header")); - var verifyHeader = (frostFS.session.Types.ResponseVerificationHeader) - message.getField(message.getDescriptorForType().findFieldByName("verify_header")); + public static boolean verify(Message response) { + var body = getField(response, BODY_FIELD_NAME); + var metaHeader = (Types.ResponseMetaHeader) getField(response, META_HEADER_FIELD_NAME); + var verifyHeader = (Types.ResponseVerificationHeader) getField(response, VERIFY_HEADER_FIELD_NAME); return verifyMatryoshkaLevel(body, metaHeader, verifyHeader); } - public static boolean verifyMatryoshkaLevel(AbstractMessage body, + public static boolean verifyMatryoshkaLevel(Message data, frostFS.session.Types.ResponseMetaHeader meta, frostFS.session.Types.ResponseVerificationHeader verification) { if (!verifyMessagePart(verification.getMetaSignature(), meta)) return false; var origin = verification.getOrigin(); if (!verifyMessagePart(verification.getOriginSignature(), origin)) return false; if (origin.getSerializedSize() == 0) { - return verifyMessagePart(verification.getBodySignature(), body); + return verifyMessagePart(verification.getBodySignature(), data); } return verification.getBodySignature().getSerializedSize() == 0 - && verifyMatryoshkaLevel(body, meta.getOrigin(), origin); + && verifyMatryoshkaLevel(data, meta.getOrigin(), origin); } - public static boolean verifyMessagePart(Types.Signature sig, AbstractMessage data) { + public static boolean verifyMessagePart(frostFS.refs.Types.Signature sig, Message data) { if (sig.getSerializedSize() == 0 || sig.getKey().isEmpty() || sig.getSign().isEmpty()) return false; var publicKey = getPublicKeyFromBytes(sig.getKey().toByteArray()); @@ -107,7 +107,7 @@ public class Verifier { public static boolean verifyData(PublicKey publicKey, byte[] data, byte[] sig) { try { - Signature signature = Signature.getInstance("NONEwithECDSAinP1363Format"); + Signature signature = Signature.getInstance(SIGNATURE_ALGORITHM); signature.initVerify(publicKey); signature.update(DigestUtils.sha512(data)); return signature.verify(Arrays.copyOfRange(sig, 1, sig.length)); diff --git a/cryptography/pom.xml b/cryptography/pom.xml index 9c18d69..f92accd 100644 --- a/cryptography/pom.xml +++ b/cryptography/pom.xml @@ -1,6 +1,6 @@ - 4.0.0 diff --git a/cryptography/src/main/java/info/FrostFS/sdk/Helper.java b/cryptography/src/main/java/info/FrostFS/sdk/Helper.java index fb11ac2..083121b 100644 --- a/cryptography/src/main/java/info/FrostFS/sdk/Helper.java +++ b/cryptography/src/main/java/info/FrostFS/sdk/Helper.java @@ -1,7 +1,7 @@ package info.FrostFS.sdk; -import com.google.protobuf.AbstractMessage; import com.google.protobuf.ByteString; +import com.google.protobuf.Message; import org.bouncycastle.crypto.digests.RIPEMD160Digest; import java.math.BigInteger; @@ -30,7 +30,7 @@ public class Helper { return getSha256Instance().digest(value); } - public static ByteString getSha256(AbstractMessage value) { + public static ByteString getSha256(Message value) { return ByteString.copyFrom(getSha256(value.toByteArray())); } diff --git a/models/pom.xml b/models/pom.xml index 7f9af60..1f04f5e 100644 --- a/models/pom.xml +++ b/models/pom.xml @@ -1,6 +1,6 @@ - 4.0.0 diff --git a/models/src/main/java/info/FrostFS/sdk/constants/FieldConst.java b/models/src/main/java/info/FrostFS/sdk/constants/FieldConst.java new file mode 100644 index 0000000..761258a --- /dev/null +++ b/models/src/main/java/info/FrostFS/sdk/constants/FieldConst.java @@ -0,0 +1,11 @@ +package info.FrostFS.sdk.constants; + +public class FieldConst { + public static final String META_HEADER_FIELD_NAME = "meta_header"; + public static final String META_SIGNATURE_FIELD_NAME = "meta_signature"; + public static final String BODY_FIELD_NAME = "body"; + public static final String BODY_SIGNATURE_FIELD_NAME = "body_signature"; + public static final String ORIGIN_FIELD_NAME = "origin"; + public static final String ORIGIN_SIGNATURE_FIELD_NAME = "origin_signature"; + public static final String VERIFY_HEADER_FIELD_NAME = "verify_header"; +}