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.ASN1OctetString;
024: import org.bouncycastle.asn1.ASN1Sequence;
025: import org.bouncycastle.asn1.ASN1TaggedObject;
026: import org.bouncycastle.asn1.DEREncodable;
027: import org.bouncycastle.asn1.DERInteger;
028: import org.bouncycastle.asn1.DERObject;
029: import org.bouncycastle.asn1.DERSequence;
030:
031: /**
032: * ASN.1 structure DER En/DeCoder.
033: *
034: * <pre>
035: * CertConfirmContent ::= SEQUENCE OF CertStatus
036: *
037: * CertStatus ::= SEQUENCE {
038: * certHash OCTET STRING,
039: * certReqId INTEGER,
040: * statusInfo PKIStatusInfo OPTIONAL
041: * }
042: *
043: * </pre>
044: */
045: public class CertConfirmContent implements DEREncodable {
046: ASN1OctetString certHash;
047: DERInteger certReqId;
048: PKIStatusInfo statusInfo;
049:
050: public static CertConfirmContent getInstance(ASN1TaggedObject obj,
051: boolean explicit) {
052: return getInstance(ASN1Sequence.getInstance(obj, explicit));
053: }
054:
055: public static CertConfirmContent getInstance(Object obj) {
056: if (obj instanceof CertConfirmContent) {
057: return (CertConfirmContent) obj;
058: } else if (obj instanceof ASN1Sequence) {
059: return new CertConfirmContent((ASN1Sequence) obj);
060: }
061:
062: throw new IllegalArgumentException("unknown object in factory");
063: }
064:
065: public CertConfirmContent(ASN1Sequence seq) {
066: ASN1Sequence s = ASN1Sequence.getInstance(seq.getObjectAt(0));
067:
068: this .certHash = ASN1OctetString.getInstance(s.getObjectAt(0));
069: this .certReqId = DERInteger.getInstance(s.getObjectAt(1));
070: this .statusInfo = null;
071:
072: if (s.size() > 2) {
073: this .statusInfo = PKIStatusInfo.getInstance(s
074: .getObjectAt(2));
075: }
076: }
077:
078: public CertConfirmContent(ASN1OctetString certHash,
079: DERInteger certReqId) {
080: this .certHash = certHash;
081: this .certReqId = certReqId;
082: this .statusInfo = null;
083: }
084:
085: public DERInteger getCertReqId() {
086: return certReqId;
087: }
088:
089: public ASN1OctetString getCertHash() {
090: return certHash;
091: }
092:
093: public PKIStatusInfo getPKIStatus() {
094: return statusInfo;
095: }
096:
097: public void setPKIStatus(PKIStatusInfo status) {
098: this .statusInfo = status;
099: }
100:
101: public DERObject getDERObject() {
102: ASN1EncodableVector outer = new ASN1EncodableVector();
103: ASN1EncodableVector v = new ASN1EncodableVector();
104:
105: v.add(certHash);
106: v.add(certReqId);
107:
108: if (statusInfo != null)
109: v.add(statusInfo);
110:
111: outer.add(new DERSequence(v));
112:
113: return new DERSequence(outer);
114: }
115:
116: public String toString() {
117: String s = "CertConfirmContent: (certHash = "
118: + this .getCertHash() + ", certReqId = "
119: + this .getCertReqId();
120:
121: if (this .getPKIStatus() != null)
122: s += "pkiStatus = " + this .getPKIStatus();
123:
124: s += ")";
125:
126: return s;
127: }
128: }
|