001: // CMP implementation copyright (c) 2003 NOVOSEC AG (http://www.novosec.com)
002: //
003: // Author: Maik Stohn
004: //
005: // Permission is hereby granted, free of charge, to any person obtaining a copy of this
006: // software and associated documentation files (the "Software"), to deal in the Software
007: // without restriction, including without limitation the rights to use, copy, modify, merge,
008: // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
009: // to whom the Software is furnished to do so, subject to the following conditions:
010: //
011: // The above copyright notice and this permission notice shall be included in all copies or
012: // substantial portions of the Software.
013: //
014: // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
015: // BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
016: // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
017: // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
018: // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
019:
020: package com.novosec.pkix.asn1.cmp;
021:
022: import org.bouncycastle.asn1.ASN1EncodableVector;
023: import org.bouncycastle.asn1.ASN1Sequence;
024: import org.bouncycastle.asn1.ASN1TaggedObject;
025: import org.bouncycastle.asn1.DEREncodable;
026: import org.bouncycastle.asn1.DERInteger;
027: import org.bouncycastle.asn1.DERObject;
028: import org.bouncycastle.asn1.DERSequence;
029:
030: /**
031: * ASN.1 structure DER En/DeCoder.
032: *
033: * <pre>
034: * ErrorMsgContent ::= SEQUENCE {
035: * pKIStatusInfo PKIStatusInfo,
036: * errorCode INTEGER OPTIONAL, -- implementation-specific error codes
037: * errorDetails PKIFreeText OPTIONAL -- implementation-specific error details
038: * }
039: *
040: * </pre>
041: */
042: public class ErrorMsgContent implements DEREncodable {
043: PKIStatusInfo pKIStatusInfo;
044: DERInteger errorCode;
045: PKIFreeText errorDetails;
046:
047: public static ErrorMsgContent getInstance(ASN1TaggedObject obj,
048: boolean explicit) {
049: return getInstance(ASN1Sequence.getInstance(obj, explicit));
050: }
051:
052: public static ErrorMsgContent getInstance(Object obj) {
053: if (obj instanceof ErrorMsgContent) {
054: return (ErrorMsgContent) obj;
055: } else if (obj instanceof ASN1Sequence) {
056: return new ErrorMsgContent((ASN1Sequence) obj);
057: }
058:
059: throw new IllegalArgumentException("unknown object in factory");
060: }
061:
062: public ErrorMsgContent(ASN1Sequence seq) {
063: this .pKIStatusInfo = PKIStatusInfo.getInstance(seq
064: .getObjectAt(0));
065:
066: this .errorCode = null;
067: this .errorDetails = null;
068:
069: if (seq.size() > 2) {
070: this .errorCode = DERInteger.getInstance(seq.getObjectAt(1));
071: this .errorDetails = PKIFreeText.getInstance(seq
072: .getObjectAt(2));
073: } else if (seq.size() > 1) {
074: Object obj = seq.getObjectAt(1);
075:
076: if (obj instanceof ASN1Sequence)
077: this .errorDetails = PKIFreeText.getInstance(obj);
078: else
079: this .errorCode = DERInteger.getInstance(obj);
080: }
081: }
082:
083: public ErrorMsgContent(PKIStatusInfo pKIstatusInfo) {
084: this .pKIStatusInfo = pKIstatusInfo;
085: this .errorCode = null;
086: this .errorDetails = null;
087: }
088:
089: public PKIStatusInfo getPKIStatus() {
090: return pKIStatusInfo;
091: }
092:
093: public DERInteger getErrorCode() {
094: return errorCode;
095: }
096:
097: public void setErrorCode(DERInteger errorCode) {
098: this .errorCode = errorCode;
099: }
100:
101: public PKIFreeText getErrorDetails() {
102: return errorDetails;
103: }
104:
105: public void setErrorDetails(PKIFreeText errorDetails) {
106: this .errorDetails = errorDetails;
107: }
108:
109: public DERObject getDERObject() {
110: ASN1EncodableVector v = new ASN1EncodableVector();
111:
112: v.add(pKIStatusInfo);
113:
114: if (errorCode != null)
115: v.add(errorCode);
116:
117: if (errorDetails != null)
118: v.add(errorDetails);
119:
120: return new DERSequence(v);
121: }
122:
123: public String toString() {
124: String s = "ErrorMsgContent: (pKIStatus = "
125: + this .getPKIStatus() + ", ";
126:
127: if (this .getErrorCode() != null)
128: s += "errorCode = " + this .getErrorCode() + ", ";
129:
130: if (this .getErrorDetails() != null)
131: s += "errorDetails = " + this .getErrorDetails();
132:
133: s += ")";
134:
135: return s;
136: }
137: }
|