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 PKCS #10 certificate signing request 033 * versions. 034 */ 035@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 036public enum PKCS10CertificateSigningRequestVersion 037{ 038 /** 039 * The PKCS #10 v1 certificate signing request version. 040 */ 041 V1(0, "v1"); 042 043 044 045 // The integer value for this certificate signing request version, as used in 046 // the encoded PKCS #10 request. 047 private final int intValue; 048 049 // The name for this PKCS #10 certificate signing request version. 050 private final String name; 051 052 053 054 /** 055 * Creates a new PKCS #10 certificate signing request version with the 056 * provided information. 057 * 058 * @param intValue The integer value for the certificate signing request 059 * version. Note that this is the integer value that is 060 * used in the encoded request, and not the logical version 061 * number that the encoded value represents (for example, 062 * the "v1" certificate signing request version has an 063 * integer value of 0 rather than 1). 064 * @param name The name for this certificate signing request version. 065 * It must not be {@code null}. 066 */ 067 PKCS10CertificateSigningRequestVersion(final int intValue, final String name) 068 { 069 this.intValue = intValue; 070 this.name = name; 071 } 072 073 074 075 /** 076 * Retrieves the integer value for this certificate signing request version. 077 * Note that this is the integer value that is used in the encoded request, 078 * and not the logical version number that the encoded value represents (for 079 * example, the "v1" certificate signing request version has an integer value 080 * of 0 rather than 1). 081 * 082 * @return The integer value for this certificate signing request version. 083 */ 084 int getIntValue() 085 { 086 return intValue; 087 } 088 089 090 091 /** 092 * Retrieves the name for this certificate signing request version. 093 * 094 * @return The name for this certificate signing request version. 095 */ 096 public String getName() 097 { 098 return name; 099 } 100 101 102 103 /** 104 * Retrieves the certificate signing request version for the provided integer 105 * value. 106 * 107 * @param intValue The integer value for the certificate signing request 108 * version to retrieve. Note that this is the integer value 109 * that is used in the encoded request, and not the logical 110 * version number that the encoded value represents (for 111 * example, the "v1" certificate signing request version has 112 * an integer value of 0 rather than 1). 113 * 114 * @return The certificate signing request version for the provided integer 115 * value, or {@code null} if the provided version does not correspond 116 * to any known certificate signing request version value. 117 */ 118 static PKCS10CertificateSigningRequestVersion valueOf(final int intValue) 119 { 120 for (final PKCS10CertificateSigningRequestVersion v : values()) 121 { 122 if (v.intValue == intValue) 123 { 124 return v; 125 } 126 } 127 128 return null; 129 } 130 131 132 133 /** 134 * Retrieves the CSR version with the specified name. 135 * 136 * @param name The name of the CSR version to retrieve. It must not be 137 * {@code null}. 138 * 139 * @return The requested CSR version, or {@code null} if no such version is 140 * defined. 141 */ 142 public static PKCS10CertificateSigningRequestVersion forName( 143 final String name) 144 { 145 switch (StaticUtils.toLowerCase(name)) 146 { 147 case "1": 148 case "v1": 149 return V1; 150 default: 151 return null; 152 } 153 } 154}