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 authentication tag from {@link JWEEncrypter} 
013 * implementations.
014 *
015 * @author Vladimir Dzhuvinov
016 * @version $version$ (2012-05-05)
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 authentication tag (optional).
042         */
043        private final Base64URL authenticationTag;
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), 
052         *                          {@code null} if not required by the 
053         *                          encryption algorithm.
054         * @param cipherText        The cipher text. Must not be {@code null}.
055         * @param authenticationTag The authentication tag, {@code null} if the 
056         *                          JWE algorithm provides built-in integrity 
057         *                          check.
058         */
059        public JWECryptoParts(final Base64URL encryptedKey, 
060                              final Base64URL iv,
061                              final Base64URL cipherText, 
062                              final Base64URL authenticationTag) {
063
064                this.encryptedKey = encryptedKey;
065
066                this.iv = iv;
067
068                if (cipherText == null) {
069
070                        throw new IllegalArgumentException("The cipher text must not be null");
071                }
072
073                this.cipherText = cipherText;
074
075                this.authenticationTag = authenticationTag;
076        }
077
078
079        /**
080         * Gets the encrypted key.
081         *
082         * @return The encrypted key, {@code null} if not required by 
083         *         the JWE algorithm.
084         */
085        public Base64URL getEncryptedKey() {
086
087                return encryptedKey;
088        }
089
090
091        /**
092         * Gets the initialisation vector (IV).
093         *
094         * @return The initialisation vector (IV), {@code null} if not required
095         *         by the JWE algorithm.
096         */
097        public Base64URL getInitializationVector() {
098
099                return iv;
100        }
101
102
103        /**
104         * Gets the cipher text.
105         *
106         * @return The cipher text.
107         */
108        public Base64URL getCipherText() {
109
110                return cipherText;
111        }
112
113
114        /**
115         * Gets the authentication tag.
116         *
117         * @return The authentication tag, {@code null} if the encryption
118         *         algorithm provides built-in integrity checking.
119         */
120        public Base64URL getAuthenticationTag() {
121
122                return authenticationTag;
123        }
124
125
126        /**
127         * Use {@link #getAuthenticationTag} instead.
128         */
129        @Deprecated
130        public Base64URL getIntegrityValue() {
131
132                return getAuthenticationTag();
133        }
134}