Skip to content

Commit

Permalink
autodetect sigAlgo when it's null by algo
Browse files Browse the repository at this point in the history
  • Loading branch information
max402 committed May 15, 2024
1 parent 6e12fd4 commit 6bce582
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.Getter;

import java.security.spec.AlgorithmParameterSpec;
import java.util.Locale;

@Getter
@Builder(toBuilder = true)
Expand Down Expand Up @@ -35,6 +36,10 @@ static KeyPairEncryptionTemplate of(String algo, Integer size, String sigAlgo, S

if (null != algo) {
result = result.toBuilder().algo(algo).build();

if (null == sigAlgo) {
sigAlgo = autodetectAlgorithm(algo);
}
}

if (null != size) {
Expand All @@ -55,4 +60,13 @@ static KeyPairEncryptionTemplate of(String algo, Integer size, String sigAlgo, S

return result;
}

private static String autodetectAlgorithm(String algo) {
return switch (algo.toUpperCase(Locale.US)) {
case "DSA" -> "SHA256withDSA";
case "RSA" -> "SHA256WithRSA";
case "ECDH" -> "SHA256WITHECDSA";
default -> null;

Check warning on line 69 in api/src/main/java/de/adorsys/keymanagement/api/types/template/generated/KeyPairEncryptionTemplate.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/de/adorsys/keymanagement/api/types/template/generated/KeyPairEncryptionTemplate.java#L67-L69

Added lines #L67 - L69 were not covered by tests
};
}
}

0 comments on commit 6bce582

Please sign in to comment.