Skip to content

Commit 6f219c8

Browse files
committed
- JavaDoc fixes/enhancements
- Fixed erroneous README.md method name reference - ensured DefaultJwkContext#getName() supports Octet keys as well.
1 parent 383517e commit 6f219c8

File tree

4 files changed

+40
-8
lines changed

4 files changed

+40
-8
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2432,17 +2432,17 @@ String kid = jwk.thumbprint().toString();
24322432
jwk.setId(kid) // Jwks are immutable - there is no `setId` method
24332433
```
24342434

2435-
Instead, you may use the `setIdAsThumbprint` methods on the `JwkBuilder` when creating a `Jwk`:
2435+
Instead, you may use the `setIdFromThumbprint` methods on the `JwkBuilder` when creating a `Jwk`:
24362436

24372437
```java
24382438
Jwk<?> jwk = Jwks.builder().forKey(aKey)
24392439

2440-
.setIdAsThumbprint() // or setIdAsThumbprint(hashAlgorithm)
2440+
.setIdFromThumbprint() // or setIdFromThumbprint(hashAlgorithm)
24412441

24422442
.build();
24432443
```
24442444

2445-
Calling either `setIdAsThumbprint` method will ensure that calling `jwk.getId()` equals `thumbprint.toString()`
2445+
Calling either `setIdFromThumbprint` method will ensure that calling `jwk.getId()` equals `thumbprint.toString()`
24462446
(which is `Encoders.BASE64URL.encode(thumbprint.toByteArray())`).
24472447

24482448
<a name="jwk-thumbprint-uri"></a>

api/src/main/java/io/jsonwebtoken/JwtBuilder.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,18 @@ public interface JwtBuilder extends ClaimsMutator<JwtBuilder> {
525525
* <td>4096 &lt;= size <sup>5</sup></td>
526526
* <td>{@link StandardSecureDigestAlgorithms#RS512 RS512}</td>
527527
* </tr>
528+
* <tr>
529+
* <td><a href="https://docs.oracle.com/en/java/javase/15/docs/api/java.base/java/security/interfaces/EdECKey.html">EdECKey</a><sup>7</sup></td>
530+
* <td><code>instanceof {@link PrivateKey}</code></td>
531+
* <td>256</td>
532+
* <td>{@link StandardSecureDigestAlgorithms#Ed25519 Ed25519}</td>
533+
* </tr>
534+
* <tr>
535+
* <td><a href="https://docs.oracle.com/en/java/javase/15/docs/api/java.base/java/security/interfaces/EdECKey.html">EdECKey</a><sup>7</sup></td>
536+
* <td><code>instanceof {@link PrivateKey}</code></td>
537+
* <td>456</td>
538+
* <td>{@link StandardSecureDigestAlgorithms#Ed448 Ed448}</td>
539+
* </tr>
528540
* </tbody>
529541
* </table>
530542
* <p>Notes:</p>
@@ -553,6 +565,8 @@ public interface JwtBuilder extends ClaimsMutator<JwtBuilder> {
553565
* {@link StandardSecureDigestAlgorithms#RS512 RS512} algorithms, so we assume an RSA signature algorithm based on the key
554566
* length to parallel similar decisions in the JWT specification for HMAC and ECDSA signature algorithms.
555567
* This is not required - just a convenience.</li>
568+
* <li><a href="https://docs.oracle.com/en/java/javase/15/docs/api/java.base/java/security/interfaces/EdECKey.html">EdECKey</a>s
569+
* require JDK >= 15 or BouncyCastle in the runtime classpath.</li>
556570
* </ol>
557571
*
558572
* <p>This implementation does not use the {@link StandardSecureDigestAlgorithms#PS256 PS256},
@@ -564,13 +578,13 @@ public interface JwtBuilder extends ClaimsMutator<JwtBuilder> {
564578
* {@link #signWith(Key, SecureDigestAlgorithm)} method instead.</p>
565579
*
566580
* <p>Finally, this method will throw an {@link InvalidKeyException} for any key that does not match the
567-
* heuristics and requirements documented above, since that inevitably means the Key is either insufficient or
568-
* explicitly disallowed by the JWT specification.</p>
581+
* heuristics and requirements documented above, since that inevitably means the Key is either insufficient,
582+
* unsupported, or explicitly disallowed by the JWT specification.</p>
569583
*
570584
* @param key the key to use for signing
571585
* @return the builder instance for method chaining.
572-
* @throws InvalidKeyException if the Key is insufficient or explicitly disallowed by the JWT specification as
573-
* described above in <em>recommended signature algorithms</em>.
586+
* @throws InvalidKeyException if the Key is insufficient, unsupported, or explicitly disallowed by the JWT
587+
* specification as described above in <em>recommended signature algorithms</em>.
574588
* @see Jwts#SIG
575589
* @see #signWith(Key, SecureDigestAlgorithm)
576590
* @since 0.10.0
@@ -751,7 +765,7 @@ public interface JwtBuilder extends ClaimsMutator<JwtBuilder> {
751765
* {@code keyAlg} when invoked with the given {@code key}, producing a JWE.
752766
*
753767
* <p>This behavior can be illustrated by the following pseudocode, a rough example of what happens during
754-
* {@link #compact() compact}ion:</p>
768+
* {@link #compact() compact}ion:</p>
755769
* <blockquote><pre>
756770
* SecretKey encryptionKey = keyAlg.getEncryptionKey(key); // (1)
757771
* byte[] jweCiphertext = enc.encrypt(payloadBytes, encryptionKey); // (2)</pre></blockquote>

impl/src/main/java/io/jsonwebtoken/impl/security/DefaultJwkContext.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ public String getName() {
126126
String value = get(AbstractJwk.KTY);
127127
if (DefaultSecretJwk.TYPE_VALUE.equals(value)) {
128128
value = "Secret";
129+
} else if (DefaultOctetPublicJwk.TYPE_VALUE.equals(value)) {
130+
value = "Octet";
129131
}
130132
StringBuilder sb = value != null ? new StringBuilder(value) : new StringBuilder();
131133
K key = getKey();

impl/src/test/groovy/io/jsonwebtoken/impl/security/DefaultJwkContextTest.groovy

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,22 @@ class DefaultJwkContextTest {
4848
assertEquals 'Private JWK', ctx.getName()
4949
}
5050

51+
@Test
52+
void testGetNameWithEdwardsPublicKey() {
53+
def ctx = new DefaultJwkContext()
54+
ctx.setKey(TestKeys.X448.pair.public)
55+
ctx.setType(DefaultOctetPublicJwk.TYPE_VALUE)
56+
assertEquals 'Octet Public JWK', ctx.getName()
57+
}
58+
59+
@Test
60+
void testGetNameWithEdwardsPrivateKey() {
61+
def ctx = new DefaultJwkContext()
62+
ctx.setKey(TestKeys.X448.pair.private)
63+
ctx.setType(DefaultOctetPublicJwk.TYPE_VALUE)
64+
assertEquals 'Octet Private JWK', ctx.getName()
65+
}
66+
5167
@Test
5268
void testGStringPrintsRedactedValues() {
5369
// DO NOT REMOVE THIS METHOD: IT IS CRITICAL TO ENSURE GROOVY STRINGS DO NOT LEAK SECRET/PRIVATE KEY MATERIAL

0 commit comments

Comments
 (0)