1b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallampackage org.bouncycastle.asn1.pkcs; 2b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 3b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallamimport java.util.Enumeration; 4b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 5b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallamimport org.bouncycastle.asn1.ASN1Encodable; 6b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallamimport org.bouncycastle.asn1.ASN1EncodableVector; 74c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstromimport org.bouncycastle.asn1.ASN1Object; 84c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstromimport org.bouncycastle.asn1.ASN1ObjectIdentifier; 94c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstromimport org.bouncycastle.asn1.ASN1Primitive; 10b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallamimport org.bouncycastle.asn1.ASN1Sequence; 114c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstromimport org.bouncycastle.asn1.ASN1TaggedObject; 12b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallamimport org.bouncycastle.asn1.BERSequence; 13b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallamimport org.bouncycastle.asn1.BERTaggedObject; 144c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstromimport org.bouncycastle.asn1.DLSequence; 15b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 16b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallampublic class ContentInfo 174c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom extends ASN1Object 18b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam implements PKCSObjectIdentifiers 19b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam{ 204c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom private ASN1ObjectIdentifier contentType; 214c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom private ASN1Encodable content; 224c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom private boolean isBer = true; 23b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 24b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public static ContentInfo getInstance( 25b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam Object obj) 26b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 27b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam if (obj instanceof ContentInfo) 28b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 29b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam return (ContentInfo)obj; 30b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 314c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom 324c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom if (obj != null) 33b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 344c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom return new ContentInfo(ASN1Sequence.getInstance(obj)); 35b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 36b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 374c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom return null; 38b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 39b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 404c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom private ContentInfo( 41b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam ASN1Sequence seq) 42b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 43b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam Enumeration e = seq.getObjects(); 44b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 454c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom contentType = (ASN1ObjectIdentifier)e.nextElement(); 46b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 47b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam if (e.hasMoreElements()) 48b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 494c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom content = ((ASN1TaggedObject)e.nextElement()).getObject(); 50b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 514c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom 524c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom isBer = seq instanceof BERSequence; 53b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 54b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 55b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public ContentInfo( 564c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom ASN1ObjectIdentifier contentType, 574c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom ASN1Encodable content) 58b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 59b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam this.contentType = contentType; 60b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam this.content = content; 61b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 62b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 634c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom public ASN1ObjectIdentifier getContentType() 64b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 65b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam return contentType; 66b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 67b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 684c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom public ASN1Encodable getContent() 69b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 70b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam return content; 71b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 72b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 73b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 74b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * Produce an object suitable for an ASN1OutputStream. 75b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * <pre> 76b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * ContentInfo ::= SEQUENCE { 77b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * contentType ContentType, 78b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * content 79b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * [0] EXPLICIT ANY DEFINED BY contentType OPTIONAL } 80b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * </pre> 81b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 824c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom public ASN1Primitive toASN1Primitive() 83b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 844c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom ASN1EncodableVector v = new ASN1EncodableVector(); 85b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 86b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam v.add(contentType); 87b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 88b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam if (content != null) 89b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 904c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom v.add(new BERTaggedObject(true, 0, content)); 91b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 92b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 934c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom if (isBer) 944c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom { 954c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom return new BERSequence(v); 964c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom } 974c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom else 984c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom { 994c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom return new DLSequence(v); 1004c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom } 101b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 102b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam} 103