01: package org.bouncycastle.asn1.ess;
02:
03: import org.bouncycastle.asn1.ASN1Encodable;
04: import org.bouncycastle.asn1.ASN1EncodableVector;
05: import org.bouncycastle.asn1.ASN1Sequence;
06: import org.bouncycastle.asn1.DEREncodable;
07: import org.bouncycastle.asn1.DERObject;
08: import org.bouncycastle.asn1.DERObjectIdentifier;
09: import org.bouncycastle.asn1.DERSequence;
10: import org.bouncycastle.asn1.DERUTF8String;
11:
12: public class ContentHints extends ASN1Encodable {
13: private DERUTF8String contentDescription;
14: private DERObjectIdentifier contentType;
15:
16: public static ContentHints getInstance(Object o) {
17: if (o == null || o instanceof ContentHints) {
18: return (ContentHints) o;
19: } else if (o instanceof ASN1Sequence) {
20: return new ContentHints((ASN1Sequence) o);
21: }
22:
23: throw new IllegalArgumentException(
24: "unknown object in 'ContentHints' factory : "
25: + o.getClass().getName() + ".");
26: }
27:
28: /**
29: * constructor
30: */
31: private ContentHints(ASN1Sequence seq) {
32: DEREncodable field = seq.getObjectAt(0);
33: if (field.getDERObject() instanceof DERUTF8String) {
34: contentDescription = DERUTF8String.getInstance(field);
35: contentType = DERObjectIdentifier.getInstance(seq
36: .getObjectAt(1));
37: } else {
38: contentType = DERObjectIdentifier.getInstance(seq
39: .getObjectAt(0));
40: }
41: }
42:
43: public ContentHints(DERObjectIdentifier contentType) {
44: this .contentType = contentType;
45: this .contentDescription = null;
46: }
47:
48: public ContentHints(DERObjectIdentifier contentType,
49: DERUTF8String contentDescription) {
50: this .contentType = contentType;
51: this .contentDescription = contentDescription;
52: }
53:
54: public DERObjectIdentifier getContentType() {
55: return contentType;
56: }
57:
58: public DERUTF8String getContentDescription() {
59: return contentDescription;
60: }
61:
62: /**
63: * <pre>
64: * ContentHints ::= SEQUENCE {
65: * contentDescription UTF8String (SIZE (1..MAX)) OPTIONAL,
66: * contentType ContentType }
67: * </pre>
68: */
69: public DERObject toASN1Object() {
70: ASN1EncodableVector v = new ASN1EncodableVector();
71:
72: if (contentDescription != null) {
73: v.add(contentDescription);
74: }
75:
76: v.add(contentType);
77:
78: return new DERSequence(v);
79: }
80: }
|