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