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
10 * http://www.apache.org/licenses/LICENSE-2.0
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
20 package org.apache.harmony.security.x509.tsp;
22 import java.math.BigInteger;
23 import java.util.List;
24 import org.apache.harmony.security.asn1.ASN1BitString;
25 import org.apache.harmony.security.asn1.ASN1Integer;
26 import org.apache.harmony.security.asn1.ASN1Sequence;
27 import org.apache.harmony.security.asn1.ASN1SequenceOf;
28 import org.apache.harmony.security.asn1.ASN1StringType;
29 import org.apache.harmony.security.asn1.ASN1Type;
30 import org.apache.harmony.security.asn1.BerInputStream;
31 import org.apache.harmony.security.asn1.BitString;
35 * As defined in Time-Stamp Protocol (TSP)
36 * (http://www.ietf.org/rfc/rfc3161.txt)
38 * PKIStatusInfo ::= SEQUENCE {
40 * statusString PKIFreeText OPTIONAL,
41 * failInfo PKIFailureInfo OPTIONAL
45 public class PKIStatusInfo {
47 private final PKIStatus status;
49 private final List statusString;
51 private final PKIFailureInfo failInfo;
53 public PKIStatusInfo(PKIStatus pKIStatus, List statusString,
54 PKIFailureInfo failInfo) {
55 this.status = pKIStatus;
56 this.statusString = statusString;
57 this.failInfo = failInfo;
60 public String toString(){
61 StringBuilder res = new StringBuilder();
62 res.append("-- PKIStatusInfo:");
63 res.append("\nPKIStatus : ");
65 res.append("\nstatusString: ");
66 res.append(statusString);
67 res.append("\nfailInfo: ");
69 res.append("\n-- PKIStatusInfo End\n");
70 return res.toString();
74 * @return Returns the failInfo.
76 public PKIFailureInfo getFailInfo() {
81 * @return Returns the pKIStatus.
83 public PKIStatus getStatus() {
88 * @return Returns the statusString.
90 public List getStatusString() {
94 public static final ASN1Sequence ASN1 = new ASN1Sequence(new ASN1Type[] {
95 ASN1Integer.getInstance(), // status
96 new ASN1SequenceOf(ASN1StringType.UTF8STRING), // statusString
97 ASN1BitString.getInstance() }) { // failInfo
103 protected void getValues(Object object, Object[] values) {
104 PKIStatusInfo psi = (PKIStatusInfo) object;
105 values[0] = BigInteger.valueOf(psi.status.getStatus())
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
112 failInfoBoolArray[psi.failInfo.getValue()] = true;
113 values[2] = new BitString(failInfoBoolArray);
119 protected Object getDecodedObject(BerInputStream in) {
120 Object[] values = (Object[]) in.content;
122 int failInfoValue = -1;
123 if (values[2] != null) {
124 boolean[] failInfoBoolArray = ((BitString) values[2]).toBooleanArray();
125 for (int i = 0; i < failInfoBoolArray.length; i++) {
126 if (failInfoBoolArray[i]) {
132 return new PKIStatusInfo(
133 PKIStatus.getInstance(ASN1Integer.toIntValue(values[0])),
135 PKIFailureInfo.getInstance(failInfoValue));