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

CA认证

开发平台:

Java

  1. package org.bouncycastle.asn1.smime;
  2. import org.bouncycastle.asn1.ASN1Sequence;
  3. import org.bouncycastle.asn1.DERSequence;
  4. import org.bouncycastle.asn1.DEREncodable;
  5. import org.bouncycastle.asn1.DEREncodableVector;
  6. import org.bouncycastle.asn1.DERObject;
  7. import org.bouncycastle.asn1.DERObjectIdentifier;
  8. import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
  9. public class SMIMECapability
  10.     implements DEREncodable
  11. {
  12.     /**
  13.      * general preferences
  14.      */
  15.     public static final DERObjectIdentifier preferSignedData = PKCSObjectIdentifiers.preferSignedData;
  16.     public static final DERObjectIdentifier canNotDecryptAny = PKCSObjectIdentifiers.canNotDecryptAny;
  17.     public static final DERObjectIdentifier sMIMECapabilitiesVersions = PKCSObjectIdentifiers.sMIMECapabilitiesVersions;
  18.     /**
  19.      * encryption algorithms preferences
  20.      */
  21.     public static final DERObjectIdentifier dES_CBC = new DERObjectIdentifier("1.3.14.3.2.7");
  22.     public static final DERObjectIdentifier dES_EDE3_CBC = PKCSObjectIdentifiers.des_EDE3_CBC;
  23.     public static final DERObjectIdentifier rC2_CBC = PKCSObjectIdentifiers.RC2_CBC;
  24. private DERObjectIdentifier capabilityID;
  25. private DEREncodable        parameters;
  26. public SMIMECapability(
  27.         ASN1Sequence seq)
  28.     {
  29. capabilityID = (DERObjectIdentifier)seq.getObjectAt(0);
  30. if (seq.size() > 1)
  31.         {
  32. parameters = (DERObject)seq.getObjectAt(1);
  33. }
  34. }
  35. public SMIMECapability(
  36.         DERObjectIdentifier capabilityID,
  37.         DEREncodable parameters)
  38.     {
  39. this.capabilityID = capabilityID;
  40. this.parameters = parameters;
  41. }
  42. public static SMIMECapability getInstance(
  43.         Object obj)
  44.     {
  45. if (obj == null || obj instanceof SMIMECapability)
  46.         {
  47. return (SMIMECapability)obj;
  48. }
  49. if (obj instanceof ASN1Sequence)
  50.         {
  51. return new SMIMECapability((ASN1Sequence)obj);
  52. }
  53. throw new IllegalArgumentException("Invalid SMIMECapability");
  54.     public DERObjectIdentifier getCapabilityID()
  55.     {
  56. return capabilityID;
  57.     }
  58.     public DEREncodable getParameters()
  59.     {
  60. return parameters;
  61.     }
  62.     /**
  63.      * <pre> 
  64.      * SMIMECapability ::= SEQUENCE {
  65.      *  capabilityID OBJECT IDENTIFIER,
  66.      *  parameters ANY DEFINED BY capabilityID OPTIONAL 
  67.      * }
  68.      * </pre>
  69.      */
  70. public DERObject getDERObject()
  71.     {
  72.         DEREncodableVector  v = new DEREncodableVector();
  73. v.add(capabilityID);
  74. if (parameters != null)
  75.         {
  76. v.add(parameters);
  77. }
  78. return new DERSequence(v);
  79. }
  80. }