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.impl; 019 020import com.nimbusds.jose.JOSEException; 021import com.nimbusds.jose.JWEAlgorithm; 022import com.nimbusds.jose.JWEHeader; 023 024 025/** 026 * JWE header validation. 027 * 028 * @author Vladimir Dzhuvinov 029 * @version 2023-09-10 030 */ 031public class JWEHeaderValidation { 032 033 034 /** 035 * Gets the JWE algorithm of the specified header and ensure it is not 036 * {@code null}. 037 * 038 * @param jweHeader The JWE header. Must not be {@code null}. 039 * 040 * @return The JWE algorithm. 041 * 042 * @throws JOSEException If the JWE {@code alg} header parameter is 043 * {@code null}. 044 */ 045 public static JWEAlgorithm getAlgorithmAndEnsureNotNull(final JWEHeader jweHeader) 046 throws JOSEException { 047 048 JWEAlgorithm alg = jweHeader.getAlgorithm(); 049 if (alg == null) { 050 throw new JOSEException("The algorithm \"alg\" header parameter must not be null"); 051 } 052 return alg; 053 } 054 055 056 private JWEHeaderValidation() {} 057}