Skip to content

Commit

Permalink
Make it build, just ignore IOException. call initCause
Browse files Browse the repository at this point in the history
  • Loading branch information
GoeLin committed Feb 17, 2025
1 parent cd891cf commit 1cff1fb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ private static DHComponents decode(byte[] encodedKey)
private static byte[] encode(BigInteger p, BigInteger g, int l,
byte[] key) {
DerOutputStream tmp = new DerOutputStream();

byte[] encoded;
try {
// version
tmp.putInteger(PKCS8_VERSION);

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

// make it a SEQUENCE
DerValue val = DerValue.wrap(DerValue.tag_Sequence, tmp);
byte[] encoded = val.toByteArray();
encoded = val.toByteArray();
val.clear();

return encoded;
} catch (IOException e) {
// Ignore, see JDK-8297065.
encoded = null;
}
return encoded;
}

/**
Expand Down Expand Up @@ -234,6 +238,8 @@ private static byte[] encode(BigInteger p, BigInteger g, int l,
DerValue val = new DerValue(DerValue.tag_Integer, xbytes);
try {
this.key = val.toByteArray();
} catch (IOException e) {
// Ignore, see JDK-8297065.
} finally {
val.clear();
Arrays.fill(xbytes, (byte) 0);
Expand Down Expand Up @@ -369,7 +375,11 @@ private void readObject(ObjectInputStream stream)
try {
c = decode(encodedKeyIntern);
} catch (IOException e) {
throw new InvalidObjectException("Invalid encoding", e);
InvalidObjectException ioe = new InvalidObjectException("Invalid encoding");
if (ioe != null) {
ioe.initCause(e);
}
throw ioe;
}
if (!Arrays.equals(c.key, key) || !c.x.equals(x) || !c.p.equals(p)
|| !c.g.equals(g) || c.l != l) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ private static DHComponents decode(byte[] encodedKey)
private static byte[] encode(BigInteger p, BigInteger g, int l,
byte[] key) {
DerOutputStream algid = new DerOutputStream();
DerOutputStream derKey;

try {
// store oid in algid
algid.putOID(DH_OID);

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

// wrap algid and key into SEQUENCE
DerOutputStream derKey = new DerOutputStream();
derKey = new DerOutputStream();
derKey.write(DerValue.tag_Sequence, tmpDerKey);
} catch (IOException e) {
// Ignore, see JDK-8297065.
derKey = null;
}
return derKey.toByteArray();
}

Expand Down Expand Up @@ -372,7 +378,11 @@ private void readObject(ObjectInputStream stream)
try {
c = decode(encodedKeyIntern);
} catch (IOException e) {
throw new InvalidObjectException("Invalid encoding", e);
InvalidObjectException ioe = new InvalidObjectException("Invalid encoding");
if (ioe != null) {
ioe.initCause(e);
}
throw ioe;
}
if (!Arrays.equals(c.key, key) || !c.y.equals(y) || !c.p.equals(p)
|| !c.g.equals(g) || c.l != l) {
Expand Down

0 comments on commit 1cff1fb

Please sign in to comment.