KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > oyster > cms > SignedData


1 /*
2  * Title: Oyster Project
3  * Description: S/MIME email sending capabilities
4  * @Author Vladimir Radisic
5  * @Version 2.1.5
6  */

7
8
9 package org.enhydra.oyster.cms;
10
11 import org.enhydra.oyster.exception.SMIMEException;
12 import org.enhydra.oyster.der.DERSequencePr;
13
14
15 /**
16  * SignedData is DER encoded container for information represented in
17  * ASN.1 notation according to RFC2630, used for construction CMS objects
18  * of signed messages.<BR>
19  * <BR>
20  * <DL>
21  * SignedData ::= SEQUENCE {<BR>
22  * <DD> version CMSVersion,<BR>
23  * <DD> digestAlgorithms DigestAlgorithmIdentifiers,<BR>
24  * <DD> encapContentInfo EncapsulatedContentInfo,<BR>
25  * <DD> certificates [0] IMPLICIT CertificateSet OPTIONAL,<BR>
26  * <DD> crls [1] IMPLICIT CertificateRevocationLists OPTIONAL,<BR>
27  * <DD> signerInfos SignerInfos }<BR>
28  * </DL>
29  */

30 public class SignedData extends DERSequencePr {
31
32 /**
33  * Determinate order of adding commponents
34  */

35   int orderIdentifier = 0;
36
37 /**
38  * Constructs an empty Signed Data
39  * @exception SMIMEException thrown in super class constructor.
40  */

41   public SignedData () throws SMIMEException
42   {
43   }
44
45 /**
46  * Adds DER encoded CMS Version
47  * @param ver0 DER encoded CMS version represented as byte array
48  * @exception SMIMEException if order of adding components is wrong. Also,
49  * exception could be thrown in super class addContent method.
50  */

51   public void addCMSVersion (byte[] ver0) throws SMIMEException {
52     if (orderIdentifier == 0) {
53       super.addContent(ver0);
54       orderIdentifier++;
55     }
56     else
57       throw new SMIMEException(this, 1018);
58   }
59
60 /**
61  * Adds DER encoded Digest Algorithm Identifier
62  * @param digAlg0 DER encoded Digest Algorithm Identifier as byte array
63  * @exception SMIMEException if order of adding components is wrong. Also,
64  * exception could be thrown in super class addContent method.
65  */

66   public void addDigestAlgorithm (byte[] digAlg0) throws SMIMEException {
67     if (orderIdentifier == 1) {
68       super.addContent(digAlg0);
69       orderIdentifier++;
70     }
71     else
72       throw new SMIMEException(this, 1018);
73   }
74
75 /**
76  * Adds DER encoded Encapsulated Content Info
77  * @param encCont0 DER encoded Encapsulated Content Info as byte array
78  * @exception SMIMEException if order of adding components is wrong. Also,
79  * exception could be thrown in super class addContent method.
80  */

81   public void addEncapsulatedContentInfo (byte[] encCont0) throws SMIMEException {
82     if (orderIdentifier == 2) {
83       super.addContent(encCont0);
84       orderIdentifier++;
85     }
86     else
87       throw new SMIMEException(this, 1018);
88   }
89
90 /**
91  * Adds DER encoded Certificate container with one or more X509 certificates
92  * @param cert0 DER encoded Certificate container
93  * @exception SMIMEException if order of adding components is wrong. Also,
94  * exception could be thrown in super class addContent method.
95  */

96   public void addCertificate (byte[] cert0) throws SMIMEException {
97     if (orderIdentifier == 3) {
98       super.addContent(cert0);
99       orderIdentifier++;
100     }
101     else
102       throw new SMIMEException(this, 1018);
103   }
104
105 /**
106  * Adds DER encoded Signer Infos
107  * @param info0 DER encoded Signer Infos
108  * @exception SMIMEException if order of adding components is wrong. Also,
109  * exception could be thrown in super class addContent method.
110  */

111   public void addSignerInfos (byte[] info0) throws SMIMEException {
112     if (orderIdentifier == 3) {
113       super.addContent(info0);
114       orderIdentifier++;
115       orderIdentifier++;
116     }
117     else if (orderIdentifier == 4) {
118       super.addContent(info0);
119       orderIdentifier++;
120     }
121     else
122       throw new SMIMEException(this, 1018);
123   }
124 }
125
126
127
128
Popular Tags