-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8360463: Ambiguity in Cipher.getInstance() specification between NoSuchAlgorithmException and NoSuchPaddingException #26489
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
2bedc41
aa99296
92ae5bc
6f19aed
e057f88
9b2a09f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -505,11 +505,11 @@ private static Transform getTransform(Service s, | |
* | ||
* @throws NoSuchAlgorithmException if {@code transformation} | ||
* is {@code null}, empty, in an invalid format, | ||
* or if no provider supports a {@code CipherSpi} | ||
* implementation for the specified algorithm | ||
* or if a {@code CipherSpi} implementation is not found, or | ||
* is found but does not support the mode | ||
* | ||
* @throws NoSuchPaddingException if {@code transformation} | ||
* contains a padding scheme that is not available | ||
* @throws NoSuchPaddingException if a {@code CipherSpi} implementation | ||
* is found but does not support the padding scheme | ||
* | ||
* @see java.security.Provider | ||
*/ | ||
|
@@ -555,17 +555,22 @@ public static final Cipher getInstance(String transformation) | |
failure = e; | ||
} | ||
} | ||
throw new NoSuchAlgorithmException | ||
("Cannot find any provider supporting " + transformation, failure); | ||
if (failure instanceof NoSuchPaddingException nspe) { | ||
throw nspe; | ||
} else { | ||
throw new NoSuchAlgorithmException | ||
("Cannot find any provider supporting " + transformation, | ||
failure); | ||
} | ||
} | ||
|
||
/** | ||
* Returns a {@code Cipher} object that implements the specified | ||
* transformation. | ||
* | ||
* <p> A new {@code Cipher} object encapsulating the | ||
* {@code CipherSpi} implementation from the specified provider | ||
* is returned. The specified provider must be registered | ||
* {@code CipherSpi} implementation from the specified {@code provider} | ||
* is returned. The specified {@code provider} must be registered | ||
* in the security provider list. | ||
* | ||
* <p> Note that the list of registered providers may be retrieved via | ||
|
@@ -600,14 +605,15 @@ public static final Cipher getInstance(String transformation) | |
* | ||
* @throws NoSuchAlgorithmException if {@code transformation} | ||
* is {@code null}, empty, in an invalid format, | ||
* or if a {@code CipherSpi} implementation for the | ||
* specified algorithm is not available from the specified | ||
* provider | ||
* or if a {@code CipherSpi} implementation from the specified | ||
* {@code provider} is not found, or is found but does not support | ||
* the mode | ||
* | ||
* @throws NoSuchPaddingException if {@code transformation} | ||
* contains a padding scheme that is not available | ||
* @throws NoSuchPaddingException if a {@code CipherSpi} implementation | ||
* from the specified {@code provider} is found but does not | ||
* support the padding scheme | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The wording is correct now. Small nit: the NSAE one uses "but does not" and the NSPE one uses "but it does not". You might want to make them the same. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, will do. |
||
* | ||
* @throws NoSuchProviderException if the specified provider is not | ||
* @throws NoSuchProviderException if the specified {@code provider} is not | ||
* registered in the security provider list | ||
* | ||
* @see java.security.Provider | ||
|
@@ -673,12 +679,13 @@ private String getProviderName() { | |
* | ||
* @throws NoSuchAlgorithmException if {@code transformation} | ||
* is {@code null}, empty, in an invalid format, | ||
* or if a {@code CipherSpi} implementation for the | ||
* specified algorithm is not available from the specified | ||
* {@code provider} object | ||
* or if a {@code CipherSpi} implementation from the specified | ||
* {@code provider} is not found, or is found but does not support | ||
* the mode | ||
* | ||
* @throws NoSuchPaddingException if {@code transformation} | ||
* contains a padding scheme that is not available | ||
* @throws NoSuchPaddingException if a {@code CipherSpi} implementation | ||
* from the specified {@code provider} is found but does not | ||
* support the padding scheme | ||
* | ||
* @see java.security.Provider | ||
*/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO,
NoSuchAlgorithmException - if transformation is null, empty, in an invalid format, or if a CipherSpi implementation for the specified transformation is not available from the specified provider
The transformation can be linked to the class level mention
A transformation is of the form:
"algorithm/mode/padding" or
"algorithm"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's important to point out that when a matched (either full or partial) transform is found, not able to set mode throws an NSAE, while not able to set padding throws an NSPE. So NSAE is related on mode availability and NSPE to padding availability. This is why the current PR need to mention mode here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for clarifying this.