From 18c17109cd8a95f69a57c86cc04c0d0da68036e2 Mon Sep 17 00:00:00 2001 From: Luciano Balmaceda Date: Tue, 14 Mar 2017 11:45:36 -0300 Subject: [PATCH] remove constructor with 2 keys. Keep keyProvider signature --- .../com/auth0/jwt/algorithms/Algorithm.java | 24 +++++++++---------- .../auth0/jwt/algorithms/ECDSAAlgorithm.java | 4 ---- .../auth0/jwt/algorithms/RSAAlgorithm.java | 4 ---- .../jwt/algorithms/ECDSAAlgorithmTest.java | 3 ++- 4 files changed, 14 insertions(+), 21 deletions(-) diff --git a/lib/src/main/java/com/auth0/jwt/algorithms/Algorithm.java b/lib/src/main/java/com/auth0/jwt/algorithms/Algorithm.java index ec4ab405..eb484478 100644 --- a/lib/src/main/java/com/auth0/jwt/algorithms/Algorithm.java +++ b/lib/src/main/java/com/auth0/jwt/algorithms/Algorithm.java @@ -37,7 +37,7 @@ public static Algorithm RSA256(RSAKeyProvider keyProvider) throws IllegalArgumen * @throws IllegalArgumentException if both provided Keys are null. */ public static Algorithm RSA256(RSAPublicKey publicKey, RSAPrivateKey privateKey) throws IllegalArgumentException { - return new RSAAlgorithm("RS256", "SHA256withRSA", publicKey, privateKey); + return RSA256(RSAAlgorithm.providerForKeys(publicKey, privateKey)); } /** @@ -46,7 +46,7 @@ public static Algorithm RSA256(RSAPublicKey publicKey, RSAPrivateKey privateKey) * @param key the key to use in the verify or signing instance. * @return a valid RSA256 Algorithm. * @throws IllegalArgumentException if the Key Provider is null. - * @deprecated use {@link #RSA256(RSAPublicKey, RSAPrivateKey)} + * @deprecated use {@link #RSA256(RSAPublicKey, RSAPrivateKey)} or {@link #RSA256(RSAKeyProvider)} */ @Deprecated public static Algorithm RSA256(RSAKey key) throws IllegalArgumentException { @@ -75,7 +75,7 @@ public static Algorithm RSA384(RSAKeyProvider keyProvider) throws IllegalArgumen * @throws IllegalArgumentException if both provided Keys are null. */ public static Algorithm RSA384(RSAPublicKey publicKey, RSAPrivateKey privateKey) throws IllegalArgumentException { - return new RSAAlgorithm("RS384", "SHA384withRSA", publicKey, privateKey); + return RSA384(RSAAlgorithm.providerForKeys(publicKey, privateKey)); } /** @@ -84,7 +84,7 @@ public static Algorithm RSA384(RSAPublicKey publicKey, RSAPrivateKey privateKey) * @param key the key to use in the verify or signing instance. * @return a valid RSA384 Algorithm. * @throws IllegalArgumentException if the provided Key is null. - * @deprecated use {@link #RSA384(RSAPublicKey, RSAPrivateKey)} + * @deprecated use {@link #RSA384(RSAPublicKey, RSAPrivateKey)} or {@link #RSA384(RSAKeyProvider)} */ @Deprecated public static Algorithm RSA384(RSAKey key) throws IllegalArgumentException { @@ -113,7 +113,7 @@ public static Algorithm RSA512(RSAKeyProvider keyProvider) throws IllegalArgumen * @throws IllegalArgumentException if both provided Keys are null. */ public static Algorithm RSA512(RSAPublicKey publicKey, RSAPrivateKey privateKey) throws IllegalArgumentException { - return new RSAAlgorithm("RS512", "SHA512withRSA", publicKey, privateKey); + return RSA512(RSAAlgorithm.providerForKeys(publicKey, privateKey)); } /** @@ -122,7 +122,7 @@ public static Algorithm RSA512(RSAPublicKey publicKey, RSAPrivateKey privateKey) * @param key the key to use in the verify or signing instance. * @return a valid RSA512 Algorithm. * @throws IllegalArgumentException if the provided Key is null. - * @deprecated use {@link #RSA512(RSAPublicKey, RSAPrivateKey)} + * @deprecated use {@link #RSA512(RSAPublicKey, RSAPrivateKey)} or {@link #RSA512(RSAKeyProvider)} */ @Deprecated public static Algorithm RSA512(RSAKey key) throws IllegalArgumentException { @@ -220,7 +220,7 @@ public static Algorithm ECDSA256(ECKeyProvider keyProvider) throws IllegalArgume * @throws IllegalArgumentException if the provided Key is null. */ public static Algorithm ECDSA256(ECPublicKey publicKey, ECPrivateKey privateKey) throws IllegalArgumentException { - return new ECDSAAlgorithm("ES256", "SHA256withECDSA", 32, publicKey, privateKey); + return ECDSA256(ECDSAAlgorithm.providerForKeys(publicKey, privateKey)); } /** @@ -229,7 +229,7 @@ public static Algorithm ECDSA256(ECPublicKey publicKey, ECPrivateKey privateKey) * @param key the key to use in the verify or signing instance. * @return a valid ECDSA256 Algorithm. * @throws IllegalArgumentException if the provided Key is null. - * @deprecated use {@link #ECDSA256(ECPublicKey, ECPrivateKey)} + * @deprecated use {@link #ECDSA256(ECPublicKey, ECPrivateKey)} or {@link #ECDSA256(ECKeyProvider)} */ @Deprecated public static Algorithm ECDSA256(ECKey key) throws IllegalArgumentException { @@ -258,7 +258,7 @@ public static Algorithm ECDSA384(ECKeyProvider keyProvider) throws IllegalArgume * @throws IllegalArgumentException if the provided Key is null. */ public static Algorithm ECDSA384(ECPublicKey publicKey, ECPrivateKey privateKey) throws IllegalArgumentException { - return new ECDSAAlgorithm("ES384", "SHA384withECDSA", 48, publicKey, privateKey); + return ECDSA384(ECDSAAlgorithm.providerForKeys(publicKey, privateKey)); } /** @@ -267,7 +267,7 @@ public static Algorithm ECDSA384(ECPublicKey publicKey, ECPrivateKey privateKey) * @param key the key to use in the verify or signing instance. * @return a valid ECDSA384 Algorithm. * @throws IllegalArgumentException if the provided Key is null. - * @deprecated use {@link #ECDSA384(ECPublicKey, ECPrivateKey)} + * @deprecated use {@link #ECDSA384(ECPublicKey, ECPrivateKey)} or {@link #ECDSA384(ECKeyProvider)} */ @Deprecated public static Algorithm ECDSA384(ECKey key) throws IllegalArgumentException { @@ -296,7 +296,7 @@ public static Algorithm ECDSA512(ECKeyProvider keyProvider) throws IllegalArgume * @throws IllegalArgumentException if the provided Key is null. */ public static Algorithm ECDSA512(ECPublicKey publicKey, ECPrivateKey privateKey) throws IllegalArgumentException { - return new ECDSAAlgorithm("ES512", "SHA512withECDSA", 66, publicKey, privateKey); + return ECDSA512(ECDSAAlgorithm.providerForKeys(publicKey, privateKey)); } /** @@ -305,7 +305,7 @@ public static Algorithm ECDSA512(ECPublicKey publicKey, ECPrivateKey privateKey) * @param key the key to use in the verify or signing instance. * @return a valid ECDSA512 Algorithm. * @throws IllegalArgumentException if the provided Key is null. - * @deprecated use {@link #ECDSA512(ECPublicKey, ECPrivateKey)} + * @deprecated use {@link #ECDSA512(ECPublicKey, ECPrivateKey)} or {@link #ECDSA512(ECKeyProvider)} */ @Deprecated public static Algorithm ECDSA512(ECKey key) throws IllegalArgumentException { diff --git a/lib/src/main/java/com/auth0/jwt/algorithms/ECDSAAlgorithm.java b/lib/src/main/java/com/auth0/jwt/algorithms/ECDSAAlgorithm.java index 04c95599..2b43c7e6 100644 --- a/lib/src/main/java/com/auth0/jwt/algorithms/ECDSAAlgorithm.java +++ b/lib/src/main/java/com/auth0/jwt/algorithms/ECDSAAlgorithm.java @@ -30,10 +30,6 @@ class ECDSAAlgorithm extends Algorithm { this.ecNumberSize = ecNumberSize; } - ECDSAAlgorithm(String id, String algorithm, int ecNumberSize, ECPublicKey publicKey, ECPrivateKey privateKey) throws IllegalArgumentException { - this(new CryptoHelper(), id, algorithm, ecNumberSize, providerForKeys(publicKey, privateKey)); - } - ECDSAAlgorithm(String id, String algorithm, int ecNumberSize, ECKeyProvider keyProvider) throws IllegalArgumentException { this(new CryptoHelper(), id, algorithm, ecNumberSize, keyProvider); } diff --git a/lib/src/main/java/com/auth0/jwt/algorithms/RSAAlgorithm.java b/lib/src/main/java/com/auth0/jwt/algorithms/RSAAlgorithm.java index c9f708d6..a5d7d3f3 100644 --- a/lib/src/main/java/com/auth0/jwt/algorithms/RSAAlgorithm.java +++ b/lib/src/main/java/com/auth0/jwt/algorithms/RSAAlgorithm.java @@ -28,10 +28,6 @@ class RSAAlgorithm extends Algorithm { this.crypto = crypto; } - RSAAlgorithm(String id, String algorithm, RSAPublicKey publicKey, RSAPrivateKey privateKey) throws IllegalArgumentException { - this(new CryptoHelper(), id, algorithm, providerForKeys(publicKey, privateKey)); - } - RSAAlgorithm(String id, String algorithm, RSAKeyProvider keyProvider) throws IllegalArgumentException { this(new CryptoHelper(), id, algorithm, keyProvider); } diff --git a/lib/src/test/java/com/auth0/jwt/algorithms/ECDSAAlgorithmTest.java b/lib/src/test/java/com/auth0/jwt/algorithms/ECDSAAlgorithmTest.java index 40f484b2..b169b554 100644 --- a/lib/src/test/java/com/auth0/jwt/algorithms/ECDSAAlgorithmTest.java +++ b/lib/src/test/java/com/auth0/jwt/algorithms/ECDSAAlgorithmTest.java @@ -336,7 +336,8 @@ public void shouldFailJOSEToDERConversionOnInvalidJOSESignatureLength() throws E ECPublicKey publicKey = (ECPublicKey) readPublicKeyFromFile(PUBLIC_KEY_FILE_256, "EC"); ECPrivateKey privateKey = mock(ECPrivateKey.class); - Algorithm algorithm = new ECDSAAlgorithm("ES256", "SHA256withECDSA", 128, publicKey, privateKey); + ECKeyProvider provider = ECDSAAlgorithm.providerForKeys(publicKey, privateKey); + Algorithm algorithm = new ECDSAAlgorithm("ES256", "SHA256withECDSA", 128, provider); AlgorithmUtils.verify(algorithm, jwt); }