001package com.nimbusds.oauth2.sdk.pkce; 002 003 004import com.nimbusds.oauth2.sdk.auth.Secret; 005 006 007/** 008 * Authorisation code verifier. 009 * 010 * <p>Related specifications: 011 * 012 * <ul> 013 * <li>Proof Key for Code Exchange by OAuth Public Clients (RFC 7636). 014 * </ul> 015 */ 016public class CodeVerifier extends Secret { 017 018 019 /** 020 * The minimal character length of a code verifier. 021 */ 022 public static final int MIN_LENGTH = 43; 023 024 025 /** 026 * The maximum character length of a code verifier. 027 */ 028 public static final int MAX_LENGTH = 128; 029 030 031 /** 032 * Creates a new code verifier with the specified value. 033 * 034 * @param value The code verifier value. Must not contain characters 035 * other than [A-Z] / [a-z] / [0-9] / "-" / "." / "_" / 036 * "~". The verifier length must be at least 43 037 * characters but not more than 128 characters. Must not 038 * be {@code null} or empty string. 039 */ 040 public CodeVerifier(final String value) { 041 super(value); 042 043 if (value.length() < MIN_LENGTH) { 044 throw new IllegalArgumentException("The code verifier must be at least " + MIN_LENGTH + " characters"); 045 } 046 047 if (value.length() > MAX_LENGTH) { 048 throw new IllegalArgumentException("The code verifier must not be longer than " + MAX_LENGTH + " characters"); 049 } 050 } 051 052 053 /** 054 * Creates a new code verifier with the minimum (43 character) length. 055 */ 056 public CodeVerifier() { 057 super(32); 058 } 059 060 061 @Override 062 public boolean equals(final Object object) { 063 return object instanceof CodeVerifier && super.equals(object); 064 } 065}