001/* 002 * nimbus-jose-jwt 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.jose.crypto.opts; 019 020 021import com.nimbusds.jose.JWEDecrypterOption; 022import net.jcip.annotations.Immutable; 023 024 025/** 026 * JSON Web Encryption (JWE) decrypter option to configure the maximum allowed 027 * length of compressed cipher text. The 028 * {@link com.nimbusds.jose.JWEObject#MAX_COMPRESSED_CIPHER_TEXT_LENGTH default} 029 * is 100 thousand characters. 030 * 031 * @author Vladimir Dzhuvinov 032 * @version 2025-01-04 033 */ 034@Immutable 035public final class MaxCompressedCipherTextLength implements JWEDecrypterOption { 036 037 038 private final int maxLength; 039 040 041 /** 042 * Creates a new maximum compressed cipher text length option. 043 * 044 * @param maxLength The maximum allowed length, in characters. Must be 045 * positive. 046 */ 047 public MaxCompressedCipherTextLength(final int maxLength) { 048 if (maxLength <= 0) { 049 throw new IllegalArgumentException("The max compressed cipher text length must be a positive integer"); 050 } 051 this.maxLength = maxLength; 052 } 053 054 055 /** 056 * Returns the maximum allowed compressed cipher text length. 057 * 058 * @return The maximum length, in characters. 059 */ 060 public int getMaxLength() { 061 return maxLength; 062 } 063 064 065 @Override 066 public String toString() { 067 return "MaxCompressedCipherTextLength(" + maxLength + ")"; 068 } 069}