MCPcopy Create free account
hub / github.com/jwtk/jjwt / DefaultJweHeader

Class DefaultJweHeader

impl/src/main/java/io/jsonwebtoken/impl/DefaultJweHeader.java:37–126  ·  view source on GitHub ↗

Header implementation satisfying JWE header parameter requirements. @since 0.12.0

Source from the content-addressed store, hash-verified

35 * @since 0.12.0
36 */
37public class DefaultJweHeader extends DefaultProtectedHeader implements JweHeader {
38
39 static final Parameter<String> ENCRYPTION_ALGORITHM = Parameters.string("enc", "Encryption Algorithm");
40
41 public static final Parameter<PublicJwk<?>> EPK = Parameters.builder(JwkConverter.PUBLIC_JWK_CLASS)
42 .setId("epk").setName("Ephemeral Public Key")
43 .setConverter(JwkConverter.PUBLIC_JWK).build();
44 static final Parameter<byte[]> APU = Parameters.bytes("apu", "Agreement PartyUInfo").build();
45 static final Parameter<byte[]> APV = Parameters.bytes("apv", "Agreement PartyVInfo").build();
46
47 // https://www.rfc-editor.org/rfc/rfc7518.html#section-4.7.1.1 says 96 bits required:
48 public static final Parameter<byte[]> IV = Parameters.bytes("iv", "Initialization Vector")
49 .setConverter(new RequiredBitLengthConverter(Converters.BASE64URL_BYTES, 96)).build();
50
51 // https://www.rfc-editor.org/rfc/rfc7518.html#section-4.7.1.2 says 128 bits required:
52 public static final Parameter<byte[]> TAG = Parameters.bytes("tag", "Authentication Tag")
53 .setConverter(new RequiredBitLengthConverter(Converters.BASE64URL_BYTES, 128)).build();
54
55 // https://www.rfc-editor.org/rfc/rfc7518.html#section-4.8.1.1 says at least 64 bits (8 bytes) is required:
56 public static final Parameter<byte[]> P2S = Parameters.bytes("p2s", "PBES2 Salt Input")
57 .setConverter(new RequiredBitLengthConverter(Converters.BASE64URL_BYTES, 64, false)).build();
58 public static final Parameter<Integer> P2C = Parameters.builder(Integer.class)
59 .setConverter(PositiveIntegerConverter.INSTANCE).setId("p2c").setName("PBES2 Count").build();
60
61 static final Registry<String, Parameter<?>> PARAMS =
62 Parameters.registry(DefaultProtectedHeader.PARAMS, ENCRYPTION_ALGORITHM, EPK, APU, APV, IV, TAG, P2S, P2C);
63
64 static boolean isCandidate(ParameterMap map) {
65 String id = map.get(DefaultHeader.ALGORITHM);
66 return Strings.hasText(id) && !id.equalsIgnoreCase(Jwts.SIG.NONE.getId()) && // alg cannot be empty or 'none'
67 Strings.hasText(map.get(ENCRYPTION_ALGORITHM)); // enc cannot be empty
68// return Strings.hasText(map.get(ENCRYPTION_ALGORITHM)) || // MUST have at least an `enc` header
69// !Collections.isEmpty(map.get(EPK)) ||
70// !Bytes.isEmpty(map.get(APU)) ||
71// !Bytes.isEmpty(map.get(APV)) ||
72// !Bytes.isEmpty(map.get(IV)) ||
73// !Bytes.isEmpty(map.get(TAG)) ||
74// !Bytes.isEmpty(map.get(P2S)) ||
75// (map.get(P2C) != null && map.get(P2C) > 0);
76
77 }
78
79 public DefaultJweHeader(Map<String, ?> map) {
80 super(PARAMS, map);
81 }
82
83 @Override
84 public String getName() {
85 return "JWE header";
86 }
87
88 @Override
89 public String getEncryptionAlgorithm() {
90 return get(ENCRYPTION_ALGORITHM);
91 }
92
93 @Override
94 public PublicJwk<?> getEphemeralPublicKey() {

Callers

nothing calls this directly

Calls 8

stringMethod · 0.95
builderMethod · 0.95
bytesMethod · 0.95
registryMethod · 0.95
buildMethod · 0.65
setConverterMethod · 0.65
setNameMethod · 0.65
setIdMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…