View Javadoc
1 /* 2 * Title: S/MIME Project 3 * Description: S/MIME email sending capabilities 4 * @author Vladimir Radisic 5 * @Version 2.0.1 6 */ 7 8 9 package org.webdocwf.util.smime.cms; 10 11 12 import org.webdocwf.util.smime.exception.SMIMEException; 13 import org.webdocwf.util.smime.der.DERSequencePr; 14 import org.webdocwf.util.smime.der.DERObjectIdentifier; 15 16 17 /*** 18 * Attribute class is super class for all DER encoded attributes represented in 19 * ASN.1 notation according to RFC2630. Attributes are implemented in CMSSignedObject 20 * which is used in designing signed messages. <BR> 21 * <BR> 22 * <DL> 23 * Attribute ::= SEQUENCE {<BR> 24 * <DD> attrType OBJECT IDENTIFIER,<BR> 25 * <DD> attrValues SET OF AttributeValue }<BR> 26 * </DL> 27 * <BR> 28 * AttributeValue ::= ANY<BR> 29 */ 30 public class Attribute extends DERSequencePr { 31 32 /*** 33 * Indicator for presence detection of attribute's value 34 */ 35 private int valueIndicator = 0; 36 37 /*** 38 * This constructor has two different forms, depend on parameter typeConstruction0, 39 * which can be: DOT_SEPARATED_ARRAY or NAME_STRING. If typeConstruction0 parameter 40 * is DOT_SEPARATED_ARRAY then id0 definition is represented by numbers separated 41 * with dots (example: "1.2.840.113549.1.9.4"). In case of NAME_STRING, id0 42 * definition is name of object identifier for attribute (example: "ID_MESSAGEDIGEST"). 43 * @param id0 defines Object Identifier in representation determined by second 44 * parameter - typeConstruction0. 45 * @param typeOfAttribute0 can take values DOT_SEPARATED_ARRAY and NAME_STRING 46 * @exception SMIMEException if wrong type of parameters are passed to the 47 * constructor. Also, it can be thrown from super class constructor or its 48 * addContent method. 49 */ 50 public Attribute(String id0, String typeOfAttribute0) throws SMIMEException { 51 DERObjectIdentifier temp = new DERObjectIdentifier(id0, typeOfAttribute0); // Finding apropriate identifier 52 53 this.addContent(temp.getDEREncoded()); // Adding identifier to Attribute 54 } 55 56 /*** 57 * Array of numbers is used for construction of desired attribute's DER Object 58 * Identifier. Every number in array represents one number between dots in 59 * object identifier string. 60 * @param arrayID0 array of given numbers (example: for ID_MESSAGEDIGEST 61 * attributes, numbers are 1, 2, 840, 113549, 1, 9 and 4). 62 * @exception SMIMEException if wrong type of parameters are passed to the 63 * constructor. Also, it can be thrown from super class constructor or its 64 * addContent method. 65 */ 66 public Attribute(int[] arrayID0) throws SMIMEException { 67 DERObjectIdentifier temp = new DERObjectIdentifier(arrayID0); // Finding apropriate identifier 68 69 this.addContent(temp.getDEREncoded()); // Adding identifier to Attribute 70 } 71 72 /*** 73 * Adding value to defined DER encoded attribute 74 * @param parameter0 byte array representation of attribute value 75 * @exception SMIMEException thrown from super class addContent method. 76 */ 77 public void addContent(byte[] parameter0) throws SMIMEException { 78 super.addContent(parameter0); 79 valueIndicator++; 80 } 81 82 /*** 83 * Returns DER encoded attribute 84 * @return DER encoded Attribute as byte array 85 * @exception SMIMEException if no value was added to attribute. Also, it can 86 * be thrown from super class getDEREncoded method. 87 */ 88 public byte[] getDEREncoded() throws SMIMEException { 89 if (valueIndicator == 0) 90 throw new SMIMEException(this, 1017); 91 return super.getDEREncoded(); 92 } 93 94 } 95

This page was automatically generated by Maven