1 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 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 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 ("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 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 toString() 139 { 140 String 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 |