001/* 002 * The contents of this file are subject to the terms of the Common Development and 003 * Distribution License (the License). You may not use this file except in compliance with the 004 * License. 005 * 006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the 007 * specific language governing permission and limitations under the License. 008 * 009 * When distributing Covered Software, include this CDDL Header Notice in each file and include 010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL 011 * Header, with the fields enclosed by brackets [] replaced by your own identifying 012 * information: "Portions copyright [year] [name of copyright owner]". 013 * 014 * Copyright 2013-2015 ForgeRock AS. 015 */ 016 017package org.forgerock.json.jose.jwe; 018 019/** 020 * An Enum for the additional JWE Header parameter names. 021 * <p> 022 * As described in the JWE specification, the reserved JWE header parameters are listed, 023 * <ul> 024 * <li>"enc"</li> 025 * <li>"epk"</li> 026 * <li>"zip"</li> 027 * <li>"apu"</li> 028 * </ul> 029 * This list add upon the list in {@link org.forgerock.json.jose.jws.JwsHeaderKey}. 030 * Any other header parameter name is deemed as a "custom" header parameter. 031 * 032 * @since 2.0.0 033 */ 034public enum JweHeaderKey { 035 036 /** 037 * Encryption Method header parameter. 038 * @see <a href="http://tools.ietf.org/html/draft-ietf-jose-json-web-encryption-11#section-4.1.2"> 039 * JWE Specification Encryption Method Header Parameter</a> 040 */ 041 ENC, 042 /** 043 * Ephemeral Public Key header parameter. 044 * @see <a href="http://tools.ietf.org/html/draft-ietf-jose-json-web-encryption-11#section-4.1.3"> 045 * JWE Specification Ephermeral Public Key Header Parameter</a> 046 */ 047 EPK, 048 /** 049 * Compression Algorithm header parameter. 050 * @see <a href="http://tools.ietf.org/html/draft-ietf-jose-json-web-encryption-11#section-4.1.4"> 051 * JWW Specification Compression Algorithm Header Parameter</a> 052 */ 053 ZIP, 054 /** 055 * Agreement PartyUInfo header parameter. 056 * @see <a href="http://tools.ietf.org/html/draft-ietf-jose-json-web-encryption-11#section-4.1.13"> 057 * JWW Specification Agreement PartyUInfo Header Parameter</a> 058 **/ 059 APU, 060 /** 061 * Generic header key for a custom header parameter. 062 * @see <a href="http://tools.ietf.org/html/draft-ietf-jose-json-web-signature-11#section-4.3"> 063 * Private Header Parameter Names</a> 064 */ 065 CUSTOM; 066 067 /** 068 * Returns a lowercase String of the JweHeaderKey constant. 069 * 070 * @return Lowercase String representation of the constant. 071 * @see #toString() 072 */ 073 public String value() { 074 return toString(); 075 } 076 077 /** 078 * Gets the JweHeaderKey constant that matches the given String. 079 * <p> 080 * If the given String does not match any of the constants, then CUSTOM is returned. 081 * 082 * @param headerKey The String representation of a JweHeaderKey. 083 * @return The matching JweHeaderKey. 084 */ 085 public static JweHeaderKey getHeaderKey(String headerKey) { 086 try { 087 return JweHeaderKey.valueOf(headerKey); 088 } catch (IllegalArgumentException e) { 089 return CUSTOM; 090 } 091 } 092 093 /** 094 * Turns the JweHeaderKey constant into a lowercase String. 095 * 096 * @return {@inheritDoc} 097 */ 098 @Override 099 public String toString() { 100 return super.toString().toLowerCase(); 101 } 102}