001package com.nimbusds.jose;
002
003
004import net.jcip.annotations.Immutable;
005
006import com.nimbusds.jose.util.Base64URL;
007
008
009/**
010 * The cryptographic parts of a JSON Web Encryption (JWE) object. This class is 
011 * an immutable simple wrapper for returning the cipher text, initialisation 
012 * vector (IV), encrypted key and integrity value from {@link JWEEncrypter} 
013 * implementations.
014 *
015 * @author Vladimir Dzhuvinov
016 * @version $version$ (2012-10-23)
017 */
018@Immutable
019public final class JWECryptoParts {
020
021
022        /**
023         * The encrypted key (optional).
024         */
025        private final Base64URL encryptedKey;
026
027
028        /**
029         * The initialisation vector (optional).
030         */
031        private final Base64URL iv;
032
033
034        /**
035         * The cipher text.
036         */
037        private final Base64URL cipherText;
038
039
040        /**
041         * The integrity value (optional).
042         */
043        private final Base64URL integrityValue;
044
045
046        /**
047         * Creates a new cryptograhic JWE parts instance.
048         *
049         * @param encryptedKey   The encrypted key, {@code null} if not
050         *                       required by the encryption algorithm.
051         * @param iv             The initialisation vector (IV), {@code null} if
052         *                       not required by the encryption algorithm.
053         * @param cipherText     The cipher text. Must not be {@code null}.
054         * @param integrityValue The integrity value, {@code null} if the JWE 
055         *                       algorithm provides built-in integrity check.
056         */
057        public JWECryptoParts(final Base64URL encryptedKey, 
058                        final Base64URL iv,
059                        final Base64URL cipherText, 
060                        final Base64URL integrityValue) {
061
062                this.encryptedKey = encryptedKey;
063
064                this.iv = iv;
065
066                if (cipherText == null) {
067                        throw new IllegalArgumentException("The cipher text must not be null");
068                }
069
070                this.cipherText = cipherText;
071
072                this.integrityValue = integrityValue;
073        }
074
075
076        /**
077         * Gets the encrypted key.
078         *
079         * @return The encrypted key, {@code null} if not required by 
080         *         the JWE algorithm.
081         */
082        public Base64URL getEncryptedKey() {
083
084                return encryptedKey;
085        }
086
087
088        /**
089         * Gets the initialisation vector (IV).
090         *
091         * @return The initialisation vector (IV), {@code null} if not required
092         *         by the JWE algorithm.
093         */
094        public Base64URL getInitializationVector() {
095
096                return iv;
097        }
098
099
100        /**
101         * Gets the cipher text.
102         *
103         * @return The cipher text.
104         */
105        public Base64URL getCipherText() {
106
107                return cipherText;
108        }
109
110
111        /**
112         * Gets the integrity value.
113         *
114         * @return The integrity value, {@code null} if the encryption
115         *         algorithm provides built-in integrity checking.
116         */
117        public Base64URL getIntegrityValue() {
118
119                return integrityValue;
120        }
121}