Polishing.

Add since and author tags. Remove unused imports. Reorder methods.

See gh-745
Original pull request: gh-791
This commit is contained in:
Mark Paluch
2023-10-16 14:48:13 +02:00
parent 253e8665d4
commit d8a7b05cc2
4 changed files with 38 additions and 26 deletions

View File

@@ -17,8 +17,8 @@ package org.springframework.vault.support;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.Base64;
import java.util.Objects;
import org.springframework.util.Assert;
/**
@@ -27,6 +27,7 @@ import org.springframework.util.Assert;
*
* @author Praveendra Singh
* @author Mark Paluch
* @author Nanne Baars
* @since 1.1
*/
public class Plaintext {

View File

@@ -24,6 +24,7 @@ import org.springframework.util.Assert;
* @author Luander Ribeiro
* @author Mark Paluch
* @author My-Lan Aragon
* @author Nanne Baars
* @since 2.0
*/
public class VaultSignRequest {
@@ -101,6 +102,7 @@ public class VaultSignRequest {
/**
* @return true if the input is already hashed.
* @since 3.1
*/
public boolean isPrehashed() {
return this.prehashed;
@@ -148,6 +150,19 @@ public class VaultSignRequest {
return this;
}
/**
* Set to {@literal true} when the input is already hashed. If the key type is
* {@literal rsa-2048}, {@literal rsa-3072}, or {@literal rsa-4096} then specify
* the algorithm used to hash the input through {@link #hashAlgorithm(String)}.
* @param prehashed whether the input is already hashed.
* @return {@code this} {@link VaultSignRequestBuilder}.
* @since 3.1
*/
public VaultSignRequestBuilder prehashed(boolean prehashed) {
this.prehashed = prehashed;
return this;
}
/**
* Configure the signature algorithm to be used for the operation when using an
* RSA key.
@@ -177,24 +192,13 @@ public class VaultSignRequest {
return signatureAlgorithm(algorithm);
}
/**
* Set to true when the input is already hashed. If the key type is rsa-2048,
* rsa-3072 or rsa-4096, then the algorithm used to hash the input should be
* indicated by the hash_algorithm parameter.
* @param prehashed whether the input is already hashed
* @return {@code this} {@link VaultSignRequestBuilder}.
*/
public VaultSignRequestBuilder prehashed(boolean prehashed) {
this.prehashed = prehashed;
return this;
}
/**
* Build a new {@link VaultSignRequest} instance. Requires
* {@link #plaintext(Plaintext)} to be configured.
* @return a new {@link VaultSignRequest}.
*/
public VaultSignRequest build() {
Assert.notNull(this.plaintext, "Plaintext input must not be null");
return new VaultSignRequest(this.plaintext, this.hashAlgorithm, this.signatureAlgorithm, this.prehashed);

View File

@@ -15,7 +15,6 @@
*/
package org.springframework.vault.support;
import org.checkerframework.checker.units.qual.A;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
@@ -26,6 +25,7 @@ import org.springframework.util.Assert;
* @author Mark Paluch
* @author My-Lan Aragon
* @author James Luke
* @author Nanne Baars
* @since 2.0
*/
public class VaultSignatureVerificationRequest {
@@ -141,7 +141,8 @@ public class VaultSignatureVerificationRequest {
}
/**
* @return true if the input is already hashed.
* @return {@literal true} if the input is already hashed.
* @since 3.1
*/
public boolean isPrehashed() {
return this.prehashed;
@@ -226,6 +227,19 @@ public class VaultSignatureVerificationRequest {
return this;
}
/**
* Set to {@literal true} when the input is already hashed. If the key type is
* {@literal rsa-2048}, {@literal rsa-3072}, or {@literal rsa-4096} then specify
* the algorithm used to hash the input through {@link #hashAlgorithm(String)}.
* @param prehashed whether the input is already hashed.
* @return {@code this} {@link VaultSignatureVerificationRequestBuilder}.
* @since 3.1
*/
public VaultSignatureVerificationRequestBuilder prehashed(boolean prehashed) {
this.prehashed = prehashed;
return this;
}
/**
* Configure the signature algorithm to be used for the operation when using an
* RSA key.
@@ -243,11 +257,6 @@ public class VaultSignatureVerificationRequest {
return this;
}
public VaultSignatureVerificationRequestBuilder prehashed(boolean prehashed) {
this.prehashed = prehashed;
return this;
}
/**
* Configure the algorithm to be used for the operation.
* @param algorithm Specify the algorithm to be used for the operation. Supported

View File

@@ -15,16 +15,12 @@
*/
package org.springframework.vault.core;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.fail;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.IntStream;
import java.util.stream.Stream;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -32,6 +28,7 @@ import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;
@@ -57,7 +54,6 @@ import org.springframework.vault.util.IntegrationTestSupport;
import org.springframework.vault.util.RequiresVaultVersion;
import org.springframework.vault.util.Version;
import static org.assertj.core.api.Assertions.*;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.fail;
@@ -812,6 +808,7 @@ class VaultTransitTemplateIntegrationTests extends IntegrationTestSupport {
@Test
@RequiresVaultVersion(SIGN_VERIFY_INTRODUCED_IN_VERSION)
void signAndVerifyWithPrehashedInput() {
String keyName = createEcdsaP256Key();
Plaintext plaintext = Plaintext.of("P8m2iUWdc4+MiKOkiqnjNUIBa3pAUuABqqU2/KdIE8s=");
VaultSignRequest signRequest = VaultSignRequest.builder()
@@ -836,6 +833,7 @@ class VaultTransitTemplateIntegrationTests extends IntegrationTestSupport {
@Test
@RequiresVaultVersion(SIGN_VERIFY_INTRODUCED_IN_VERSION)
void signWithPrehashedAndVerifyWithoutShouldFail() {
String keyName = createEcdsaP256Key();
Plaintext plaintext = Plaintext.of("P8m2iUWdc4+MiKOkiqnjNUIBa3pAUuABqqU2/KdIE8s=");
VaultSignRequest signRequest = VaultSignRequest.builder()