1/* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 20package org.apache.harmony.security.x509.tsp; 21 22import java.security.InvalidParameterException; 23 24/** 25 Corresponds to PKIFailureInfo structure. 26 See RFC 3161 - 27 Internet X.509 Public Key Infrastructure 28 Time-Stamp Protocol (TSP) 29 http://www.ietf.org/rfc/rfc3161.txt) 30 31 PKIFailureInfo ::= BIT STRING { 32 badAlg (0), 33 -- unrecognized or unsupported Algorithm Identifier 34 badRequest (2), 35 -- transaction not permitted or supported 36 badDataFormat (5), 37 -- the data submitted has the wrong format 38 timeNotAvailable (14), 39 -- the TSA's time source is not available 40 unacceptedPolicy (15), 41 -- the requested TSA policy is not supported by the TSA 42 unacceptedExtension (16), 43 -- the requested extension is not supported by the TSA 44 addInfoNotAvailable (17) 45 -- the additional information requested could not be understood 46 -- or is not available 47 systemFailure (25) 48 -- the request cannot be handled due to system failure } 49 50 The value of PKIFailureInfo can take only one of the values, 51 so it is represented by an integer here. 52 */ 53public enum PKIFailureInfo { 54 /** 55 * Unrecognized algorithm ID 56 */ 57 BAD_ALG(0), 58 59 /** 60 * Transaction is not supported 61 */ 62 BAD_REQUEST(2), 63 64 /** 65 * Data format is wrong 66 */ 67 BAD_DATA_FORMAT(5), 68 69 /** 70 * TSA cannot use the time source 71 */ 72 TIME_NOT_AVAILABLE(14), 73 74 /** 75 * The policy is not supported 76 */ 77 UNACCEPTED_POLICY(15), 78 79 /** 80 * The extension is not supported 81 */ 82 UNACCEPTED_EXTENSION(16), 83 84 /** 85 * The requested additional info is not available 86 */ 87 ADD_INFO_NOT_AVAILABLE(17), 88 89 /** 90 * System failure has occured 91 */ 92 SYSTEM_FAILURE(25); 93 94 95 private final int value; 96 97 private static int maxValue; 98 99 PKIFailureInfo(int value) { 100 this.value = value; 101 } 102 103 /** 104 * @return int value of the failure 105 */ 106 public int getValue() { 107 return value; 108 } 109 110 /** 111 * @return maximum of values in the enum 112 */ 113 public static int getMaxValue() { 114 if (maxValue == 0) { 115 for (PKIFailureInfo cur : values()) 116 if (cur.value > maxValue) { 117 maxValue = cur.value; 118 } 119 } 120 return maxValue; 121 } 122 123 /** 124 * @param value 125 * @return 126 */ 127 public static PKIFailureInfo getInstance(int value) { 128 for (PKIFailureInfo info : values()){ 129 if (value == info.value) { 130 return info; 131 } 132 } 133 throw new InvalidParameterException("Unknown PKIFailureInfo value"); 134 } 135} 136 137