001/*
002 * Copyright 2017-2018 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright (C) 2017-2018 Ping Identity Corporation
007 *
008 * This program is free software; you can redistribute it and/or modify
009 * it under the terms of the GNU General Public License (GPLv2 only)
010 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
011 * as published by the Free Software Foundation.
012 *
013 * This program is distributed in the hope that it will be useful,
014 * but WITHOUT ANY WARRANTY; without even the implied warranty of
015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016 * GNU General Public License for more details.
017 *
018 * You should have received a copy of the GNU General Public License
019 * along with this program; if not, see <http://www.gnu.org/licenses>.
020 */
021package com.unboundid.util.ssl.cert;
022
023
024
025import com.unboundid.util.ThreadSafety;
026import com.unboundid.util.ThreadSafetyLevel;
027
028
029
030/**
031 * This enum defines a set of supported PKCS #10 certificate signing request
032 * versions.
033 */
034@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
035public enum PKCS10CertificateSigningRequestVersion
036{
037  /**
038   * The PKCS #10 v1 certificate signing request version.
039   */
040  V1(0, "v1");
041
042
043
044  // The integer value for this certificate signing request version, as used in
045  // the encoded PKCS #10 request.
046  private final int intValue;
047
048  // The name for this PKCS #10 certificate signing request version.
049  private final String name;
050
051
052
053  /**
054   * Creates a new PKCS #10 certificate signing request version with the
055   * provided information.
056   *
057   * @param  intValue  The integer value for the certificate signing request
058   *                   version.  Note that this is the integer value that is
059   *                   used in the encoded request, and not the logical version
060   *                   number that the encoded value represents (for example,
061   *                   the "v1" certificate signing request version has an
062   *                   integer value of 0 rather than 1).
063   * @param  name      The name for this certificate signing request version.
064   *                   It must not be {@code null}.
065   */
066  PKCS10CertificateSigningRequestVersion(final int intValue, final String name)
067  {
068    this.intValue = intValue;
069    this.name = name;
070  }
071
072
073
074  /**
075   * Retrieves the integer value for this certificate signing request version.
076   * Note that this is the integer value that is used in the encoded request,
077   * and not the logical version number that the encoded value represents (for
078   * example, the "v1" certificate signing request version has an integer value
079   * of 0 rather than 1).
080   *
081   * @return  The integer value for this certificate signing request version.
082   */
083  int getIntValue()
084  {
085    return intValue;
086  }
087
088
089
090  /**
091   * Retrieves the name for this certificate signing request version.
092   *
093   * @return  The name for this certificate signing request version.
094   */
095  public String getName()
096  {
097    return name;
098  }
099
100
101
102  /**
103   * Retrieves the certificate signing request version for the provided integer
104   * value.
105   *
106   * @param  intValue  The integer value for the certificate signing request
107   *                   version to retrieve.  Note that this is the integer value
108   *                   that is used in the encoded request, and not the logical
109   *                   version number that the encoded value represents (for
110   *                   example, the "v1" certificate signing request version has
111   *                   an integer value of 0 rather than 1).
112   *
113   * @return  The certificate signing request version for the provided integer
114   *          value, or {@code null} if the provided version does not correspond
115   *          to any known certificate signing request version value.
116   */
117  static PKCS10CertificateSigningRequestVersion valueOf(final int intValue)
118  {
119    for (final PKCS10CertificateSigningRequestVersion v : values())
120    {
121      if (v.intValue == intValue)
122      {
123        return v;
124      }
125    }
126
127    return null;
128  }
129}