8343772: Expected IAPE not thrown in KDF.getInstance (TCK)
Reviewed-by: valeriep
This commit is contained in:
parent
fac89f471c
commit
2c7bea1cb2
@ -396,7 +396,7 @@ public final class KDF {
|
||||
InvalidAlgorithmParameterException {
|
||||
Objects.requireNonNull(algorithm, "algorithm must not be null");
|
||||
Objects.requireNonNull(provider, "provider must not be null");
|
||||
|
||||
try {
|
||||
Instance instance = GetInstance.getInstance("KDF", KDFSpi.class,
|
||||
algorithm,
|
||||
kdfParameters,
|
||||
@ -407,8 +407,10 @@ public final class KDF {
|
||||
throw new NoSuchProviderException(msg);
|
||||
}
|
||||
return new KDF(new Delegate((KDFSpi) instance.impl,
|
||||
instance.provider), algorithm
|
||||
);
|
||||
instance.provider), algorithm);
|
||||
} catch (NoSuchAlgorithmException nsae) {
|
||||
return handleException(nsae);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -444,6 +446,7 @@ public final class KDF {
|
||||
InvalidAlgorithmParameterException {
|
||||
Objects.requireNonNull(algorithm, "algorithm must not be null");
|
||||
Objects.requireNonNull(provider, "provider must not be null");
|
||||
try {
|
||||
Instance instance = GetInstance.getInstance("KDF", KDFSpi.class,
|
||||
algorithm,
|
||||
kdfParameters,
|
||||
@ -454,8 +457,20 @@ public final class KDF {
|
||||
throw new SecurityException(msg);
|
||||
}
|
||||
return new KDF(new Delegate((KDFSpi) instance.impl,
|
||||
instance.provider), algorithm
|
||||
);
|
||||
instance.provider), algorithm);
|
||||
} catch (NoSuchAlgorithmException nsae) {
|
||||
return handleException(nsae);
|
||||
}
|
||||
}
|
||||
|
||||
private static KDF handleException(NoSuchAlgorithmException e)
|
||||
throws NoSuchAlgorithmException,
|
||||
InvalidAlgorithmParameterException {
|
||||
Throwable cause = e.getCause();
|
||||
if (cause instanceof InvalidAlgorithmParameterException iape) {
|
||||
throw iape;
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -671,7 +686,8 @@ public final class KDF {
|
||||
if (hasOne) throw new InvalidAlgorithmParameterException(
|
||||
"The KDFParameters supplied could not be used in combination "
|
||||
+ "with the supplied algorithm for the selected Provider");
|
||||
else throw new NoSuchAlgorithmException();
|
||||
else throw new NoSuchAlgorithmException(
|
||||
"No available provider supports the specified algorithm");
|
||||
}
|
||||
|
||||
private static boolean checkSpiNonNull(Delegate d) {
|
||||
|
@ -69,6 +69,8 @@ public class HKDFExhaustiveTest {
|
||||
private static final int LARGE_LENGTH = 1000;
|
||||
private static final int NEGATIVE_LENGTH = -1;
|
||||
|
||||
static class TestKDFParams implements KDFParameters {}
|
||||
|
||||
private static final KdfVerifier<String, String, AlgorithmParameterSpec> KdfGetInstanceVerifier =
|
||||
(a, p, s) -> {
|
||||
|
||||
@ -304,6 +306,12 @@ public class HKDFExhaustiveTest {
|
||||
Utils.runAndCheckException(
|
||||
() -> KDF.getInstance(KDF_ALGORITHMS[0], null, INVALID_STRING),
|
||||
NoSuchProviderException.class);
|
||||
Utils.runAndCheckException(
|
||||
() -> KDF.getInstance(KDF_ALGORITHMS[0], new TestKDFParams(), SUNJCE),
|
||||
InvalidAlgorithmParameterException.class);
|
||||
Utils.runAndCheckException(
|
||||
() -> KDF.getInstance(KDF_ALGORITHMS[0], new TestKDFParams(), SUNJCE_PROVIDER),
|
||||
InvalidAlgorithmParameterException.class);
|
||||
|
||||
// getInstance(String algorithm, KDFParameters kdfParameters, Provider provider)
|
||||
Utils.runAndCheckException(
|
||||
|
Loading…
Reference in New Issue
Block a user