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 java.util.Enumeration;
023:
024: import org.bouncycastle.asn1.ASN1EncodableVector;
025: import org.bouncycastle.asn1.ASN1Sequence;
026: import org.bouncycastle.asn1.ASN1TaggedObject;
027: import org.bouncycastle.asn1.DEREncodable;
028: import org.bouncycastle.asn1.DERInteger;
029: import org.bouncycastle.asn1.DERObject;
030: import org.bouncycastle.asn1.DEROctetString;
031: import org.bouncycastle.asn1.DERSequence;
032:
033: /**
034: * ASN.1 structure DER En/DeCoder.
035: *
036: * <pre>
037: * CertResponse ::= SEQUENCE {
038: * certReqId INTEGER, -- to match this response with corresponding request (a value of -1 is to be used if certReqId is not specified in the corresponding request)
039: * status PKIStatusInfo,
040: * certifiedKeyPair CertifiedKeyPair OPTIONAL,
041: * rspInfo OCTET STRING OPTIONAL -- analogous to the id-regInfo-asciiPairs OCTET STRING defined for regInfo in CertReqMsg [CRMF]
042: * }
043: *
044: * </pre>
045: */
046: public class CertResponse implements DEREncodable {
047: DERInteger certReqId;
048: PKIStatusInfo status;
049: CertifiedKeyPair certifiedKeyPair;
050: DEROctetString rspInfo;
051:
052: public static CertResponse getInstance(ASN1TaggedObject obj,
053: boolean explicit) {
054: return getInstance(ASN1Sequence.getInstance(obj, explicit));
055: }
056:
057: public static CertResponse getInstance(Object obj) {
058: if (obj instanceof CertResponse) {
059: return (CertResponse) obj;
060: } else if (obj instanceof ASN1Sequence) {
061: return new CertResponse((ASN1Sequence) obj);
062: }
063:
064: throw new IllegalArgumentException("unknown object in factory");
065: }
066:
067: public CertResponse(ASN1Sequence seq) {
068: Enumeration e = seq.getObjects();
069:
070: certReqId = DERInteger.getInstance(e.nextElement());
071: status = PKIStatusInfo.getInstance(e.nextElement());
072:
073: Object obj = null;
074:
075: if (e.hasMoreElements())
076: obj = e.nextElement();
077:
078: if (obj instanceof ASN1Sequence) {
079: certifiedKeyPair = CertifiedKeyPair.getInstance(obj);
080:
081: if (e.hasMoreElements())
082: obj = e.nextElement();
083: }
084:
085: if (obj instanceof DEROctetString)
086: rspInfo = (DEROctetString) obj;
087: }
088:
089: public CertResponse(DERInteger certReqId, PKIStatusInfo status) {
090: this .certReqId = certReqId;
091: this .status = status;
092: }
093:
094: public DERInteger getCertReqId() {
095: return certReqId;
096: }
097:
098: public PKIStatusInfo getStatus() {
099: return status;
100: }
101:
102: public void setCertifiedKeyPair(CertifiedKeyPair certifiedKeyPair) {
103: this .certifiedKeyPair = certifiedKeyPair;
104: }
105:
106: public CertifiedKeyPair getCertifiedKeyPair() {
107: return certifiedKeyPair;
108: }
109:
110: public void setRspInfo(DEROctetString rspInfo) {
111: this .rspInfo = rspInfo;
112: }
113:
114: public DEROctetString getRspInfo() {
115: return rspInfo;
116: }
117:
118: public DERObject getDERObject() {
119: ASN1EncodableVector v = new ASN1EncodableVector();
120:
121: v.add(certReqId);
122: v.add(status);
123:
124: if (certifiedKeyPair != null)
125: v.add(certifiedKeyPair);
126:
127: if (rspInfo != null)
128: v.add(rspInfo);
129:
130: return new DERSequence(v);
131: }
132:
133: public String toString() {
134: String s = "CertResponse: ( certReqId: " + this .getCertReqId()
135: + ", status: " + this .getStatus() + ", ";
136:
137: if (this .getCertifiedKeyPair() != null)
138: s += "certifiedKeyPair: " + this .getCertifiedKeyPair()
139: + ", ";
140:
141: if (this .getRspInfo() != null)
142: s += "rspInfo: " + this .getRspInfo() + ", ";
143:
144: s += ")";
145:
146: return s;
147: }
148: }
|