SMIMECapabilities.java
上传用户:lior1029
上传日期:2013-05-07
资源大小:209k
文件大小:3k
源码类别:

CA认证

开发平台:

Java

  1. package org.bouncycastle.asn1.smime;
  2. import java.util.Vector;
  3. import java.util.Enumeration;
  4. import org.bouncycastle.asn1.ASN1Sequence;
  5. import org.bouncycastle.asn1.DERObjectIdentifier;
  6. import org.bouncycastle.asn1.DERObject;
  7. import org.bouncycastle.asn1.DEREncodable;
  8. import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
  9. import org.bouncycastle.asn1.cms.Attribute;
  10. /**
  11.  * Handler class for dealing with S/MIME Capabilities
  12.  */
  13. public class SMIMECapabilities
  14.     implements DEREncodable
  15. {
  16.     /**
  17.      * general preferences
  18.      */
  19.     public static final DERObjectIdentifier preferSignedData = PKCSObjectIdentifiers.preferSignedData;
  20.     public static final DERObjectIdentifier canNotDecryptAny = PKCSObjectIdentifiers.canNotDecryptAny;
  21.     public static final DERObjectIdentifier sMIMECapabilitesVersions = PKCSObjectIdentifiers.sMIMECapabilitiesVersions;
  22.     /**
  23.      * encryption algorithms preferences
  24.      */
  25.     public static final DERObjectIdentifier dES_CBC = new DERObjectIdentifier("1.3.14.3.2.7");
  26.     public static final DERObjectIdentifier dES_EDE3_CBC = PKCSObjectIdentifiers.des_EDE3_CBC;
  27.     public static final DERObjectIdentifier rC2_CBC = PKCSObjectIdentifiers.RC2_CBC;
  28. private ASN1Sequence         capabilities;
  29.     /**
  30.      * return an Attribute object from the given object.
  31.      *
  32.      * @param o the object we want converted.
  33.      * @exception IllegalArgumentException if the object cannot be converted.
  34.      */
  35. public static SMIMECapabilities getInstance(
  36.         Object o)
  37.     {
  38. if (o == null || o instanceof SMIMECapabilities)
  39.         {
  40. return (SMIMECapabilities)o;
  41. }
  42. if (o instanceof ASN1Sequence)
  43.         {
  44. return new SMIMECapabilities((ASN1Sequence)o);
  45. }
  46. if (o instanceof Attribute)
  47.         {
  48. return new SMIMECapabilities(
  49.                 (ASN1Sequence)(((Attribute)o).getAttrValues().getObjectAt(0)));
  50. }
  51.         throw new IllegalArgumentException("unknown object in factory");
  52. }
  53. public SMIMECapabilities(
  54.         ASN1Sequence seq)
  55.     {
  56. capabilities = seq;
  57. }
  58.     /**
  59.      * returns a vector with 0 or more objects of all the capabilities
  60.      * matching the passed in capability OID. If the OID passed is null the
  61.      * entire set is returned.
  62.      */
  63.     public Vector getCapabilities(
  64.         DERObjectIdentifier capability)
  65.     {
  66.         Enumeration e = capabilities.getObjects();
  67.         Vector      list = new Vector();
  68.         if (capability == null)
  69.         {
  70.             while (e.hasMoreElements())
  71.             {
  72.                 SMIMECapability  cap = SMIMECapability.getInstance(e.nextElement());
  73.                 list.addElement(cap);
  74.             }
  75.         }
  76.         else
  77.         {
  78.             while (e.hasMoreElements())
  79.             {
  80.                 SMIMECapability  cap = SMIMECapability.getInstance(e.nextElement());
  81.                 if (capability.equals(cap.getCapabilityID()))
  82.                 {
  83.                     list.addElement(cap);
  84.                 }
  85.             }
  86.         }
  87.         return list;
  88. }
  89.     /** 
  90.      * <pre>
  91.      * SMIMECapabilities ::= SEQUENCE OF SMIMECapability
  92.      * </pre>
  93.      */
  94. public DERObject getDERObject()
  95.     {
  96. return capabilities;
  97. }
  98. }