001package com.nimbusds.openid.connect.sdk.claims;
002
003
004import net.jcip.annotations.Immutable;
005
006import com.nimbusds.jose.JWSAlgorithm;
007
008import com.nimbusds.oauth2.sdk.AuthorizationCode;
009
010
011/**
012 * Authorisation code hash ({@code c_hash}).
013 *
014 * <p>Related specifications:
015 *
016 * <ul>
017 *     <li>OpenID Connect Core 1.0, section 3.3.2.11.
018 * </ul>
019 */
020@Immutable
021public final class CodeHash extends HashClaim {
022
023
024        /**
025         * Creates a new authorisation code hash with the specified value.
026         *
027         * @param value The authorisation code hash value. Must not be 
028         *              {@code null}.
029         */
030        public CodeHash(final String value) {
031        
032                super(value);
033        }
034
035
036        /**
037         * Computes the hash for the specified authorisation code and reference
038         * JSON Web Signature (JWS) algorithm.
039         *
040         * @param code The authorisation code. Must not be {@code null}.
041         * @param alg  The reference JWS algorithm. Must not be {@code null}.
042         *
043         * @return The authorisation code hash, or {@code null} if the JWS
044         *         algorithm is not supported.
045         */
046        public static CodeHash compute(final AuthorizationCode code, final JWSAlgorithm alg) {
047
048                String value = computeValue(code, alg);
049
050                if (value == null)
051                        return null;
052
053                return new CodeHash(value);
054        }
055
056
057        @Override
058        public boolean equals(final Object object) {
059        
060                return object instanceof CodeHash &&
061                       this.toString().equals(object.toString());
062        }
063}