1package org.bouncycastle.asn1.cms; 2 3import org.bouncycastle.asn1.ASN1Encodable; 4import org.bouncycastle.asn1.ASN1EncodableVector; 5import org.bouncycastle.asn1.ASN1Object; 6import org.bouncycastle.asn1.ASN1ObjectIdentifier; 7import org.bouncycastle.asn1.ASN1Primitive; 8import org.bouncycastle.asn1.ASN1Sequence; 9import org.bouncycastle.asn1.ASN1TaggedObject; 10import org.bouncycastle.asn1.BERSequence; 11import org.bouncycastle.asn1.BERTaggedObject; 12 13public class ContentInfo 14 extends ASN1Object 15 // BEGIN android-removed 16 // implements CMSObjectIdentifiers 17 // END android-removed 18{ 19 private ASN1ObjectIdentifier contentType; 20 private ASN1Encodable content; 21 22 public static ContentInfo getInstance( 23 Object obj) 24 { 25 if (obj instanceof ContentInfo) 26 { 27 return (ContentInfo)obj; 28 } 29 else if (obj != null) 30 { 31 return new ContentInfo(ASN1Sequence.getInstance(obj)); 32 } 33 34 return null; 35 } 36 37 public static ContentInfo getInstance( 38 ASN1TaggedObject obj, 39 boolean explicit) 40 { 41 return getInstance(ASN1Sequence.getInstance(obj, explicit)); 42 } 43 44 /** 45 * @deprecated use getInstance() 46 */ 47 public ContentInfo( 48 ASN1Sequence seq) 49 { 50 if (seq.size() < 1 || seq.size() > 2) 51 { 52 throw new IllegalArgumentException("Bad sequence size: " + seq.size()); 53 } 54 55 contentType = (ASN1ObjectIdentifier)seq.getObjectAt(0); 56 57 if (seq.size() > 1) 58 { 59 ASN1TaggedObject tagged = (ASN1TaggedObject)seq.getObjectAt(1); 60 if (!tagged.isExplicit() || tagged.getTagNo() != 0) 61 { 62 throw new IllegalArgumentException("Bad tag for 'content'"); 63 } 64 65 content = tagged.getObject(); 66 } 67 } 68 69 public ContentInfo( 70 ASN1ObjectIdentifier contentType, 71 ASN1Encodable content) 72 { 73 this.contentType = contentType; 74 this.content = content; 75 } 76 77 public ASN1ObjectIdentifier getContentType() 78 { 79 return contentType; 80 } 81 82 public ASN1Encodable getContent() 83 { 84 return content; 85 } 86 87 /** 88 * Produce an object suitable for an ASN1OutputStream. 89 * <pre> 90 * ContentInfo ::= SEQUENCE { 91 * contentType ContentType, 92 * content 93 * [0] EXPLICIT ANY DEFINED BY contentType OPTIONAL } 94 * </pre> 95 */ 96 public ASN1Primitive toASN1Primitive() 97 { 98 ASN1EncodableVector v = new ASN1EncodableVector(); 99 100 v.add(contentType); 101 102 if (content != null) 103 { 104 v.add(new BERTaggedObject(0, content)); 105 } 106 107 return new BERSequence(v); 108 } 109} 110