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}). This class is immutable. 013 * 014 * <p>Related specifications: 015 * 016 * <ul> 017 * <li>OpenID Connect Messages 1.0, section 2.1.1. 018 * </ul> 019 * 020 * @author Vladimir Dzhuvinov 021 */ 022@Immutable 023public final class CodeHash extends HashClaim { 024 025 026 /** 027 * Creates a new authorisation code hash with the specified value. 028 * 029 * @param value The authorisation code hash value. Must not be 030 * {@code null}. 031 */ 032 public CodeHash(final String value) { 033 034 super(value); 035 } 036 037 038 /** 039 * Computes the hash for the specified authorisation code and reference 040 * JSON Web Signature (JWS) algorithm. 041 * 042 * @param code The authorisation code. Must not be {@code null}. 043 * @param alg The reference JWS algorithm. Must not be {@code null}. 044 * 045 * @return The authorisation code hash, or {@code null} if the JWS 046 * algorithm is not supported. 047 */ 048 public static CodeHash compute(final AuthorizationCode code, final JWSAlgorithm alg) { 049 050 String value = computeValue(code, alg); 051 052 if (value == null) 053 return null; 054 055 return new CodeHash(value); 056 } 057 058 059 @Override 060 public boolean equals(final Object object) { 061 062 return object instanceof CodeHash && 063 this.toString().equals(object.toString()); 064 } 065}