Skip to content

Commit 18c1710

Browse files
committed
remove constructor with 2 keys. Keep keyProvider signature
1 parent f27584e commit 18c1710

File tree

4 files changed

+14
-21
lines changed

4 files changed

+14
-21
lines changed

lib/src/main/java/com/auth0/jwt/algorithms/Algorithm.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public static Algorithm RSA256(RSAKeyProvider keyProvider) throws IllegalArgumen
3737
* @throws IllegalArgumentException if both provided Keys are null.
3838
*/
3939
public static Algorithm RSA256(RSAPublicKey publicKey, RSAPrivateKey privateKey) throws IllegalArgumentException {
40-
return new RSAAlgorithm("RS256", "SHA256withRSA", publicKey, privateKey);
40+
return RSA256(RSAAlgorithm.providerForKeys(publicKey, privateKey));
4141
}
4242

4343
/**
@@ -46,7 +46,7 @@ public static Algorithm RSA256(RSAPublicKey publicKey, RSAPrivateKey privateKey)
4646
* @param key the key to use in the verify or signing instance.
4747
* @return a valid RSA256 Algorithm.
4848
* @throws IllegalArgumentException if the Key Provider is null.
49-
* @deprecated use {@link #RSA256(RSAPublicKey, RSAPrivateKey)}
49+
* @deprecated use {@link #RSA256(RSAPublicKey, RSAPrivateKey)} or {@link #RSA256(RSAKeyProvider)}
5050
*/
5151
@Deprecated
5252
public static Algorithm RSA256(RSAKey key) throws IllegalArgumentException {
@@ -75,7 +75,7 @@ public static Algorithm RSA384(RSAKeyProvider keyProvider) throws IllegalArgumen
7575
* @throws IllegalArgumentException if both provided Keys are null.
7676
*/
7777
public static Algorithm RSA384(RSAPublicKey publicKey, RSAPrivateKey privateKey) throws IllegalArgumentException {
78-
return new RSAAlgorithm("RS384", "SHA384withRSA", publicKey, privateKey);
78+
return RSA384(RSAAlgorithm.providerForKeys(publicKey, privateKey));
7979
}
8080

8181
/**
@@ -84,7 +84,7 @@ public static Algorithm RSA384(RSAPublicKey publicKey, RSAPrivateKey privateKey)
8484
* @param key the key to use in the verify or signing instance.
8585
* @return a valid RSA384 Algorithm.
8686
* @throws IllegalArgumentException if the provided Key is null.
87-
* @deprecated use {@link #RSA384(RSAPublicKey, RSAPrivateKey)}
87+
* @deprecated use {@link #RSA384(RSAPublicKey, RSAPrivateKey)} or {@link #RSA384(RSAKeyProvider)}
8888
*/
8989
@Deprecated
9090
public static Algorithm RSA384(RSAKey key) throws IllegalArgumentException {
@@ -113,7 +113,7 @@ public static Algorithm RSA512(RSAKeyProvider keyProvider) throws IllegalArgumen
113113
* @throws IllegalArgumentException if both provided Keys are null.
114114
*/
115115
public static Algorithm RSA512(RSAPublicKey publicKey, RSAPrivateKey privateKey) throws IllegalArgumentException {
116-
return new RSAAlgorithm("RS512", "SHA512withRSA", publicKey, privateKey);
116+
return RSA512(RSAAlgorithm.providerForKeys(publicKey, privateKey));
117117
}
118118

119119
/**
@@ -122,7 +122,7 @@ public static Algorithm RSA512(RSAPublicKey publicKey, RSAPrivateKey privateKey)
122122
* @param key the key to use in the verify or signing instance.
123123
* @return a valid RSA512 Algorithm.
124124
* @throws IllegalArgumentException if the provided Key is null.
125-
* @deprecated use {@link #RSA512(RSAPublicKey, RSAPrivateKey)}
125+
* @deprecated use {@link #RSA512(RSAPublicKey, RSAPrivateKey)} or {@link #RSA512(RSAKeyProvider)}
126126
*/
127127
@Deprecated
128128
public static Algorithm RSA512(RSAKey key) throws IllegalArgumentException {
@@ -220,7 +220,7 @@ public static Algorithm ECDSA256(ECKeyProvider keyProvider) throws IllegalArgume
220220
* @throws IllegalArgumentException if the provided Key is null.
221221
*/
222222
public static Algorithm ECDSA256(ECPublicKey publicKey, ECPrivateKey privateKey) throws IllegalArgumentException {
223-
return new ECDSAAlgorithm("ES256", "SHA256withECDSA", 32, publicKey, privateKey);
223+
return ECDSA256(ECDSAAlgorithm.providerForKeys(publicKey, privateKey));
224224
}
225225

226226
/**
@@ -229,7 +229,7 @@ public static Algorithm ECDSA256(ECPublicKey publicKey, ECPrivateKey privateKey)
229229
* @param key the key to use in the verify or signing instance.
230230
* @return a valid ECDSA256 Algorithm.
231231
* @throws IllegalArgumentException if the provided Key is null.
232-
* @deprecated use {@link #ECDSA256(ECPublicKey, ECPrivateKey)}
232+
* @deprecated use {@link #ECDSA256(ECPublicKey, ECPrivateKey)} or {@link #ECDSA256(ECKeyProvider)}
233233
*/
234234
@Deprecated
235235
public static Algorithm ECDSA256(ECKey key) throws IllegalArgumentException {
@@ -258,7 +258,7 @@ public static Algorithm ECDSA384(ECKeyProvider keyProvider) throws IllegalArgume
258258
* @throws IllegalArgumentException if the provided Key is null.
259259
*/
260260
public static Algorithm ECDSA384(ECPublicKey publicKey, ECPrivateKey privateKey) throws IllegalArgumentException {
261-
return new ECDSAAlgorithm("ES384", "SHA384withECDSA", 48, publicKey, privateKey);
261+
return ECDSA384(ECDSAAlgorithm.providerForKeys(publicKey, privateKey));
262262
}
263263

264264
/**
@@ -267,7 +267,7 @@ public static Algorithm ECDSA384(ECPublicKey publicKey, ECPrivateKey privateKey)
267267
* @param key the key to use in the verify or signing instance.
268268
* @return a valid ECDSA384 Algorithm.
269269
* @throws IllegalArgumentException if the provided Key is null.
270-
* @deprecated use {@link #ECDSA384(ECPublicKey, ECPrivateKey)}
270+
* @deprecated use {@link #ECDSA384(ECPublicKey, ECPrivateKey)} or {@link #ECDSA384(ECKeyProvider)}
271271
*/
272272
@Deprecated
273273
public static Algorithm ECDSA384(ECKey key) throws IllegalArgumentException {
@@ -296,7 +296,7 @@ public static Algorithm ECDSA512(ECKeyProvider keyProvider) throws IllegalArgume
296296
* @throws IllegalArgumentException if the provided Key is null.
297297
*/
298298
public static Algorithm ECDSA512(ECPublicKey publicKey, ECPrivateKey privateKey) throws IllegalArgumentException {
299-
return new ECDSAAlgorithm("ES512", "SHA512withECDSA", 66, publicKey, privateKey);
299+
return ECDSA512(ECDSAAlgorithm.providerForKeys(publicKey, privateKey));
300300
}
301301

302302
/**
@@ -305,7 +305,7 @@ public static Algorithm ECDSA512(ECPublicKey publicKey, ECPrivateKey privateKey)
305305
* @param key the key to use in the verify or signing instance.
306306
* @return a valid ECDSA512 Algorithm.
307307
* @throws IllegalArgumentException if the provided Key is null.
308-
* @deprecated use {@link #ECDSA512(ECPublicKey, ECPrivateKey)}
308+
* @deprecated use {@link #ECDSA512(ECPublicKey, ECPrivateKey)} or {@link #ECDSA512(ECKeyProvider)}
309309
*/
310310
@Deprecated
311311
public static Algorithm ECDSA512(ECKey key) throws IllegalArgumentException {

lib/src/main/java/com/auth0/jwt/algorithms/ECDSAAlgorithm.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ class ECDSAAlgorithm extends Algorithm {
3030
this.ecNumberSize = ecNumberSize;
3131
}
3232

33-
ECDSAAlgorithm(String id, String algorithm, int ecNumberSize, ECPublicKey publicKey, ECPrivateKey privateKey) throws IllegalArgumentException {
34-
this(new CryptoHelper(), id, algorithm, ecNumberSize, providerForKeys(publicKey, privateKey));
35-
}
36-
3733
ECDSAAlgorithm(String id, String algorithm, int ecNumberSize, ECKeyProvider keyProvider) throws IllegalArgumentException {
3834
this(new CryptoHelper(), id, algorithm, ecNumberSize, keyProvider);
3935
}

lib/src/main/java/com/auth0/jwt/algorithms/RSAAlgorithm.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ class RSAAlgorithm extends Algorithm {
2828
this.crypto = crypto;
2929
}
3030

31-
RSAAlgorithm(String id, String algorithm, RSAPublicKey publicKey, RSAPrivateKey privateKey) throws IllegalArgumentException {
32-
this(new CryptoHelper(), id, algorithm, providerForKeys(publicKey, privateKey));
33-
}
34-
3531
RSAAlgorithm(String id, String algorithm, RSAKeyProvider keyProvider) throws IllegalArgumentException {
3632
this(new CryptoHelper(), id, algorithm, keyProvider);
3733
}

lib/src/test/java/com/auth0/jwt/algorithms/ECDSAAlgorithmTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,8 @@ public void shouldFailJOSEToDERConversionOnInvalidJOSESignatureLength() throws E
336336

337337
ECPublicKey publicKey = (ECPublicKey) readPublicKeyFromFile(PUBLIC_KEY_FILE_256, "EC");
338338
ECPrivateKey privateKey = mock(ECPrivateKey.class);
339-
Algorithm algorithm = new ECDSAAlgorithm("ES256", "SHA256withECDSA", 128, publicKey, privateKey);
339+
ECKeyProvider provider = ECDSAAlgorithm.providerForKeys(publicKey, privateKey);
340+
Algorithm algorithm = new ECDSAAlgorithm("ES256", "SHA256withECDSA", 128, provider);
340341
AlgorithmUtils.verify(algorithm, jwt);
341342
}
342343

0 commit comments

Comments
 (0)