001/*******************************************************************************
002 * Copyright 2017 The MIT Internet Trust Consortium
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *   http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *******************************************************************************/
016
017package org.mitre.oauth2.model;
018
019import com.nimbusds.jose.Algorithm;
020import com.nimbusds.jose.Requirement;
021
022/**
023 * @author jricher
024 *
025 */
026public final class PKCEAlgorithm extends Algorithm {
027
028        /**
029         *
030         */
031        private static final long serialVersionUID = 7752852583210088925L;
032
033        public static final PKCEAlgorithm plain = new PKCEAlgorithm("plain", Requirement.REQUIRED);
034
035        public static final PKCEAlgorithm S256 = new PKCEAlgorithm("S256", Requirement.OPTIONAL);
036
037        public PKCEAlgorithm(String name, Requirement req) {
038                super(name, req);
039        }
040
041        public PKCEAlgorithm(String name) {
042                super(name, null);
043        }
044
045        public static PKCEAlgorithm parse(final String s) {
046                if (s.equals(plain.getName())) {
047                        return plain;
048                } else if (s.equals(S256.getName())) {
049                        return S256;
050                } else {
051                        return new PKCEAlgorithm(s);
052                }
053        }
054
055
056
057}