|
44 | 44 | */
|
45 | 45 | public interface HashAlgorithm extends DigestAlgorithm<Request<InputStream>, VerifyDigestRequest> {
|
46 | 46 |
|
| 47 | + /** |
| 48 | + * Computes a digest of a request {@link Request#getPayload() payload} {@code InputStream} using configured |
| 49 | + * parameters. This is a lambda-style method to execute the request in-line instead of requiring the caller to |
| 50 | + * first use a {@link Request.Builder} to construct the request. |
| 51 | + * |
| 52 | + * <p>Callers are expected to {@link InputStream#close() close} or {@link InputStream#reset() reset} the request |
| 53 | + * payload stream if necessary after calling this method.</p> |
| 54 | + * |
| 55 | + * @param c consumer supporting lambda-style specification of digest {@link Request.Params}. |
| 56 | + * @return the computed digest of the request {@link Request#getPayload() payload}. |
| 57 | + * @since JJWT_RELEASE_VERSION |
| 58 | + */ |
47 | 59 | default byte[] digest(Consumer<Request.Params<InputStream, ?>> c) {
|
48 | 60 | Request.Builder<InputStream> b = Request.builder();
|
49 | 61 | c.accept(b);
|
50 | 62 | Request<InputStream> r = b.build();
|
51 | 63 | return digest(r);
|
52 | 64 | }
|
53 | 65 |
|
| 66 | + /** |
| 67 | + * Computes a digest of the specified {@code is} input stream. |
| 68 | + * |
| 69 | + * <p>Callers are expected to {@link InputStream#close() close} or {@link InputStream#reset() reset} the payload |
| 70 | + * stream if necessary after calling this method.</p> |
| 71 | + * |
| 72 | + * @param is the {@code InputStream} that will be consumed to compute the digest. Callers are expected to |
| 73 | + * {@link InputStream#close() close} or {@link InputStream#reset() reset} the payload stream if necessary |
| 74 | + * after calling this method. |
| 75 | + * @return the computed digest of the specified {@code is} input stream. |
| 76 | + * @since JJWT_RELEASE_VERSION |
| 77 | + */ |
54 | 78 | default byte[] digest(InputStream is) {
|
55 | 79 | return digest(c -> c.payload(is));
|
56 | 80 | }
|
57 | 81 |
|
| 82 | + /** |
| 83 | + * Returns {@code true} if the request's specified {@link VerifyDigestRequest#getDigest() digest} matches (equals) |
| 84 | + * the algorithm's computed digest of the request {@link VerifyDigestRequest#getPayload() payload}, {@code false} |
| 85 | + * otherwise. This is a lambda-style method to execute the request in-line instead of requiring the caller to first |
| 86 | + * use a {@link VerifyDigestRequest.Builder} to construct the request. |
| 87 | + * |
| 88 | + * <p>Callers are expected to {@link InputStream#close() close} or {@link InputStream#reset() reset} the request |
| 89 | + * payload stream if necessary after calling this method.</p> |
| 90 | + * |
| 91 | + * @param c consumer supporting lambda-style specification of {@link VerifyDigestRequest.Params}. |
| 92 | + * @return {@code true} if the request's specified {@link VerifyDigestRequest#getDigest() digest} matches (equals) |
| 93 | + * the algorithm's computed digest of the request {@link VerifyDigestRequest#getPayload() payload}, {@code false} |
| 94 | + * otherwise. |
| 95 | + * @since JJWT_RELEASE_VERSION |
| 96 | + */ |
58 | 97 | default boolean verify(Consumer<VerifyDigestRequest.Params<?>> c) {
|
59 | 98 | VerifyDigestRequest.Builder b = VerifyDigestRequest.builder();
|
60 | 99 | c.accept(b);
|
61 | 100 | VerifyDigestRequest r = b.build();
|
62 | 101 | return verify(r);
|
63 | 102 | }
|
64 | 103 |
|
| 104 | + /** |
| 105 | + * Returns {@code true} if the specified {@code digest} matches (equals) the algorithm's computed digest of the |
| 106 | + * specified {@code is} input stream, {@code false} otherwise. |
| 107 | + * |
| 108 | + * <p>Callers are expected to {@link InputStream#close() close} or {@link InputStream#reset() reset} the payload |
| 109 | + * stream if necessary after calling this method.</p> |
| 110 | + * |
| 111 | + * @param is the {@code InputStream} that will be consumed to compute the digest. Callers are expected to |
| 112 | + * {@link InputStream#close() close} or {@link InputStream#reset() reset} the payload stream if |
| 113 | + * necessary after calling this method. |
| 114 | + * @param digest the previously-computed digest to compare with the algorithm's computed digest of {@code is}. |
| 115 | + * @return {@code true} if the specified {@code digest} matches (equals) the algorithm's computed digest of the |
| 116 | + * specified {@code is} input stream, {@code false} otherwise. |
| 117 | + * @since JJWT_RELEASE_VERSION |
| 118 | + */ |
65 | 119 | default boolean verify(InputStream is, byte[] digest) {
|
66 | 120 | return verify(c -> c.payload(is).digest(digest));
|
67 | 121 | }
|
68 |
| - |
69 | 122 | }
|
0 commit comments