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
019import org.forgerock.json.jose.jwt.Algorithm;
020
021/**
022 * An Enum of the possible encryption algorithms that can be used to encrypt a JWT.
023 * <p>
024 * @see <a href="http://tools.ietf.org/html/draft-ietf-jose-json-web-algorithms-11#section-4.1">JWE Algorithms</a>
025 *
026 * @since 2.0.0
027 */
028public enum JweAlgorithm implements Algorithm {
029
030    /** RSA in ECB mode with PKCS1 Padding. */
031    RSAES_PKCS1_V1_5("RSA/ECB/PKCS1Padding", JweAlgorithmType.RSA);
032
033    private final String transformation;
034    private final JweAlgorithmType algorithmType;
035
036    /**
037     * Constructs a new JweAlgorithm with the Java Cryptographic string name of the algorithm and The JweAlgorithmType
038     * of the algorithm.
039     *
040     * @param transformation The Java Cryptographic algorithm name
041     * @param algorithmType The JweAlgorithmType of the JweAlgorithm.
042     */
043    private JweAlgorithm(String transformation, JweAlgorithmType algorithmType) {
044        this.transformation = transformation;
045        this.algorithmType = algorithmType;
046    }
047
048    /**
049     * {@inheritDoc}
050     */
051    @Override
052    public String getAlgorithm() {
053        return transformation;
054    }
055
056    /**
057     * Gets the JweAlgorithmType of the JweAlgorithm.
058     *
059     * @return The JweAlgorithmType.
060     */
061    public JweAlgorithmType getAlgorithmType() {
062        return algorithmType;
063    }
064
065    /**
066     * Turns the JweAlgorithm constant into a JSON value string.
067     *
068     * @return {@inheritDoc}
069     */
070    @Override
071    public String toString() {
072        return super.toString();
073    }
074}