001/* 002 * nimbus-jose-jwt 003 * 004 * Copyright 2012-2016, Connect2id Ltd. 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; 019 020 021import java.security.Key; 022import java.util.Arrays; 023 024 025/** 026 * Key type exception. 027 * 028 * @author Vladimir Dzhuvinov 029 * @author stisve 030 * @version 2020-03-03 031 */ 032public class KeyTypeException extends KeyException { 033 034 035 /** 036 * Creates a new key type exception. 037 * 038 * @param expectedKeyClass The expected key class. Should not be 039 * {@code null}. 040 */ 041 public KeyTypeException(final Class<? extends Key> expectedKeyClass) { 042 043 super("Invalid key: Must be an instance of " + expectedKeyClass); 044 } 045 046 /** 047 * Creates a new key type exception. 048 * 049 * @param expectedKeyInterface The expected key interfaces. Should not 050 * be {@code null}. 051 * @param additionalInterfaces Additional interfaces the key is required to implement. 052 */ 053 public KeyTypeException(final Class<? extends Key> expectedKeyInterface, final Class<?> ... additionalInterfaces) { 054 055 super("Invalid key: Must be an instance of " + expectedKeyInterface 056 + " and implement all of the following interfaces " + Arrays.toString(additionalInterfaces)); 057 } 058}