001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019:
020: package org.apache.harmony.security.x509.tsp;
021:
022: import java.security.InvalidParameterException;
023:
024: /**
025: Corresponds to PKIFailureInfo structure.
026: See RFC 3161 -
027: Internet X.509 Public Key Infrastructure
028: Time-Stamp Protocol (TSP)
029: http://www.ietf.org/rfc/rfc3161.txt)
030:
031: PKIFailureInfo ::= BIT STRING {
032: badAlg (0),
033: -- unrecognized or unsupported Algorithm Identifier
034: badRequest (2),
035: -- transaction not permitted or supported
036: badDataFormat (5),
037: -- the data submitted has the wrong format
038: timeNotAvailable (14),
039: -- the TSA's time source is not available
040: unacceptedPolicy (15),
041: -- the requested TSA policy is not supported by the TSA
042: unacceptedExtension (16),
043: -- the requested extension is not supported by the TSA
044: addInfoNotAvailable (17)
045: -- the additional information requested could not be understood
046: -- or is not available
047: systemFailure (25)
048: -- the request cannot be handled due to system failure }
049:
050: The value of PKIFailureInfo can take only one of the values,
051: so it is represented by an integer here.
052: */
053: public enum PKIFailureInfo {
054: /**
055: * Unrecognized algorithm ID
056: */
057: BAD_ALG(0),
058:
059: /**
060: * Transaction is not supported
061: */
062: BAD_REQUEST(2),
063:
064: /**
065: * Data format is wrong
066: */
067: BAD_DATA_FORMAT(5),
068:
069: /**
070: * TSA cannot use the time source
071: */
072: TIME_NOT_AVAILABLE(14),
073:
074: /**
075: * The policy is not supported
076: */
077: UNACCEPTED_POLICY(15),
078:
079: /**
080: * The extension is not supported
081: */
082: UNACCEPTED_EXTENSION(16),
083:
084: /**
085: * The requested additional info is not available
086: */
087: ADD_INFO_NOT_AVAILABLE(17),
088:
089: /**
090: * System failure has occured
091: */
092: SYSTEM_FAILURE(25);
093:
094: private final int value;
095:
096: private static int maxValue;
097:
098: PKIFailureInfo(int value) {
099: this .value = value;
100: }
101:
102: /**
103: * @return int value of the failure
104: */
105: public int getValue() {
106: return value;
107: }
108:
109: /**
110: * @return maximum of values in the enum
111: */
112: public static int getMaxValue() {
113: if (maxValue == 0) {
114: for (PKIFailureInfo cur : values())
115: if (cur.value > maxValue) {
116: maxValue = cur.value;
117: }
118: }
119: return maxValue;
120: }
121:
122: /**
123: * @param value
124: * @return
125: */
126: public static PKIFailureInfo getInstance(int value) {
127: for (PKIFailureInfo info : values()) {
128: if (value == info.value) {
129: return info;
130: }
131: }
132: throw new InvalidParameterException(
133: "Unknown PKIFailureInfo value");
134: }
135: }
|