001package org.apache.commons.ssl.org.bouncycastle.asn1.cmp; 002 003import java.math.BigInteger; 004 005import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1EncodableVector; 006import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Integer; 007import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Object; 008import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1OctetString; 009import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Primitive; 010import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Sequence; 011import org.apache.commons.ssl.org.bouncycastle.asn1.DEROctetString; 012import org.apache.commons.ssl.org.bouncycastle.asn1.DERSequence; 013 014public class CertStatus 015 extends ASN1Object 016{ 017 private ASN1OctetString certHash; 018 private ASN1Integer certReqId; 019 private PKIStatusInfo statusInfo; 020 021 private CertStatus(ASN1Sequence seq) 022 { 023 certHash = ASN1OctetString.getInstance(seq.getObjectAt(0)); 024 certReqId = ASN1Integer.getInstance(seq.getObjectAt(1)); 025 026 if (seq.size() > 2) 027 { 028 statusInfo = PKIStatusInfo.getInstance(seq.getObjectAt(2)); 029 } 030 } 031 032 public CertStatus(byte[] certHash, BigInteger certReqId) 033 { 034 this.certHash = new DEROctetString(certHash); 035 this.certReqId = new ASN1Integer(certReqId); 036 } 037 038 public CertStatus(byte[] certHash, BigInteger certReqId, PKIStatusInfo statusInfo) 039 { 040 this.certHash = new DEROctetString(certHash); 041 this.certReqId = new ASN1Integer(certReqId); 042 this.statusInfo = statusInfo; 043 } 044 045 public static CertStatus getInstance(Object o) 046 { 047 if (o instanceof CertStatus) 048 { 049 return (CertStatus)o; 050 } 051 052 if (o != null) 053 { 054 return new CertStatus(ASN1Sequence.getInstance(o)); 055 } 056 057 return null; 058 } 059 060 public ASN1OctetString getCertHash() 061 { 062 return certHash; 063 } 064 065 public ASN1Integer getCertReqId() 066 { 067 return certReqId; 068 } 069 070 public PKIStatusInfo getStatusInfo() 071 { 072 return statusInfo; 073 } 074 075 /** 076 * <pre> 077 * CertStatus ::= SEQUENCE { 078 * certHash OCTET STRING, 079 * -- the hash of the certificate, using the same hash algorithm 080 * -- as is used to create and verify the certificate signature 081 * certReqId INTEGER, 082 * -- to match this confirmation with the corresponding req/rep 083 * statusInfo PKIStatusInfo OPTIONAL 084 * } 085 * </pre> 086 * @return a basic ASN.1 object representation. 087 */ 088 public ASN1Primitive toASN1Primitive() 089 { 090 ASN1EncodableVector v = new ASN1EncodableVector(); 091 092 v.add(certHash); 093 v.add(certReqId); 094 095 if (statusInfo != null) 096 { 097 v.add(statusInfo); 098 } 099 100 return new DERSequence(v); 101 } 102}