001/*
002 * Copyright 2017-2020 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2017-2020 Ping Identity Corporation
007 *
008 * Licensed under the Apache License, Version 2.0 (the "License");
009 * you may not use this file except in compliance with the License.
010 * You may obtain a copy of the License at
011 *
012 *    http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing, software
015 * distributed under the License is distributed on an "AS IS" BASIS,
016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017 * See the License for the specific language governing permissions and
018 * limitations under the License.
019 */
020/*
021 * Copyright (C) 2017-2020 Ping Identity Corporation
022 *
023 * This program is free software; you can redistribute it and/or modify
024 * it under the terms of the GNU General Public License (GPLv2 only)
025 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
026 * as published by the Free Software Foundation.
027 *
028 * This program is distributed in the hope that it will be useful,
029 * but WITHOUT ANY WARRANTY; without even the implied warranty of
030 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
031 * GNU General Public License for more details.
032 *
033 * You should have received a copy of the GNU General Public License
034 * along with this program; if not, see <http://www.gnu.org/licenses>.
035 */
036package com.unboundid.util.ssl.cert;
037
038
039
040import com.unboundid.util.StaticUtils;
041import com.unboundid.util.ThreadSafety;
042import com.unboundid.util.ThreadSafetyLevel;
043
044
045
046/**
047 * This enum defines a set of supported PKCS #10 certificate signing request
048 * versions.
049 */
050@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
051public enum PKCS10CertificateSigningRequestVersion
052{
053  /**
054   * The PKCS #10 v1 certificate signing request version.
055   */
056  V1(0, "v1");
057
058
059
060  // The integer value for this certificate signing request version, as used in
061  // the encoded PKCS #10 request.
062  private final int intValue;
063
064  // The name for this PKCS #10 certificate signing request version.
065  private final String name;
066
067
068
069  /**
070   * Creates a new PKCS #10 certificate signing request version with the
071   * provided information.
072   *
073   * @param  intValue  The integer value for the certificate signing request
074   *                   version.  Note that this is the integer value that is
075   *                   used in the encoded request, and not the logical version
076   *                   number that the encoded value represents (for example,
077   *                   the "v1" certificate signing request version has an
078   *                   integer value of 0 rather than 1).
079   * @param  name      The name for this certificate signing request version.
080   *                   It must not be {@code null}.
081   */
082  PKCS10CertificateSigningRequestVersion(final int intValue, final String name)
083  {
084    this.intValue = intValue;
085    this.name = name;
086  }
087
088
089
090  /**
091   * Retrieves the integer value for this certificate signing request version.
092   * Note that this is the integer value that is used in the encoded request,
093   * and not the logical version number that the encoded value represents (for
094   * example, the "v1" certificate signing request version has an integer value
095   * of 0 rather than 1).
096   *
097   * @return  The integer value for this certificate signing request version.
098   */
099  int getIntValue()
100  {
101    return intValue;
102  }
103
104
105
106  /**
107   * Retrieves the name for this certificate signing request version.
108   *
109   * @return  The name for this certificate signing request version.
110   */
111  public String getName()
112  {
113    return name;
114  }
115
116
117
118  /**
119   * Retrieves the certificate signing request version for the provided integer
120   * value.
121   *
122   * @param  intValue  The integer value for the certificate signing request
123   *                   version to retrieve.  Note that this is the integer value
124   *                   that is used in the encoded request, and not the logical
125   *                   version number that the encoded value represents (for
126   *                   example, the "v1" certificate signing request version has
127   *                   an integer value of 0 rather than 1).
128   *
129   * @return  The certificate signing request version for the provided integer
130   *          value, or {@code null} if the provided version does not correspond
131   *          to any known certificate signing request version value.
132   */
133  static PKCS10CertificateSigningRequestVersion valueOf(final int intValue)
134  {
135    for (final PKCS10CertificateSigningRequestVersion v : values())
136    {
137      if (v.intValue == intValue)
138      {
139        return v;
140      }
141    }
142
143    return null;
144  }
145
146
147
148  /**
149   * Retrieves the CSR version with the specified name.
150   *
151   * @param  name  The name of the CSR version to retrieve.  It must not be
152   *               {@code null}.
153   *
154   * @return  The requested CSR version, or {@code null} if no such version is
155   *          defined.
156   */
157  public static PKCS10CertificateSigningRequestVersion forName(
158                                                            final String name)
159  {
160    switch (StaticUtils.toLowerCase(name))
161    {
162      case "1":
163      case "v1":
164        return V1;
165      default:
166        return null;
167    }
168  }
169}