mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 07:14:30 +02:00
8296442: EncryptedPrivateKeyInfo can be created with an uninitialized AlgorithmParameters
Reviewed-by: xuelei, kdriver, mullan
This commit is contained in:
parent
37848a9ca2
commit
68d3ed5cee
6 changed files with 128 additions and 72 deletions
|
@ -100,6 +100,8 @@ public class AlgorithmId implements Serializable, DerEncoder {
|
|||
*
|
||||
* @param oid the identifier for the algorithm.
|
||||
* @param algparams the associated algorithm parameters, can be null.
|
||||
* @exception IllegalStateException if algparams is not initialized
|
||||
* or cannot be encoded
|
||||
*/
|
||||
public AlgorithmId(ObjectIdentifier oid, AlgorithmParameters algparams) {
|
||||
algid = oid;
|
||||
|
@ -108,9 +110,9 @@ public class AlgorithmId implements Serializable, DerEncoder {
|
|||
try {
|
||||
encodedParams = algParams.getEncoded();
|
||||
} catch (IOException ioe) {
|
||||
// Ignore this at the moment. This exception can occur
|
||||
// if AlgorithmParameters was not initialized yet. Will
|
||||
// try to re-getEncoded() again later.
|
||||
throw new IllegalStateException(
|
||||
"AlgorithmParameters not initialized or cannot be decoded",
|
||||
ioe);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -157,17 +159,11 @@ public class AlgorithmId implements Serializable, DerEncoder {
|
|||
* @exception IOException on encoding error.
|
||||
*/
|
||||
@Override
|
||||
public void encode (DerOutputStream out) throws IOException {
|
||||
public void encode(DerOutputStream out) throws IOException {
|
||||
DerOutputStream bytes = new DerOutputStream();
|
||||
|
||||
bytes.putOID(algid);
|
||||
|
||||
// Re-getEncoded() from algParams if it was not initialized
|
||||
if (algParams != null && encodedParams == null) {
|
||||
encodedParams = algParams.getEncoded();
|
||||
// If still not initialized. Let the IOE be thrown.
|
||||
}
|
||||
|
||||
if (encodedParams == null) {
|
||||
// Changes backed out for compatibility with Solaris
|
||||
|
||||
|
@ -488,6 +484,8 @@ public class AlgorithmId implements Serializable, DerEncoder {
|
|||
*
|
||||
* @param algparams the associated algorithm parameters.
|
||||
* @exception NoSuchAlgorithmException on error.
|
||||
* @exception IllegalStateException if algparams is not initialized
|
||||
* or cannot be encoded
|
||||
*/
|
||||
public static AlgorithmId get(AlgorithmParameters algparams)
|
||||
throws NoSuchAlgorithmException {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue