diff --git a/README.md b/README.md index bdaf1de..3a5efa6 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,8 @@ Core Interfaces's Maven group ID is `io.apimatic`, and its artifact ID is `core- | [`ExceptionCreator`](./src/main/java/io/apimatic/coreinterfaces/type/functional/ExceptionCreator.java) | Functional interface to create the SDK exception | | [`Serializer`](./src/main/java/io/apimatic/coreinterfaces/type/functional/Serializer.java) | Functional interface to apply the serialization function | | [`ContextInitializer`](./src/main/java/io/apimatic/coreinterfaces/type/functional/ContextInitializer.java) | Functional Interface to apply the context initialization function for the response models | +| [`SignatureVerifier`](./src/main/java/io/apimatic/coreinterfaces/security/SignatureVerifier.java) | Defines a contract for verifying the signature of an HTTP request | +| [`VerificationResult`](./src/main/java/io/apimatic/coreinterfaces/security/VerificationResult.java) | Represents the result of an operation that can either succeed or fail with an error message | ## Enumerations diff --git a/sonar-project.properties b/sonar-project.properties index 88ed11e..b907db9 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -6,4 +6,7 @@ sonar.sourceEncoding=UTF-8 sonar.sources=src/main/java -sonar.java.binaries=target/classes \ No newline at end of file +sonar.java.binaries=target/classes + +# Skip coverage +sonar.coverage.exclusions=** \ No newline at end of file diff --git a/src/main/java/io/apimatic/coreinterfaces/security/SignatureVerifier.java b/src/main/java/io/apimatic/coreinterfaces/security/SignatureVerifier.java new file mode 100644 index 0000000..36535bb --- /dev/null +++ b/src/main/java/io/apimatic/coreinterfaces/security/SignatureVerifier.java @@ -0,0 +1,19 @@ +package io.apimatic.coreinterfaces.security; + +import io.apimatic.coreinterfaces.http.request.Request; + +import java.util.concurrent.CompletableFuture; + +/** + * Defines a contract for verifying the signature of an HTTP request. + */ +public interface SignatureVerifier { + + /** + * Verifies the signature of the specified HTTP request. + * + * @param request The HTTP request data to verify. + * @return A {@link CompletableFuture} containing the outcome of the verification process. + */ + CompletableFuture verifyAsync(Request request); +} diff --git a/src/main/java/io/apimatic/coreinterfaces/security/VerificationResult.java b/src/main/java/io/apimatic/coreinterfaces/security/VerificationResult.java new file mode 100644 index 0000000..6ad70fa --- /dev/null +++ b/src/main/java/io/apimatic/coreinterfaces/security/VerificationResult.java @@ -0,0 +1,66 @@ +package io.apimatic.coreinterfaces.security; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +/** + * Represents the result of an operation that can either succeed + * or fail with an error message. + */ +public interface VerificationResult { + + /** + * Indicates whether the verification succeeded. + * + * @return true if successful; false otherwise. + */ + boolean isSuccess(); + + /** + * Gets the collection of error messages, if any. + * Always returns a read-only list (never null). + * + * @return unmodifiable list of errors, empty if success. + */ + List getErrors(); + + /** + * Creates a successful result. + * + * @return a success result + */ + static VerificationResult success() { + return new VerificationResult() { + @Override + public boolean isSuccess() { + return true; + } + + @Override + public List getErrors() { + return Collections.emptyList(); + } + }; + } + + /** + * Creates a failed result with the given error messages. + * + * @param errors list of error messages + * @return a failure result + */ + static VerificationResult failure(String... errors) { + return new VerificationResult() { + @Override + public boolean isSuccess() { + return false; + } + + @Override + public List getErrors() { + return Collections.unmodifiableList(errors != null + ? Arrays.asList(errors) : Collections.emptyList()); + } + }; + } +}