KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > novosec > pkix > asn1 > cmp > ErrorMsgContent


1 // CMP implementation copyright (c) 2003 NOVOSEC AG (http://www.novosec.com)
2
//
3
// Author: Maik Stohn
4
//
5
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
6
// software and associated documentation files (the "Software"), to deal in the Software
7
// without restriction, including without limitation the rights to use, copy, modify, merge,
8
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
9
// to whom the Software is furnished to do so, subject to the following conditions:
10
//
11
// The above copyright notice and this permission notice shall be included in all copies or
12
// substantial portions of the Software.
13
//
14
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
15
// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
17
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19

20 package com.novosec.pkix.asn1.cmp;
21
22 import org.bouncycastle.asn1.ASN1EncodableVector;
23 import org.bouncycastle.asn1.ASN1Sequence;
24 import org.bouncycastle.asn1.ASN1TaggedObject;
25 import org.bouncycastle.asn1.DEREncodable;
26 import org.bouncycastle.asn1.DERInteger;
27 import org.bouncycastle.asn1.DERObject;
28 import org.bouncycastle.asn1.DERSequence;
29
30 /**
31  * ASN.1 structure DER En/DeCoder.
32  *
33  * <pre>
34  * ErrorMsgContent ::= SEQUENCE {
35  * pKIStatusInfo PKIStatusInfo,
36  * errorCode INTEGER OPTIONAL, -- implementation-specific error codes
37  * errorDetails PKIFreeText OPTIONAL -- implementation-specific error details
38  * }
39  *
40  * </pre>
41  */

42 public class ErrorMsgContent implements DEREncodable
43 {
44     PKIStatusInfo pKIStatusInfo;
45     DERInteger errorCode;
46     PKIFreeText errorDetails;
47
48     public static ErrorMsgContent getInstance( ASN1TaggedObject obj, boolean explicit )
49     {
50         return getInstance(ASN1Sequence.getInstance(obj, explicit));
51     }
52
53     public static ErrorMsgContent getInstance( Object JavaDoc obj )
54     {
55         if (obj instanceof ErrorMsgContent)
56         {
57             return (ErrorMsgContent)obj;
58         }
59         else if (obj instanceof ASN1Sequence)
60         {
61             return new ErrorMsgContent((ASN1Sequence)obj);
62         }
63
64         throw new IllegalArgumentException JavaDoc("unknown object in factory");
65     }
66     
67     public ErrorMsgContent( ASN1Sequence seq )
68     {
69       this.pKIStatusInfo = PKIStatusInfo.getInstance( seq.getObjectAt(0) );
70       
71       this.errorCode = null;
72       this.errorDetails = null;
73       
74       if( seq.size() > 2 )
75       {
76         this.errorCode = DERInteger.getInstance( seq.getObjectAt(1) );
77         this.errorDetails = PKIFreeText.getInstance( seq.getObjectAt(2) );
78       }
79       else
80       if (seq.size() > 1)
81       {
82           Object JavaDoc obj = seq.getObjectAt(1);
83
84           if( obj instanceof ASN1Sequence )
85             this.errorDetails = PKIFreeText.getInstance(obj);
86           else
87             this.errorCode = DERInteger.getInstance(obj);
88       }
89     }
90
91     public ErrorMsgContent( PKIStatusInfo pKIstatusInfo )
92     {
93       this.pKIStatusInfo = pKIstatusInfo;
94       this.errorCode = null;
95       this.errorDetails = null;
96     }
97
98     public PKIStatusInfo getPKIStatus()
99     {
100       return pKIStatusInfo;
101     }
102
103     public DERInteger getErrorCode()
104     {
105       return errorCode;
106     }
107
108     public void setErrorCode(DERInteger errorCode)
109     {
110       this.errorCode = errorCode;
111     }
112
113     public PKIFreeText getErrorDetails()
114     {
115       return errorDetails;
116     }
117
118     public void setErrorDetails(PKIFreeText errorDetails)
119     {
120       this.errorDetails = errorDetails;
121     }
122
123     public DERObject getDERObject()
124     {
125         ASN1EncodableVector v = new ASN1EncodableVector();
126
127         v.add( pKIStatusInfo );
128
129         if ( errorCode != null )
130             v.add( errorCode );
131
132         if ( errorDetails!= null)
133             v.add( errorDetails );
134
135         return new DERSequence(v);
136     }
137
138     public String JavaDoc toString()
139     {
140       String JavaDoc s = "ErrorMsgContent: (pKIStatus = " + this.getPKIStatus() + ", ";
141       
142       if( this.getErrorCode() != null )
143         s += "errorCode = " + this.getErrorCode() + ", ";
144       
145       if( this.getErrorDetails() != null )
146         s += "errorDetails = " + this.getErrorDetails();
147         
148       s += ")";
149       
150       return s;
151     }
152 }
153
Popular Tags