01: package org.bouncycastle.asn1.cms;
02:
03: import java.util.Enumeration;
04:
05: import org.bouncycastle.asn1.ASN1Encodable;
06: import org.bouncycastle.asn1.ASN1EncodableVector;
07: import org.bouncycastle.asn1.ASN1Sequence;
08: import org.bouncycastle.asn1.ASN1TaggedObject;
09: import org.bouncycastle.asn1.BERSequence;
10: import org.bouncycastle.asn1.BERTaggedObject;
11: import org.bouncycastle.asn1.DEREncodable;
12: import org.bouncycastle.asn1.DERObject;
13: import org.bouncycastle.asn1.DERObjectIdentifier;
14:
15: public class ContentInfo extends ASN1Encodable implements
16: CMSObjectIdentifiers {
17: private DERObjectIdentifier contentType;
18: private DEREncodable content;
19:
20: public static ContentInfo getInstance(Object obj) {
21: if (obj instanceof ContentInfo) {
22: return (ContentInfo) obj;
23: } else if (obj instanceof ASN1Sequence) {
24: return new ContentInfo((ASN1Sequence) obj);
25: }
26:
27: throw new IllegalArgumentException(
28: "unknown object in factory: "
29: + obj.getClass().getName());
30: }
31:
32: public ContentInfo(ASN1Sequence seq) {
33: Enumeration e = seq.getObjects();
34:
35: contentType = (DERObjectIdentifier) e.nextElement();
36:
37: if (e.hasMoreElements()) {
38: content = ((ASN1TaggedObject) e.nextElement()).getObject();
39: }
40: }
41:
42: public ContentInfo(DERObjectIdentifier contentType,
43: DEREncodable content) {
44: this .contentType = contentType;
45: this .content = content;
46: }
47:
48: public DERObjectIdentifier getContentType() {
49: return contentType;
50: }
51:
52: public DEREncodable getContent() {
53: return content;
54: }
55:
56: /**
57: * Produce an object suitable for an ASN1OutputStream.
58: * <pre>
59: * ContentInfo ::= SEQUENCE {
60: * contentType ContentType,
61: * content
62: * [0] EXPLICIT ANY DEFINED BY contentType OPTIONAL }
63: * </pre>
64: */
65: public DERObject toASN1Object() {
66: ASN1EncodableVector v = new ASN1EncodableVector();
67:
68: v.add(contentType);
69:
70: if (content != null) {
71: v.add(new BERTaggedObject(0, content));
72: }
73:
74: return new BERSequence(v);
75: }
76: }
|