001package org.apache.commons.ssl.org.bouncycastle.asn1.cms; 002 003import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1EncodableVector; 004import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Object; 005import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Primitive; 006import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Sequence; 007import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1TaggedObject; 008import org.apache.commons.ssl.org.bouncycastle.asn1.DERSequence; 009import org.apache.commons.ssl.org.bouncycastle.asn1.DERTaggedObject; 010 011/** 012 * <a href="http://tools.ietf.org/html/rfc5940">RFC 5940</a>: 013 * Additional Cryptographic Message Syntax (CMS) Revocation Information Choices. 014 * <p> 015 * <pre> 016 * SCVPReqRes ::= SEQUENCE { 017 * request [0] EXPLICIT ContentInfo OPTIONAL, 018 * response ContentInfo } 019 * </pre> 020 */ 021public class SCVPReqRes 022 extends ASN1Object 023{ 024 private final ContentInfo request; 025 private final ContentInfo response; 026 027 /** 028 * Return a SCVPReqRes object from the given object. 029 * <p> 030 * Accepted inputs: 031 * <ul> 032 * <li> null → null 033 * <li> {@link SCVPReqRes} object 034 * <li> {@link org.bouncycastle.asn1.ASN1Sequence#getInstance(java.lang.Object) ASN1Sequence} input formats with SCVPReqRes structure inside 035 * </ul> 036 * 037 * @param obj the object we want converted. 038 * @exception IllegalArgumentException if the object cannot be converted. 039 */ 040 public static SCVPReqRes getInstance( 041 Object obj) 042 { 043 if (obj instanceof SCVPReqRes) 044 { 045 return (SCVPReqRes)obj; 046 } 047 else if (obj != null) 048 { 049 return new SCVPReqRes(ASN1Sequence.getInstance(obj)); 050 } 051 052 return null; 053 } 054 055 private SCVPReqRes( 056 ASN1Sequence seq) 057 { 058 if (seq.getObjectAt(0) instanceof ASN1TaggedObject) 059 { 060 this.request = ContentInfo.getInstance(ASN1TaggedObject.getInstance(seq.getObjectAt(0)), true); 061 this.response = ContentInfo.getInstance(seq.getObjectAt(1)); 062 } 063 else 064 { 065 this.request = null; 066 this.response = ContentInfo.getInstance(seq.getObjectAt(0)); 067 } 068 } 069 070 public SCVPReqRes(ContentInfo response) 071 { 072 this.request = null; // use of this confuses earlier JDKs 073 this.response = response; 074 } 075 076 public SCVPReqRes(ContentInfo request, ContentInfo response) 077 { 078 this.request = request; 079 this.response = response; 080 } 081 082 public ContentInfo getRequest() 083 { 084 return request; 085 } 086 087 public ContentInfo getResponse() 088 { 089 return response; 090 } 091 092 /** 093 * @return the ASN.1 primitive representation. 094 */ 095 public ASN1Primitive toASN1Primitive() 096 { 097 ASN1EncodableVector v = new ASN1EncodableVector(); 098 099 if (request != null) 100 { 101 v.add(new DERTaggedObject(true, 0, request)); 102 } 103 104 v.add(response); 105 106 return new DERSequence(v); 107 } 108}