Skip to content

Commit

Permalink
Remove use of optionals when calculating option overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
kdubb committed May 6, 2021
1 parent ebdc0a5 commit 2f3498a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,10 @@ private void signBatch(String keyName, int keyVersion, List<SigningRequestResult
}

if (options != null) {
hashAlgorithm = options.getHashAlgorithm().orElse(hashAlgorithm);
body.signatureAlgorithm = options.getSignatureAlgorithm().orElse(body.signatureAlgorithm);
body.prehashed = options.getPrehashed().orElse(body.prehashed);
body.marshalingAlgorithm = options.getMarshalingAlgorithm().orElse(null);
hashAlgorithm = defaultIfNull(options.getHashAlgorithm(), hashAlgorithm);
body.signatureAlgorithm = defaultIfNull(options.getSignatureAlgorithm(), body.signatureAlgorithm);
body.prehashed = defaultIfNull(options.getPrehashed(), body.prehashed);
body.marshalingAlgorithm = defaultIfNull(options.getMarshalingAlgorithm(), null);
}

VaultTransitSign sign = vaultInternalTransitSecretEngine.sign(getToken(), keyName, hashAlgorithm, body);
Expand Down Expand Up @@ -344,10 +344,10 @@ private List<VerificationResult> verifyBatch(String keyName, List<VerificationRe
}

if (options != null) {
hashAlgorithm = options.getHashAlgorithm().orElse(hashAlgorithm);
body.signatureAlgorithm = options.getSignatureAlgorithm().orElse(body.signatureAlgorithm);
body.prehashed = options.getPrehashed().orElse(body.prehashed);
body.marshalingAlgorithm = options.getMarshalingAlgorithm().orElse(null);
hashAlgorithm = defaultIfNull(options.getHashAlgorithm(), hashAlgorithm);
body.signatureAlgorithm = defaultIfNull(options.getSignatureAlgorithm(), body.signatureAlgorithm);
body.prehashed = defaultIfNull(options.getPrehashed(), body.prehashed);
body.marshalingAlgorithm = defaultIfNull(options.getMarshalingAlgorithm(), null);
}

VaultTransitVerify verify = vaultInternalTransitSecretEngine.verify(getToken(), keyName, hashAlgorithm, body);
Expand Down Expand Up @@ -521,4 +521,10 @@ private <K, T, V> Map<K, V> zip(List<K> keys, List<T> values, Function<T, V> f)
return map;
}

private <T> T defaultIfNull(T value, T defaultValue) {
if (value != null)
return value;
return defaultValue;
}

}
Original file line number Diff line number Diff line change
@@ -1,43 +1,41 @@
package io.quarkus.vault.transit;

import java.util.Optional;

public class SignVerifyOptions {

private String signatureAlgorithm;
private String hashAlgorithm;
private Boolean prehashed;
private String marshalingAlgorithm;

public Optional<String> getSignatureAlgorithm() {
return Optional.ofNullable(signatureAlgorithm);
public String getSignatureAlgorithm() {
return signatureAlgorithm;
}

public SignVerifyOptions setSignatureAlgorithm(String signatureAlgorithm) {
this.signatureAlgorithm = signatureAlgorithm;
return this;
}

public Optional<String> getHashAlgorithm() {
return Optional.ofNullable(hashAlgorithm);
public String getHashAlgorithm() {
return hashAlgorithm;
}

public SignVerifyOptions setHashAlgorithm(String hashAlgorithm) {
this.hashAlgorithm = hashAlgorithm;
return this;
}

public Optional<Boolean> getPrehashed() {
return Optional.ofNullable(prehashed);
public Boolean getPrehashed() {
return prehashed;
}

public SignVerifyOptions setPrehashed(Boolean prehashed) {
this.prehashed = prehashed;
return this;
}

public Optional<String> getMarshalingAlgorithm() {
return Optional.ofNullable(marshalingAlgorithm);
public String getMarshalingAlgorithm() {
return marshalingAlgorithm;
}

public SignVerifyOptions setMarshalingAlgorithm(String marshalingAlgorithm) {
Expand Down

0 comments on commit 2f3498a

Please sign in to comment.