001package org.apache.commons.ssl.org.bouncycastle.asn1.cms; 002 003import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Encodable; 004import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1EncodableVector; 005import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Object; 006import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1ObjectIdentifier; 007import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Primitive; 008import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Sequence; 009import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1TaggedObject; 010import org.apache.commons.ssl.org.bouncycastle.asn1.DERSequence; 011 012/** 013 * <a href="http://tools.ietf.org/html/rfc5652#section-6.2.5">RFC 5652</a>: 014 * Content encryption key delivery mechanisms. 015 * <pre> 016 * OtherRecipientInfo ::= SEQUENCE { 017 * oriType OBJECT IDENTIFIER, 018 * oriValue ANY DEFINED BY oriType } 019 * </pre> 020 */ 021public class OtherRecipientInfo 022 extends ASN1Object 023{ 024 private ASN1ObjectIdentifier oriType; 025 private ASN1Encodable oriValue; 026 027 public OtherRecipientInfo( 028 ASN1ObjectIdentifier oriType, 029 ASN1Encodable oriValue) 030 { 031 this.oriType = oriType; 032 this.oriValue = oriValue; 033 } 034 035 /** 036 * @deprecated use getInstance(). 037 */ 038 public OtherRecipientInfo( 039 ASN1Sequence seq) 040 { 041 oriType = ASN1ObjectIdentifier.getInstance(seq.getObjectAt(0)); 042 oriValue = seq.getObjectAt(1); 043 } 044 045 /** 046 * Return a OtherRecipientInfo object from a tagged object. 047 * 048 * @param obj the tagged object holding the object we want. 049 * @param explicit true if the object is meant to be explicitly 050 * tagged false otherwise. 051 * @exception IllegalArgumentException if the object held by the 052 * tagged object cannot be converted. 053 */ 054 public static OtherRecipientInfo getInstance( 055 ASN1TaggedObject obj, 056 boolean explicit) 057 { 058 return getInstance(ASN1Sequence.getInstance(obj, explicit)); 059 } 060 061 /** 062 * Return a OtherRecipientInfo object from the given object. 063 * <p> 064 * Accepted inputs: 065 * <ul> 066 * <li> null → null 067 * <li> {@link PasswordRecipientInfo} object 068 * <li> {@link org.bouncycastle.asn1.ASN1Sequence#getInstance(java.lang.Object) ASN1Sequence} input formats with OtherRecipientInfo structure inside 069 * </ul> 070 * 071 * @param obj the object we want converted. 072 * @exception IllegalArgumentException if the object cannot be converted. 073 */ 074 public static OtherRecipientInfo getInstance( 075 Object obj) 076 { 077 if (obj instanceof OtherRecipientInfo) 078 { 079 return (OtherRecipientInfo)obj; 080 } 081 082 if (obj != null) 083 { 084 return new OtherRecipientInfo(ASN1Sequence.getInstance(obj)); 085 } 086 087 return null; 088 } 089 090 public ASN1ObjectIdentifier getType() 091 { 092 return oriType; 093 } 094 095 public ASN1Encodable getValue() 096 { 097 return oriValue; 098 } 099 100 /** 101 * Produce an object suitable for an ASN1OutputStream. 102 */ 103 public ASN1Primitive toASN1Primitive() 104 { 105 ASN1EncodableVector v = new ASN1EncodableVector(); 106 107 v.add(oriType); 108 v.add(oriValue); 109 110 return new DERSequence(v); 111 } 112}