01: /*
02: * Title: Oyster Project
03: * Description: S/MIME email sending capabilities
04: * @Author Vladimir Radisic
05: * @Version 2.1.6
06: */
07:
08: package org.enhydra.oyster.cms;
09:
10: import org.enhydra.oyster.exception.SMIMEException;
11: import org.enhydra.oyster.der.DERClassContextSpecific;
12: import org.enhydra.oyster.der.DERSequencePr;
13: import org.enhydra.oyster.der.DEROctetString;
14:
15: /**
16: * EncapsulatedContentInfo class is DER encoded content info represented in
17: * ASN.1 notation according to RFC2630. This class is used in CMS objects for
18: * signed messages. It contains message content in case of implicit signing.<BR>
19: * <BR>
20: * <DL>
21: * EncapsulatedContentInfo ::= SEQUENCE {<BR>
22: * <DD> eContentType ContentType, <BR>
23: * <DD> eContent [0] EXPLICIT OCTET STRING OPTIONAL }<BR>
24: * </DL>
25: * <BR>
26: * ContentType ::= OBJECT IDENTIFIER<BR>
27: */
28: public class EncapsulatedContentInfo extends DERSequencePr {
29:
30: /**
31: * Determinate order of adding commponents.
32: */
33: int orderIdentifier = 0;
34:
35: /**
36: * Constructs empty EncapsulatedContentInfo object.
37: * @exception SMIMEException thrown from super class constructor.
38: */
39: public EncapsulatedContentInfo() throws SMIMEException {
40: }
41:
42: /**
43: * Adds Content Type
44: * @param contType0 content type represented as byte array
45: * @exception SMIMEException if order of adding components is wrong. Also, it
46: * can be thrown from super class addContent method.
47: */
48: public void addContentType(byte[] contType0) throws SMIMEException {
49: if (orderIdentifier == 0) {
50: super .addContent(contType0);
51: orderIdentifier++;
52: } else
53: throw new SMIMEException(1018);
54: }
55:
56: /**
57: * Adds Encapsulated Content
58: * @param cont0 content represented as byte array
59: * @exception SMIMEException if order of adding components is wrong. Also, it
60: * can be thrown from super class addContent method.
61: */
62: public void addEncapsulatedContent(byte[] cont0)
63: throws SMIMEException {
64: if (orderIdentifier == 1) {
65: DERClassContextSpecific eContent = new DERClassContextSpecific(
66: 0, true);
67: eContent.addContent(new DEROctetString(cont0)
68: .getDEREncoded());
69: super .addContent(eContent.getDEREncoded());
70: orderIdentifier++;
71: } else
72: throw new SMIMEException(1018);
73: }
74: }
|