Merge pull request #224 from woody77/master

Test for instanceof PrivateKey and instanceof ECKey when signing
This commit is contained in:
Les Hazlewood 2017-05-25 12:38:44 -07:00 committed by GitHub
commit bc9e9c7c06
2 changed files with 6 additions and 5 deletions

View File

@ -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);
}
}

View File

@ -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.";
}
}