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.StaticUtils;
026import com.unboundid.util.ThreadSafety;
027import com.unboundid.util.ThreadSafetyLevel;
028
029
030
031/**
032 * This enum defines a set of supported RSA private key versions.
033 */
034@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
035public enum RSAPrivateKeyVersion
036{
037  /**
038   * The two-prime RSA private key version.
039   */
040  TWO_PRIME(0, "two-prime"),
041
042
043
044  /**
045   * The multi RSA private key version.
046   */
047  MULTI(1, "multi");
048
049
050
051  // The integer value for this RSA private key version.
052  private final int intValue;
053
054  // The name for this RSA private key version.
055  private final String name;
056
057
058
059  /**
060   * Creates a new RSA private key version with the provided information.
061   *
062   * @param  intValue  The integer value for the private key version.
063   * @param  name      The name for this private key version.  It must not be
064   *                   {@code null}.
065   */
066  RSAPrivateKeyVersion(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 private key version.
076   *
077   * @return  The integer value for this private key version.
078   */
079  int getIntValue()
080  {
081    return intValue;
082  }
083
084
085
086  /**
087   * Retrieves the name for this private key version.
088   *
089   * @return  The name for this private key version.
090   */
091  public String getName()
092  {
093    return name;
094  }
095
096
097
098  /**
099   * Retrieves the private key version for the provided integer value.
100   *
101   * @param  intValue  The integer value for the private key version to
102   *                   retrieve.
103   *
104   * @return  The private key version for the provided integer value, or
105   *          {@code null} if the provided version does not correspond to any
106   *          known private key version value.
107   */
108  static RSAPrivateKeyVersion valueOf(final int intValue)
109  {
110    for (final RSAPrivateKeyVersion v : values())
111    {
112      if (v.intValue == intValue)
113      {
114        return v;
115      }
116    }
117
118    return null;
119  }
120
121
122
123  /**
124   * Retrieves the RSA private key version with the specified name.
125   *
126   * @param  name  The name of the RSA private key version to retrieve.  It must
127   *               not be {@code null}.
128   *
129   * @return  The requested RSA private key version, or {@code null} if no such
130   *          version is defined.
131   */
132  public static RSAPrivateKeyVersion forName(final String name)
133  {
134    switch (StaticUtils.toLowerCase(name))
135    {
136      case "twoprime":
137      case "two-prime":
138      case "two_prime":
139        return TWO_PRIME;
140      case "multi":
141        return MULTI;
142      default:
143        return null;
144    }
145  }
146}