001package com.nimbusds.jose.proc;
002
003
004import java.text.ParseException;
005
006import com.nimbusds.jose.*;
007
008
009/**
010 * Interface for parsing and processing {@link com.nimbusds.jose.PlainObject
011 * unsecured} (plain), {@link com.nimbusds.jose.JWSObject JWS} and
012 * {@link com.nimbusds.jose.JWEObject JWE} objects.
013 *
014 * @author Vladimir Dzhuvinov
015 * @version 2015-08-20
016 */
017public interface JOSEProcessor<C extends SecurityContext> {
018
019
020        /**
021         * Parses and processes the specified JOSE object (unsecured, JWS or
022         * JWE).
023         *
024         * @param compactEncodedJOSE The JOSE object, compact-encoded to a
025         *                           URL-safe string. Must not be {@code null}.
026         * @param context            Optional context of the JOSE object,
027         *                           {@code null} if not required.
028         *
029         * @return The payload on success.
030         *
031         * @throws ParseException   If the string couldn't be parsed to a valid
032         *                          JOSE object.
033         * @throws BadJOSEException If the JOSE object is rejected.
034         * @throws JOSEException    If an internal processing exception is
035         *                          encountered.
036         */
037        Payload process(final String compactEncodedJOSE, final C context)
038                throws ParseException, BadJOSEException, JOSEException;
039
040
041        /**
042         * Processes the specified JOSE object (unsecured, JWS or JWE).
043         *
044         * @param joseObject The JOSE object. Must not be {@code null}.
045         * @param context    Optional context of the JOSE object, {@code null}
046         *                   if not required.
047         *
048         * @return The payload on success.
049         *
050         * @throws BadJOSEException If the JOSE object is rejected.
051         * @throws JOSEException    If an internal processing exception is
052         *                          encountered.
053         */
054        Payload process(final JOSEObject joseObject, final C context)
055                throws BadJOSEException, JOSEException;
056
057
058        /**
059         * Processes the specified unsecured (plain) JOSE object, typically by
060         * checking its context.
061         *
062         * @param plainObject The unsecured (plain) JOSE object. Not
063         *                    {@code null}.
064         * @param context     Optional context of the unsecured JOSE object,
065         *                    {@code null} if not required.
066         *
067         * @return The payload on success.
068         *
069         * @throws BadJOSEException If the unsecured (plain) JOSE object is
070         *                          rejected.
071         * @throws JOSEException    If an internal processing exception is
072         *                          encountered.
073         */
074        Payload process(final PlainObject plainObject, final C context)
075                throws BadJOSEException, JOSEException;
076
077
078        /**
079         * Processes the specified JWS object by verifying its signature. The
080         * key candidate(s) are selected by examining the JWS header and / or
081         * the message context.
082         *
083         * @param jwsObject The JWS object. Not {@code null}.
084         * @param context   Optional context of the JWS object, {@code null} if
085         *                  not required.
086         *
087         * @return The payload on success.
088         *
089         * @throws BadJOSEException If the JWS object is rejected, typically
090         *                          due to a bad signature.
091         * @throws JOSEException    If an internal processing exception is
092         *                          encountered.
093         */
094        Payload process(final JWSObject jwsObject, final C context)
095                throws BadJOSEException, JOSEException;
096
097
098        /**
099         * Processes the specified JWE object by decrypting it. The key
100         * candidate(s) are selected by examining the JWS header and / or the
101         * message context.
102         *
103         * @param jweObject The JWE object. Not {@code null}.
104         * @param context   Optional context of the JWE object, {@code null} if
105         *                  not required.
106         *
107         * @return The payload on success.
108         *
109         * @throws BadJOSEException If the JWE object is rejected, typically
110         *                          due to failed decryption.
111         * @throws JOSEException    If an internal processing exception is
112         *                          encountered.
113         */
114        Payload process(final JWEObject jweObject, final C context)
115                throws BadJOSEException, JOSEException;
116}
117