001: package org.bouncycastle.asn1.smime;
002:
003: import java.util.Enumeration;
004: import java.util.Vector;
005:
006: import org.bouncycastle.asn1.ASN1Encodable;
007: import org.bouncycastle.asn1.ASN1Sequence;
008: import org.bouncycastle.asn1.DERObject;
009: import org.bouncycastle.asn1.DERObjectIdentifier;
010: import org.bouncycastle.asn1.cms.Attribute;
011: import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
012:
013: /**
014: * Handler class for dealing with S/MIME Capabilities
015: */
016: public class SMIMECapabilities extends ASN1Encodable {
017: /**
018: * general preferences
019: */
020: public static final DERObjectIdentifier preferSignedData = PKCSObjectIdentifiers.preferSignedData;
021: public static final DERObjectIdentifier canNotDecryptAny = PKCSObjectIdentifiers.canNotDecryptAny;
022: public static final DERObjectIdentifier sMIMECapabilitesVersions = PKCSObjectIdentifiers.sMIMECapabilitiesVersions;
023:
024: /**
025: * encryption algorithms preferences
026: */
027: public static final DERObjectIdentifier dES_CBC = new DERObjectIdentifier(
028: "1.3.14.3.2.7");
029: public static final DERObjectIdentifier dES_EDE3_CBC = PKCSObjectIdentifiers.des_EDE3_CBC;
030: public static final DERObjectIdentifier rC2_CBC = PKCSObjectIdentifiers.RC2_CBC;
031:
032: private ASN1Sequence capabilities;
033:
034: /**
035: * return an Attribute object from the given object.
036: *
037: * @param o the object we want converted.
038: * @exception IllegalArgumentException if the object cannot be converted.
039: */
040: public static SMIMECapabilities getInstance(Object o) {
041: if (o == null || o instanceof SMIMECapabilities) {
042: return (SMIMECapabilities) o;
043: }
044:
045: if (o instanceof ASN1Sequence) {
046: return new SMIMECapabilities((ASN1Sequence) o);
047: }
048:
049: if (o instanceof Attribute) {
050: return new SMIMECapabilities(
051: (ASN1Sequence) (((Attribute) o).getAttrValues()
052: .getObjectAt(0)));
053: }
054:
055: throw new IllegalArgumentException("unknown object in factory");
056: }
057:
058: public SMIMECapabilities(ASN1Sequence seq) {
059: capabilities = seq;
060: }
061:
062: /**
063: * returns a vector with 0 or more objects of all the capabilities
064: * matching the passed in capability OID. If the OID passed is null the
065: * entire set is returned.
066: */
067: public Vector getCapabilities(DERObjectIdentifier capability) {
068: Enumeration e = capabilities.getObjects();
069: Vector list = new Vector();
070:
071: if (capability == null) {
072: while (e.hasMoreElements()) {
073: SMIMECapability cap = SMIMECapability.getInstance(e
074: .nextElement());
075:
076: list.addElement(cap);
077: }
078: } else {
079: while (e.hasMoreElements()) {
080: SMIMECapability cap = SMIMECapability.getInstance(e
081: .nextElement());
082:
083: if (capability.equals(cap.getCapabilityID())) {
084: list.addElement(cap);
085: }
086: }
087: }
088:
089: return list;
090: }
091:
092: /**
093: * Produce an object suitable for an ASN1OutputStream.
094: * <pre>
095: * SMIMECapabilities ::= SEQUENCE OF SMIMECapability
096: * </pre>
097: */
098: public DERObject toASN1Object() {
099: return capabilities;
100: }
101: }
|