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.security.AlgorithmParameters;
022import java.security.NoSuchAlgorithmException;
023import java.security.Provider;
024
025
026/**
027 * Utility for creating {@link java.security.AlgorithmParameters} objects with
028 * an optional JCA provider.
029 *
030 * @author Justin Richer
031 */
032public class AlgorithmParametersHelper {
033
034
035        /**
036         * Creates a new {@link java.security.AlgorithmParameters} instance.
037         *
038         * @param name     The name of the requested algorithm. Must not be
039         *                 {@code null}.
040         * @param provider The JCA provider, or {@code null} to use the default
041         *                 one.
042         *
043         * @return The AlgorithmParameters instance.
044         *
045         * @throws NoSuchAlgorithmException If an AlgorithmParameterGeneratorSpi
046         *                                  implementation for the specified
047         *                                  algorithm is not available from the
048         *                                  specified Provider object.
049         */
050        public static AlgorithmParameters getInstance(final String name, final Provider provider)
051                throws NoSuchAlgorithmException {
052
053                if (provider == null) {
054                        return AlgorithmParameters.getInstance(name);
055                } else {
056                        return AlgorithmParameters.getInstance(name, provider);
057                }
058        }
059}