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 020 021import java.util.Collections; 022import java.util.Set; 023 024import com.nimbusds.jose.JWSAlgorithm; 025import com.nimbusds.jose.JWSProvider; 026import com.nimbusds.jose.jca.JCAContext; 027 028 029/** 030 * The base abstract class for JSON Web Signature (JWS) signers and verifiers. 031 * 032 * @author Vladimir Dzhuvinov 033 * @version 2015-11-16 034 */ 035public abstract class BaseJWSProvider implements JWSProvider { 036 037 038 /** 039 * The supported algorithms by the JWS provider instance. 040 */ 041 private final Set<JWSAlgorithm> algs; 042 043 044 /** 045 * The JCA context. 046 */ 047 private final JCAContext jcaContext = new JCAContext(); 048 049 050 /** 051 * Creates a new base JWS provider. 052 * 053 * @param algs The supported algorithms by the JWS provider instance. 054 * Must not be {@code null}. 055 */ 056 public BaseJWSProvider(final Set<JWSAlgorithm> algs) { 057 058 if (algs == null) { 059 throw new IllegalArgumentException("The supported JWS algorithm set must not be null"); 060 } 061 062 this.algs = Collections.unmodifiableSet(algs); 063 } 064 065 066 @Override 067 public Set<JWSAlgorithm> supportedJWSAlgorithms() { 068 069 return algs; 070 } 071 072 073 @Override 074 public JCAContext getJCAContext() { 075 076 return jcaContext; 077 } 078} 079