20
20
import io .jsonwebtoken .lang .Classes ;
21
21
import io .jsonwebtoken .lang .Registry ;
22
22
import io .jsonwebtoken .security .AeadAlgorithm ;
23
+ import io .jsonwebtoken .security .AeadRequest ;
24
+ import io .jsonwebtoken .security .AeadResult ;
25
+ import io .jsonwebtoken .security .DecryptAeadRequest ;
26
+ import io .jsonwebtoken .security .DecryptionKeyRequest ;
23
27
import io .jsonwebtoken .security .KeyAlgorithm ;
24
28
import io .jsonwebtoken .security .KeyPairBuilderSupplier ;
29
+ import io .jsonwebtoken .security .KeyRequest ;
25
30
import io .jsonwebtoken .security .MacAlgorithm ;
26
31
import io .jsonwebtoken .security .Password ;
32
+ import io .jsonwebtoken .security .Request ;
27
33
import io .jsonwebtoken .security .SecretKeyAlgorithm ;
28
34
import io .jsonwebtoken .security .SecureDigestAlgorithm ;
35
+ import io .jsonwebtoken .security .SecureRequest ;
29
36
import io .jsonwebtoken .security .SignatureAlgorithm ;
37
+ import io .jsonwebtoken .security .VerifyDigestRequest ;
38
+ import io .jsonwebtoken .security .VerifySecureDigestRequest ;
30
39
import io .jsonwebtoken .security .X509Builder ;
31
40
32
41
import javax .crypto .SecretKey ;
42
+ import java .io .InputStream ;
43
+ import java .io .OutputStream ;
33
44
import java .security .Key ;
34
45
import java .security .PrivateKey ;
35
46
import java .security .PublicKey ;
@@ -82,6 +93,18 @@ public static final class ENC {
82
93
private static final String IMPL_CLASSNAME = "io.jsonwebtoken.impl.security.StandardEncryptionAlgorithms" ;
83
94
private static final Registry <String , AeadAlgorithm > REGISTRY = Classes .newInstance (IMPL_CLASSNAME );
84
95
96
+ // @since 0.13.0
97
+ private static final Supplier <AeadRequest .Builder > REQUEST_BUILDER_SUPPLIER =
98
+ Classes .newInstance ("io.jsonwebtoken.impl.security.DefaultAeadRequest$Builder$Supplier" );
99
+
100
+ // @since 0.13.0
101
+ private static final Supplier <DecryptAeadRequest .Builder > DECRYPT_REQUEST_BUILDER_SUPPLIER =
102
+ Classes .newInstance ("io.jsonwebtoken.impl.security.DefaultDecryptAeadRequest$Builder$Supplier" );
103
+
104
+ // @since 0.13.0
105
+ private static final Supplier <AeadResult .Builder > RESULT_BUILDER_SUPPLIER =
106
+ Classes .newInstance ("io.jsonwebtoken.impl.security.DefaultAeadResult$Builder$Supplier" );
107
+
85
108
/**
86
109
* Returns all standard JWA <a href="https://www.rfc-editor.org/rfc/rfc7518.html#section-5">Cryptographic
87
110
* Algorithms for Content Encryption</a> defined in the
@@ -139,6 +162,42 @@ private ENC() {
139
162
* algorithm requires a 256-bit (32 byte) key.
140
163
*/
141
164
public static final AeadAlgorithm A256GCM = get ().forKey ("A256GCM" );
165
+
166
+ /**
167
+ * Returns a new builder to create {@link AeadRequest}s used for AEAD encryption via
168
+ * {@link AeadAlgorithm#encrypt(AeadRequest, AeadResult)}
169
+ *
170
+ * @return a new builder to create {@link AeadRequest}s used for AEAD encryption via
171
+ * {@link AeadAlgorithm#encrypt(AeadRequest, AeadResult)}
172
+ * @since 0.13.0
173
+ */
174
+ public static AeadRequest .Builder request () {
175
+ return REQUEST_BUILDER_SUPPLIER .get ();
176
+ }
177
+
178
+ /**
179
+ * Returns a new builder to create {@link DecryptAeadRequest}s used for AEAD decryption via
180
+ * {@link AeadAlgorithm#decrypt(DecryptAeadRequest, OutputStream)}
181
+ *
182
+ * @return a new builder to create {@link DecryptAeadRequest}s used for AEAD decryption via
183
+ * {@link AeadAlgorithm#decrypt(DecryptAeadRequest, OutputStream)}
184
+ * @since 0.13.0
185
+ */
186
+ public static DecryptAeadRequest .Builder decryptRequest () {
187
+ return DECRYPT_REQUEST_BUILDER_SUPPLIER .get ();
188
+ }
189
+
190
+ /**
191
+ * Returns a new builder to create {@link AeadResult}s used to store AEAD encryption results when calling
192
+ * {@link AeadAlgorithm#encrypt(AeadRequest, AeadResult)}
193
+ *
194
+ * @return a new builder to create {@link AeadResult}s used to store AEAD encryption results when calling
195
+ * {@link AeadAlgorithm#encrypt(AeadRequest, AeadResult)}
196
+ * @since 0.13.0
197
+ */
198
+ public static AeadResult .Builder result () {
199
+ return RESULT_BUILDER_SUPPLIER .get ();
200
+ }
142
201
}
143
202
144
203
/**
@@ -162,6 +221,14 @@ public static final class SIG {
162
221
private static final String IMPL_CLASSNAME = "io.jsonwebtoken.impl.security.StandardSecureDigestAlgorithms" ;
163
222
private static final Registry <String , SecureDigestAlgorithm <?, ?>> REGISTRY = Classes .newInstance (IMPL_CLASSNAME );
164
223
224
+ // @since 0.13.0
225
+ private static final Supplier <SecureRequest .Builder <InputStream , ?>> REQUEST_BUILDER_SUPPLIER =
226
+ Classes .newInstance ("io.jsonwebtoken.impl.security.DefaultSecureRequest$Builder$Supplier" );
227
+
228
+ // @since 0.13.0
229
+ private static final Supplier <VerifySecureDigestRequest .Builder <?>> VERIFY_REQUEST_BUILDER_SUPPLIER =
230
+ Classes .newInstance ("io.jsonwebtoken.impl.security.DefaultVerifySecureDigestRequest$Builder$Supplier" );
231
+
165
232
//prevent instantiation
166
233
private SIG () {
167
234
}
@@ -302,6 +369,34 @@ private SIG() {
302
369
* classpath.</b></p>
303
370
*/
304
371
public static final SignatureAlgorithm EdDSA = Jwts .get (REGISTRY , "EdDSA" );
372
+
373
+ /**
374
+ * Returns a new builder to create {@link SecureRequest}s used to compute a mac or signature via
375
+ * {@link SecureDigestAlgorithm#digest(Request)}.
376
+ *
377
+ * @param <K> the type of key used by the algorithm to compute the mac or signature.
378
+ * @return a new builder to create {@link SecureRequest}s used to compute a mac or signature via
379
+ * {@link SecureDigestAlgorithm#digest(Request)}.
380
+ * @since 0.13.0
381
+ */
382
+ @ SuppressWarnings ("unchecked" )
383
+ public static <K extends Key > SecureRequest .Builder <InputStream , K > request () {
384
+ return (SecureRequest .Builder <InputStream , K >) REQUEST_BUILDER_SUPPLIER .get ();
385
+ }
386
+
387
+ /**
388
+ * Returns a new builder to create {@link VerifySecureDigestRequest}s used to verify a mac or signature via
389
+ * {@link SecureDigestAlgorithm#verify(VerifyDigestRequest)}.
390
+ *
391
+ * @param <K> the type of key used by the algorithm to verify the mac or signature.
392
+ * @return a new builder to create {@link VerifySecureDigestRequest}s used to verify a mac or signature via
393
+ * {@link SecureDigestAlgorithm#verify(VerifyDigestRequest)}.
394
+ * @since 0.13.0
395
+ */
396
+ @ SuppressWarnings ("unchecked" )
397
+ public static <K extends Key > VerifySecureDigestRequest .Builder <K > verifyRequest () {
398
+ return (VerifySecureDigestRequest .Builder <K >) VERIFY_REQUEST_BUILDER_SUPPLIER .get ();
399
+ }
305
400
}
306
401
307
402
/**
@@ -323,6 +418,14 @@ public static final class KEY {
323
418
private static final String IMPL_CLASSNAME = "io.jsonwebtoken.impl.security.StandardKeyAlgorithms" ;
324
419
private static final Registry <String , KeyAlgorithm <?, ?>> REGISTRY = Classes .newInstance (IMPL_CLASSNAME );
325
420
421
+ // @since 0.13.0
422
+ private static final Supplier <KeyRequest .Builder <?>> REQUEST_BUILDER_SUPPLIER =
423
+ Classes .newInstance ("io.jsonwebtoken.impl.security.DefaultKeyRequest$Builder$Supplier" );
424
+
425
+ // @since 0.13.0
426
+ private static final Supplier <DecryptionKeyRequest .Builder <?>> VERIFY_REQUEST_BUILDER_SUPPLIER =
427
+ Classes .newInstance ("io.jsonwebtoken.impl.security.DefaultDecryptionKeyRequest$Builder$Supplier" );
428
+
326
429
/**
327
430
* Returns all standard JWA standard <a href="https://www.rfc-editor.org/rfc/rfc7518.html#section-4">Cryptographic
328
431
* Algorithms for Key Management</a>..
@@ -926,6 +1029,34 @@ public static final class KEY {
926
1029
*/
927
1030
public static final KeyAlgorithm <PublicKey , PrivateKey > ECDH_ES_A256KW = Jwts .get (REGISTRY , "ECDH-ES+A256KW" );
928
1031
1032
+ /**
1033
+ * Returns a new builder to create {@link KeyRequest}s used to get a JWE encryption key via
1034
+ * {@link KeyAlgorithm#getEncryptionKey(KeyRequest)}.
1035
+ *
1036
+ * @param <K> the type of key used by the {@link KeyAlgorithm} to get a JWE encryption key.
1037
+ * @return a new builder to create {@link KeyRequest}s used to get a JWE encryption key via
1038
+ * {@link KeyAlgorithm#getEncryptionKey(KeyRequest)}.
1039
+ * @since 0.13.0
1040
+ */
1041
+ @ SuppressWarnings ("unchecked" )
1042
+ public static <K extends Key > KeyRequest .Builder <K > request () {
1043
+ return (KeyRequest .Builder <K >) REQUEST_BUILDER_SUPPLIER .get ();
1044
+ }
1045
+
1046
+ /**
1047
+ * Returns a new builder to create {@link DecryptionKeyRequest}s used to get a JWE decryption key via
1048
+ * {@link KeyAlgorithm#getDecryptionKey(DecryptionKeyRequest)}.
1049
+ *
1050
+ * @param <K> the type of key used by the {@link KeyAlgorithm} to get a JWE decryption key.
1051
+ * @return a new builder to create {@link DecryptionKeyRequest}s used to get a JWE decryption key via
1052
+ * {@link KeyAlgorithm#getDecryptionKey(DecryptionKeyRequest)}.
1053
+ * @since 0.13.0
1054
+ */
1055
+ @ SuppressWarnings ("unchecked" )
1056
+ public static <K extends Key > DecryptionKeyRequest .Builder <K > decRequest () {
1057
+ return (DecryptionKeyRequest .Builder <K >) VERIFY_REQUEST_BUILDER_SUPPLIER .get ();
1058
+ }
1059
+
929
1060
//prevent instantiation
930
1061
private KEY () {
931
1062
}
0 commit comments