001/*
002 * oauth2-oidc-sdk
003 *
004 * Copyright 2012-2016, Connect2id Ltd and contributors.
005 *
006 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use
007 * this file except in compliance with the License. You may obtain a copy of the
008 * License at
009 *
010 *    http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software distributed
013 * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
014 * CONDITIONS OF ANY KIND, either express or implied. See the License for the
015 * specific language governing permissions and limitations under the License.
016 */
017
018package com.nimbusds.openid.connect.sdk.claims;
019
020
021import com.nimbusds.jose.JWSAlgorithm;
022import com.nimbusds.oauth2.sdk.id.State;
023import net.jcip.annotations.Immutable;
024
025
026/**
027 * State hash ({@code s_hash}).
028 *
029 * <p>Related specifications:
030 *
031 * <ul>
032 *     <li>Financial Services – Financial API - Part 2: Read and Write API
033 *         Security Profile, section 5.1.
034 * </ul>
035 */
036@Immutable
037public class StateHash extends HashClaim {
038        
039        
040        /**
041         * Creates a new state hash with the specified value.
042         *
043         * @param value The state hash value. Must not be {@code null}.
044         */
045        public StateHash(final String value) {
046                
047                super(value);
048        }
049        
050        
051        /**
052         * Computes the hash for the specified state and reference JSON
053         * Web Signature (JWS) algorithm.
054         *
055         * @param state The state. Must not be {@code null}.
056         * @param alg   The reference JWS algorithm. Must not be {@code null}.
057         *
058         * @return The state hash, or {@code null} if the JWS algorithm is not
059         *         supported.
060         */
061        public static StateHash compute(final State state, final JWSAlgorithm alg) {
062                
063                String value = computeValue(state, alg);
064                
065                if (value == null)
066                        return null;
067                
068                return new StateHash(value);
069        }
070        
071        
072        @Override
073        public boolean equals(final Object object) {
074                
075                return object instanceof StateHash &&
076                        this.toString().equals(object.toString());
077        }
078}