mirror of https://github.com/jwtk/jjwt.git
Merge pull request #224 from woody77/master
Test for instanceof PrivateKey and instanceof ECKey when signing
This commit is contained in:
commit
bc9e9c7c06
|
@ -19,6 +19,7 @@ import java.security.InvalidKeyException;
|
|||
import java.security.Key;
|
||||
import java.security.PrivateKey;
|
||||
import java.security.Signature;
|
||||
import java.security.interfaces.ECKey;
|
||||
import java.security.interfaces.ECPrivateKey;
|
||||
|
||||
import io.jsonwebtoken.JwtException;
|
||||
|
@ -29,9 +30,9 @@ public class EllipticCurveSigner extends EllipticCurveProvider implements Signer
|
|||
|
||||
public EllipticCurveSigner(SignatureAlgorithm alg, Key key) {
|
||||
super(alg, key);
|
||||
if (!(key instanceof ECPrivateKey)) {
|
||||
String msg = "Elliptic Curve signatures must be computed using an ECPrivateKey. The specified key of " +
|
||||
"type " + key.getClass().getName() + " is not an ECPrivateKey.";
|
||||
if (!(key instanceof PrivateKey && key instanceof ECKey)) {
|
||||
String msg = "Elliptic Curve signatures must be computed using an EC PrivateKey. The specified key of " +
|
||||
"type " + key.getClass().getName() + " is not an EC PrivateKey.";
|
||||
throw new IllegalArgumentException(msg);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,8 +46,8 @@ class EllipticCurveSignerTest {
|
|||
new EllipticCurveSigner(SignatureAlgorithm.ES256, key);
|
||||
fail('EllipticCurveSigner should reject non ECPrivateKey instances.')
|
||||
} catch (IllegalArgumentException expected) {
|
||||
assertEquals expected.message, "Elliptic Curve signatures must be computed using an ECPrivateKey. The specified key of " +
|
||||
"type " + key.getClass().getName() + " is not an ECPrivateKey.";
|
||||
assertEquals expected.message, "Elliptic Curve signatures must be computed using an EC PrivateKey. The specified key of " +
|
||||
"type " + key.getClass().getName() + " is not an EC PrivateKey.";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue