1 /*
2 * The contents of this file are subject to the terms of the Common Development and
3 * Distribution License (the License). You may not use this file except in compliance with the
4 * License.
5 *
6 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
7 * specific language governing permission and limitations under the License.
8 *
9 * When distributing Covered Software, include this CDDL Header Notice in each file and include
10 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
11 * Header, with the fields enclosed by brackets [] replaced by your own identifying
12 * information: "Portions copyright [year] [name of copyright owner]".
13 *
14 * Copyright 2013-2015 ForgeRock AS.
15 */
16
17 package org.forgerock.json.jose.jwe;
18
19 /**
20 * An Enum for the additional JWE Header parameter names.
21 * <p>
22 * As described in the JWE specification, the reserved JWE header parameters are listed,
23 * <ul>
24 * <li>"enc"</li>
25 * <li>"epk"</li>
26 * <li>"zip"</li>
27 * <li>"apu"</li>
28 * </ul>
29 * This list add upon the list in {@link org.forgerock.json.jose.jws.JwsHeaderKey}.
30 * Any other header parameter name is deemed as a "custom" header parameter.
31 *
32 * @since 2.0.0
33 */
34 public enum JweHeaderKey {
35
36 /**
37 * Encryption Method header parameter.
38 * @see <a href="http://tools.ietf.org/html/draft-ietf-jose-json-web-encryption-11#section-4.1.2">
39 * JWE Specification Encryption Method Header Parameter</a>
40 */
41 ENC,
42 /**
43 * Ephemeral Public Key header parameter.
44 * @see <a href="http://tools.ietf.org/html/draft-ietf-jose-json-web-encryption-11#section-4.1.3">
45 * JWE Specification Ephermeral Public Key Header Parameter</a>
46 */
47 EPK,
48 /**
49 * Compression Algorithm header parameter.
50 * @see <a href="http://tools.ietf.org/html/draft-ietf-jose-json-web-encryption-11#section-4.1.4">
51 * JWW Specification Compression Algorithm Header Parameter</a>
52 */
53 ZIP,
54 /**
55 * Agreement PartyUInfo header parameter.
56 * @see <a href="http://tools.ietf.org/html/draft-ietf-jose-json-web-encryption-11#section-4.1.13">
57 * JWW Specification Agreement PartyUInfo Header Parameter</a>
58 **/
59 APU,
60 /**
61 * Generic header key for a custom header parameter.
62 * @see <a href="http://tools.ietf.org/html/draft-ietf-jose-json-web-signature-11#section-4.3">
63 * Private Header Parameter Names</a>
64 */
65 CUSTOM;
66
67 /**
68 * Returns a lowercase String of the JweHeaderKey constant.
69 *
70 * @return Lowercase String representation of the constant.
71 * @see #toString()
72 */
73 public String value() {
74 return toString();
75 }
76
77 /**
78 * Gets the JweHeaderKey constant that matches the given String.
79 * <p>
80 * If the given String does not match any of the constants, then CUSTOM is returned.
81 *
82 * @param headerKey The String representation of a JweHeaderKey.
83 * @return The matching JweHeaderKey.
84 */
85 public static JweHeaderKey getHeaderKey(String headerKey) {
86 try {
87 return JweHeaderKey.valueOf(headerKey);
88 } catch (IllegalArgumentException e) {
89 return CUSTOM;
90 }
91 }
92
93 /**
94 * Turns the JweHeaderKey constant into a lowercase String.
95 *
96 * @return {@inheritDoc}
97 */
98 @Override
99 public String toString() {
100 return super.toString().toLowerCase();
101 }
102 }