Skip to content

Commit

Permalink
better exception messages
Browse files Browse the repository at this point in the history
  • Loading branch information
wangweij committed Jan 8, 2025
1 parent 7027918 commit 45e3266
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -380,10 +380,9 @@ protected SecretKey engineGenerateSecret(String algorithm)
}

if (!KeyUtil.isSupportedKeyAgreementOutputAlgorithm(algorithm) &&
!AllowKDF.VALUE) {

throw new NoSuchAlgorithmException("Unsupported secret key "
+ "algorithm: " + algorithm);
!AllowKDF.VALUE) {
throw new NoSuchAlgorithmException(
"Unsupported secret key algorithm: " + algorithm);
}

byte[] secret = engineGenerateSecret();
Expand Down Expand Up @@ -429,7 +428,7 @@ protected SecretKey engineGenerateSecret(String algorithm)
}
} else {
throw new NoSuchAlgorithmException(
"Unsupported secret key algorithm " + algorithm);
"Unsupported secret key algorithm: " + algorithm);
}
}
}
2 changes: 1 addition & 1 deletion src/java.base/share/classes/javax/crypto/KeyAgreement.java
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ public final int generateSecret(byte[] sharedSecret, int offset)
* may be adjusted to be compatible with the specified algorithm,
* regardless of whether the key is extractable. If {@code algorithm}
* is specified as "Generic" and it is supported by the implementation,
* the full shared secret will be returned.
* the full shared secret is returned.
*
* @exception IllegalStateException if this key agreement has not been
* initialized or if {@code doPhase} has not been called to supply the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ protected abstract int engineGenerateSecret(byte[] sharedSecret,
* may be adjusted to be compatible with the specified algorithm,
* regardless of whether the key is extractable. If {@code algorithm}
* is specified as "Generic" and it is supported by the implementation,
* the full shared secret will be returned.
* the full shared secret is returned.
*
* @exception IllegalStateException if this key agreement has not been
* initialized or if {@code doPhase} has not been called to supply the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ protected SecretKey engineGenerateSecret(String algorithm)
}
if (!KeyUtil.isSupportedKeyAgreementOutputAlgorithm(algorithm)) {
throw new NoSuchAlgorithmException(
"Unsupported secret key algorithm " + algorithm);
"Unsupported secret key algorithm: " + algorithm);
}
return new SecretKeySpec(engineGenerateSecret(), algorithm);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ protected SecretKey engineGenerateSecret(String algorithm)

if (!KeyUtil.isSupportedKeyAgreementOutputAlgorithm(algorithm)) {
throw new NoSuchAlgorithmException(
"Unsupported secret key algorithm " + algorithm);
"Unsupported secret key algorithm: " + algorithm);
}
return new SecretKeySpec(engineGenerateSecret(), algorithm);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ protected SecretKey engineGenerateSecret(String algorithm)
}
if (!KeyUtil.isSupportedKeyAgreementOutputAlgorithm(algorithm)) {
throw new NoSuchAlgorithmException(
"Unsupported secret key algorithm " + algorithm);
"Unsupported secret key algorithm: " + algorithm);
}
return nativeGenerateSecret(algorithm);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@ protected SecretKey engineGenerateSecret(String algorithm)

if (KeyUtil.isSupportedKeyAgreementOutputAlgorithm(algorithm)) {
// For now, only perform native derivation for TlsPremasterSecret
// as that is required for FIPS compliance and Generic for KDF.
// and Generic algorithms. TlsPremasterSecret is required for
// FIPS compliance and Generic is required for input to KDF.
// For other algorithms, there are unresolved issues regarding
// how this should work in JCE plus a Solaris truncation bug.
// (bug not yet filed).
Expand All @@ -279,7 +280,7 @@ protected SecretKey engineGenerateSecret(String algorithm)

if (!AllowKDF.VALUE) {
throw new NoSuchAlgorithmException(
"Unsupported secret key algorithm " + algorithm);
"Unsupported secret key algorithm: " + algorithm);
}

byte[] secret = engineGenerateSecret();
Expand Down

0 comments on commit 45e3266

Please sign in to comment.