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

CA认证

开发平台:

Java

  1. package org.bouncycastle.asn1.cms;
  2. import org.bouncycastle.asn1.ASN1Sequence;
  3. import org.bouncycastle.asn1.ASN1TaggedObject;
  4. import org.bouncycastle.asn1.DERTaggedObject;
  5. import org.bouncycastle.asn1.DEREncodable;
  6. import org.bouncycastle.asn1.DERInteger;
  7. import org.bouncycastle.asn1.DERObject;
  8. public class RecipientInfo
  9.     implements DEREncodable
  10. {
  11.     DEREncodable    info;
  12.     public RecipientInfo(
  13.         KeyTransRecipientInfo info)
  14.     {
  15.         this.info = info;
  16.     }
  17.     public RecipientInfo(
  18.         KeyAgreeRecipientInfo info)
  19.     {
  20.         this.info = new DERTaggedObject(true, 1, info);
  21.     }
  22.     public RecipientInfo(
  23.         KEKRecipientInfo info)
  24.     {
  25.         this.info = new DERTaggedObject(true, 2, info);
  26.     }
  27.     public RecipientInfo(
  28.         DERObject   info)
  29.     {
  30.         this.info = info;
  31.     }
  32.     public static RecipientInfo getInstance(
  33.         Object  o)
  34.     {
  35.         if (o == null || o instanceof RecipientInfo)
  36.         {
  37.             return (RecipientInfo)o;
  38.         }
  39.         else if (o instanceof ASN1Sequence)
  40.         {
  41.             return new RecipientInfo((ASN1Sequence)o);
  42.         }
  43.         else if (o instanceof ASN1TaggedObject)
  44.         {
  45.             return new RecipientInfo((ASN1TaggedObject)o);
  46.         }
  47.         throw new IllegalArgumentException("unknown object in factory: "
  48.                                                     + o.getClass().getName());
  49.     }
  50.     public DERInteger getVersion()
  51.     {
  52.         if (info instanceof ASN1TaggedObject)
  53.         {
  54.             ASN1TaggedObject o = (ASN1TaggedObject)info;
  55.             switch (o.getTagNo())
  56.             {
  57.             case 1:
  58.                 return KeyAgreeRecipientInfo.getInstance(o, true).getVersion();
  59.             case 2:
  60.                 return KEKRecipientInfo.getInstance(o, true).getVersion();
  61.             default:
  62.                 throw new IllegalStateException("unknown tag");
  63.             }
  64.         }
  65.         return KeyTransRecipientInfo.getInstance(info).getVersion();
  66.     }
  67.     public boolean isTagged()
  68.     {
  69.         return (info instanceof ASN1TaggedObject);
  70.     }
  71. public DEREncodable getInfo()
  72.     {
  73.         if (info instanceof ASN1TaggedObject)
  74.         {
  75.             ASN1TaggedObject o = (ASN1TaggedObject)info;
  76.             switch (o.getTagNo())
  77.             {
  78.             case 1:
  79.                 return KeyAgreeRecipientInfo.getInstance(o, true);
  80.             case 2:
  81.                 return KEKRecipientInfo.getInstance(o, true);
  82.             default:
  83.                 throw new IllegalStateException("unknown tag");
  84.             }
  85.         }
  86.         return KeyTransRecipientInfo.getInstance(info);
  87. }
  88.     /** 
  89.      * <pre>
  90.      * RecipientInfo ::= CHOICE {
  91.      *  ktri KeyTransRecipientInfo,
  92.      *  kari [1] KeyAgreeRecipientInfo,
  93.      *  kekri [2] KEKRecipientInfo 
  94.      * }
  95.      * </pre>
  96.      */
  97. public DERObject getDERObject()
  98.     {
  99.         return info.getDERObject();
  100. }
  101. }