Skip to content

Commit 1cff1fb

Browse files
committed
Make it build, just ignore IOException. call initCause
1 parent cd891cf commit 1cff1fb

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

src/java.base/share/classes/com/sun/crypto/provider/DHPrivateKey.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ private static DHComponents decode(byte[] encodedKey)
162162
private static byte[] encode(BigInteger p, BigInteger g, int l,
163163
byte[] key) {
164164
DerOutputStream tmp = new DerOutputStream();
165-
165+
byte[] encoded;
166+
try {
166167
// version
167168
tmp.putInteger(PKCS8_VERSION);
168169

@@ -191,10 +192,13 @@ private static byte[] encode(BigInteger p, BigInteger g, int l,
191192

192193
// make it a SEQUENCE
193194
DerValue val = DerValue.wrap(DerValue.tag_Sequence, tmp);
194-
byte[] encoded = val.toByteArray();
195+
encoded = val.toByteArray();
195196
val.clear();
196-
197-
return encoded;
197+
} catch (IOException e) {
198+
// Ignore, see JDK-8297065.
199+
encoded = null;
200+
}
201+
return encoded;
198202
}
199203

200204
/**
@@ -234,6 +238,8 @@ private static byte[] encode(BigInteger p, BigInteger g, int l,
234238
DerValue val = new DerValue(DerValue.tag_Integer, xbytes);
235239
try {
236240
this.key = val.toByteArray();
241+
} catch (IOException e) {
242+
// Ignore, see JDK-8297065.
237243
} finally {
238244
val.clear();
239245
Arrays.fill(xbytes, (byte) 0);
@@ -369,7 +375,11 @@ private void readObject(ObjectInputStream stream)
369375
try {
370376
c = decode(encodedKeyIntern);
371377
} catch (IOException e) {
372-
throw new InvalidObjectException("Invalid encoding", e);
378+
InvalidObjectException ioe = new InvalidObjectException("Invalid encoding");
379+
if (ioe != null) {
380+
ioe.initCause(e);
381+
}
382+
throw ioe;
373383
}
374384
if (!Arrays.equals(c.key, key) || !c.x.equals(x) || !c.p.equals(p)
375385
|| !c.g.equals(g) || c.l != l) {

src/java.base/share/classes/com/sun/crypto/provider/DHPublicKey.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@ private static DHComponents decode(byte[] encodedKey)
151151
private static byte[] encode(BigInteger p, BigInteger g, int l,
152152
byte[] key) {
153153
DerOutputStream algid = new DerOutputStream();
154+
DerOutputStream derKey;
154155

156+
try {
155157
// store oid in algid
156158
algid.putOID(DH_OID);
157159

@@ -177,8 +179,12 @@ private static byte[] encode(BigInteger p, BigInteger g, int l,
177179
tmpDerKey.putBitString(key);
178180

179181
// wrap algid and key into SEQUENCE
180-
DerOutputStream derKey = new DerOutputStream();
182+
derKey = new DerOutputStream();
181183
derKey.write(DerValue.tag_Sequence, tmpDerKey);
184+
} catch (IOException e) {
185+
// Ignore, see JDK-8297065.
186+
derKey = null;
187+
}
182188
return derKey.toByteArray();
183189
}
184190

@@ -372,7 +378,11 @@ private void readObject(ObjectInputStream stream)
372378
try {
373379
c = decode(encodedKeyIntern);
374380
} catch (IOException e) {
375-
throw new InvalidObjectException("Invalid encoding", e);
381+
InvalidObjectException ioe = new InvalidObjectException("Invalid encoding");
382+
if (ioe != null) {
383+
ioe.initCause(e);
384+
}
385+
throw ioe;
376386
}
377387
if (!Arrays.equals(c.key, key) || !c.y.equals(y) || !c.p.equals(p)
378388
|| !c.g.equals(g) || c.l != l) {

0 commit comments

Comments
 (0)