Skip to content

Commit

Permalink
Change behaviour to match Java23
Browse files Browse the repository at this point in the history
  • Loading branch information
KostasTsiounis committed May 17, 2024
1 parent 46de52d commit b715b0d
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,24 +98,28 @@ public NativeECDHKeyAgreement() {

private void init(Key key)
throws InvalidKeyException, InvalidAlgorithmParameterException {
this.privateKey = null;
this.privateKeyOps = null;
this.publicKey = null;

if (!(key instanceof PrivateKey)) {
throw new InvalidKeyException
("Key must be an instance of PrivateKey");
}
/* attempt to translate the key if it is not an ECKey */
ECKey ecKey = ECKeyFactory.toECKey(key);
if (ecKey instanceof ECPrivateKeyImpl keyImpl) {
this.privateKey = keyImpl;
this.publicKey = null;
Optional<ECOperations> opsOpt =
ECOperations.forParameters(this.privateKey.getParams());
ECOperations.forParameters(keyImpl.getParams());
if (opsOpt.isEmpty()) {
NamedCurve nc = CurveDB.lookup(this.privateKey.getParams());
NamedCurve nc = CurveDB.lookup(keyImpl.getParams());
throw new InvalidAlgorithmParameterException(
"Curve not supported: " +
((nc != null) ? nc.toString() : "unknown"));
}
ECUtil.checkPrivateKey(this.privateKey);
ECUtil.checkPrivateKey(keyImpl);

this.privateKey = keyImpl;
this.privateKeyOps = opsOpt.get();

ECParameterSpec params = this.privateKey.getParams();
Expand Down

0 comments on commit b715b0d

Please sign in to comment.