KickJava   Java API By Example, From Geeks To Geeks.

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


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 import org.enhydra.oyster.der.DERObjectIdentifier;
14
15
16 /**
17  * Attribute class is super class for all DER encoded attributes represented in
18  * ASN.1 notation according to RFC2630. Attributes are implemented in CMSSignedObject
19  * which is used in designing signed messages. <BR>
20  * <BR>
21  * <DL>
22  * Attribute ::= SEQUENCE {<BR>
23  * <DD> attrType OBJECT IDENTIFIER,<BR>
24  * <DD> attrValues SET OF AttributeValue }<BR>
25  * </DL>
26  * <BR>
27  * AttributeValue ::= ANY<BR>
28  */

29 public class Attribute extends DERSequencePr {
30
31 /**
32  * Indicator for presence detection of attribute's value
33  */

34   private int valueIndicator = 0;
35
36 /**
37  * This constructor has two different forms, depend on parameter typeConstruction0,
38  * which can be: DOT_SEPARATED_ARRAY or NAME_STRING. If typeConstruction0 parameter
39  * is DOT_SEPARATED_ARRAY then id0 definition is represented by numbers separated
40  * with dots (example: "1.2.840.113549.1.9.4"). In case of NAME_STRING, id0
41  * definition is name of object identifier for attribute (example: "ID_MESSAGEDIGEST").
42  * @param id0 defines Object Identifier in representation determined by second
43  * parameter - typeConstruction0.
44  * @param typeOfAttribute0 can take values DOT_SEPARATED_ARRAY and NAME_STRING
45  * @exception SMIMEException if wrong type of parameters are passed to the
46  * constructor. Also, it can be thrown from super class constructor or its
47  * addContent method.
48  */

49   public Attribute (String JavaDoc id0, String JavaDoc typeOfAttribute0) throws SMIMEException
50   {
51     DERObjectIdentifier temp = new DERObjectIdentifier(id0, typeOfAttribute0); // Finding apropriate identifier
52
this.addContent(temp.getDEREncoded()); // Adding identifier to Attribute
53
}
54
55 /**
56  * Array of numbers is used for construction of desired attribute's DER Object
57  * Identifier. Every number in array represents one number between dots in
58  * object identifier string.
59  * @param arrayID0 array of given numbers (example: for ID_MESSAGEDIGEST
60  * attributes, numbers are 1, 2, 840, 113549, 1, 9 and 4).
61  * @exception SMIMEException if wrong type of parameters are passed to the
62  * constructor. Also, it can be thrown from super class constructor or its
63  * addContent method.
64  */

65   public Attribute (int[] arrayID0) throws SMIMEException
66   {
67     DERObjectIdentifier temp = new DERObjectIdentifier(arrayID0); // Finding apropriate identifier
68
this.addContent(temp.getDEREncoded()); // Adding identifier to Attribute
69
}
70
71 /**
72  * Adding value to defined DER encoded attribute
73  * @param parameter0 byte array representation of attribute value
74  * @exception SMIMEException thrown from super class addContent method.
75  */

76   public void addContent (byte[] parameter0) throws SMIMEException {
77     super.addContent(parameter0);
78     valueIndicator++;
79   }
80
81 /**
82  * Returns DER encoded attribute
83  * @return DER encoded Attribute as byte array
84  * @exception SMIMEException if no value was added to attribute. Also, it can
85  * be thrown from super class getDEREncoded method.
86  */

87   public byte[] getDEREncoded () throws SMIMEException {
88     if (valueIndicator == 0)
89       throw new SMIMEException(this, 1017);
90     return super.getDEREncoded();
91   }
92
93 }
94
95
96
97
Popular Tags