001: /*
002: * Title: Oyster Project
003: * Description: S/MIME email sending capabilities
004: * @Author Vladimir Radisic
005: * @Version 2.1.6
006: */
007:
008: package org.enhydra.oyster.cms;
009:
010: import org.enhydra.oyster.exception.SMIMEException;
011: import org.enhydra.oyster.der.DERSequencePr;
012:
013: /**
014: * SignedData is DER encoded container for information represented in
015: * ASN.1 notation according to RFC2630, used for construction CMS objects
016: * of signed messages.<BR>
017: * <BR>
018: * <DL>
019: * SignedData ::= SEQUENCE {<BR>
020: * <DD> version CMSVersion,<BR>
021: * <DD> digestAlgorithms DigestAlgorithmIdentifiers,<BR>
022: * <DD> encapContentInfo EncapsulatedContentInfo,<BR>
023: * <DD> certificates [0] IMPLICIT CertificateSet OPTIONAL,<BR>
024: * <DD> crls [1] IMPLICIT CertificateRevocationLists OPTIONAL,<BR>
025: * <DD> signerInfos SignerInfos }<BR>
026: * </DL>
027: */
028: public class SignedData extends DERSequencePr {
029:
030: /**
031: * Determinate order of adding commponents
032: */
033: int orderIdentifier = 0;
034:
035: /**
036: * Constructs an empty Signed Data
037: * @exception SMIMEException thrown in super class constructor.
038: */
039: public SignedData() throws SMIMEException {
040: }
041:
042: /**
043: * Adds DER encoded CMS Version
044: * @param ver0 DER encoded CMS version represented as byte array
045: * @exception SMIMEException if order of adding components is wrong. Also,
046: * exception could be thrown in super class addContent method.
047: */
048: public void addCMSVersion(byte[] ver0) throws SMIMEException {
049: if (orderIdentifier == 0) {
050: super .addContent(ver0);
051: orderIdentifier++;
052: } else
053: throw new SMIMEException(1018);
054: }
055:
056: /**
057: * Adds DER encoded Digest Algorithm Identifier
058: * @param digAlg0 DER encoded Digest Algorithm Identifier as byte array
059: * @exception SMIMEException if order of adding components is wrong. Also,
060: * exception could be thrown in super class addContent method.
061: */
062: public void addDigestAlgorithm(byte[] digAlg0)
063: throws SMIMEException {
064: if (orderIdentifier == 1) {
065: super .addContent(digAlg0);
066: orderIdentifier++;
067: } else
068: throw new SMIMEException(1018);
069: }
070:
071: /**
072: * Adds DER encoded Encapsulated Content Info
073: * @param encCont0 DER encoded Encapsulated Content Info as byte array
074: * @exception SMIMEException if order of adding components is wrong. Also,
075: * exception could be thrown in super class addContent method.
076: */
077: public void addEncapsulatedContentInfo(byte[] encCont0)
078: throws SMIMEException {
079: if (orderIdentifier == 2) {
080: super .addContent(encCont0);
081: orderIdentifier++;
082: } else
083: throw new SMIMEException(1018);
084: }
085:
086: /**
087: * Adds DER encoded Certificate container with one or more X509 certificates
088: * @param cert0 DER encoded Certificate container
089: * @exception SMIMEException if order of adding components is wrong. Also,
090: * exception could be thrown in super class addContent method.
091: */
092: public void addCertificate(byte[] cert0) throws SMIMEException {
093: if (orderIdentifier == 3) {
094: super .addContent(cert0);
095: orderIdentifier++;
096: } else
097: throw new SMIMEException(1018);
098: }
099:
100: /**
101: * Adds DER encoded Signer Infos
102: * @param info0 DER encoded Signer Infos
103: * @exception SMIMEException if order of adding components is wrong. Also,
104: * exception could be thrown in super class addContent method.
105: */
106: public void addSignerInfos(byte[] info0) throws SMIMEException {
107: if (orderIdentifier == 3) {
108: super .addContent(info0);
109: orderIdentifier++;
110: orderIdentifier++;
111: } else if (orderIdentifier == 4) {
112: super .addContent(info0);
113: orderIdentifier++;
114: } else
115: throw new SMIMEException(1018);
116: }
117: }
|