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.math.BigInteger;
023: import java.util.List;
024:
025: import org.apache.harmony.security.asn1.ASN1BitString;
026: import org.apache.harmony.security.asn1.ASN1Integer;
027: import org.apache.harmony.security.asn1.ASN1Sequence;
028: import org.apache.harmony.security.asn1.ASN1SequenceOf;
029: import org.apache.harmony.security.asn1.ASN1StringType;
030: import org.apache.harmony.security.asn1.ASN1Type;
031: import org.apache.harmony.security.asn1.BerInputStream;
032: import org.apache.harmony.security.asn1.BitString;
033:
034: /**
035: * As defined in Time-Stamp Protocol (TSP)
036: * (http://www.ietf.org/rfc/rfc3161.txt)
037: *
038: * PKIStatusInfo ::= SEQUENCE {
039: * status PKIStatus,
040: * statusString PKIFreeText OPTIONAL,
041: * failInfo PKIFailureInfo OPTIONAL
042: * }
043: *
044: */
045: public class PKIStatusInfo {
046:
047: private final PKIStatus status;
048:
049: private final List statusString;
050:
051: private final PKIFailureInfo failInfo;
052:
053: public PKIStatusInfo(PKIStatus pKIStatus, List statusString,
054: PKIFailureInfo failInfo) {
055: this .status = pKIStatus;
056: this .statusString = statusString;
057: this .failInfo = failInfo;
058: }
059:
060: public String toString() {
061: StringBuffer res = new StringBuffer();
062: res.append("-- PKIStatusInfo:");
063: res.append("\nPKIStatus : ");
064: res.append(status);
065: res.append("\nstatusString: ");
066: res.append(statusString);
067: res.append("\nfailInfo: ");
068: res.append(failInfo);
069: res.append("\n-- PKIStatusInfo End\n");
070: return res.toString();
071: }
072:
073: /**
074: * @return Returns the failInfo.
075: */
076: public PKIFailureInfo getFailInfo() {
077: return failInfo;
078: }
079:
080: /**
081: * @return Returns the pKIStatus.
082: */
083: public PKIStatus getStatus() {
084: return status;
085: }
086:
087: /**
088: * @return Returns the statusString.
089: */
090: public List getStatusString() {
091: return statusString;
092: }
093:
094: public static final ASN1Sequence ASN1 = new ASN1Sequence(
095: new ASN1Type[] { ASN1Integer.getInstance(), // status
096: new ASN1SequenceOf(ASN1StringType.UTF8STRING), // statusString
097: ASN1BitString.getInstance() }) { // failInfo
098: {
099: setOptional(1);
100: setOptional(2);
101: }
102:
103: protected void getValues(Object object, Object[] values) {
104: PKIStatusInfo psi = (PKIStatusInfo) object;
105: values[0] = BigInteger.valueOf(psi.status.getStatus())
106: .toByteArray();
107: values[1] = psi.statusString;
108: if (psi.failInfo != null) {
109: // set the needed bit in the bit string
110: boolean[] failInfoBoolArray = new boolean[PKIFailureInfo
111: .getMaxValue()];
112: failInfoBoolArray[psi.failInfo.getValue()] = true;
113: values[2] = new BitString(failInfoBoolArray);
114: } else {
115: values[2] = null;
116: }
117: }
118:
119: protected Object getDecodedObject(BerInputStream in) {
120: Object[] values = (Object[]) in.content;
121:
122: int failInfoValue = -1;
123: if (values[2] != null) {
124: boolean[] failInfoBoolArray = ((BitString) values[2])
125: .toBooleanArray();
126: for (int i = 0; i < failInfoBoolArray.length; i++) {
127: if (failInfoBoolArray[i]) {
128: failInfoValue = i;
129: break;
130: }
131: }
132: }
133: return new PKIStatusInfo(PKIStatus.getInstance(ASN1Integer
134: .toIntValue(values[0])), (List) values[1],
135: PKIFailureInfo.getInstance(failInfoValue));
136: }
137: };
138: }
|