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

CA认证

开发平台:

Java

  1. package org.bouncycastle.asn1.pkcs;
  2. import org.bouncycastle.asn1.*;
  3. import org.bouncycastle.asn1.x509.*;
  4. /**
  5.  * PKCS10
  6.  *
  7.  * <pre>
  8.  *  CertificationRequestInfo ::= SEQUENCE {
  9.  *   version             INTEGER { v1(0) } (v1,...),
  10.  *   subject             Name,
  11.  *   subjectPKInfo   SubjectPublicKeyInfo{{ PKInfoAlgorithms }},
  12.  *   attributes          [0] Attributes{{ CRIAttributes }}
  13.  *  }
  14.  *
  15.  *  Attributes { ATTRIBUTE:IOSet } ::= SET OF Attribute{{ IOSet }}
  16.  *
  17.  *  Attribute { ATTRIBUTE:IOSet } ::= SEQUENCE {
  18.  *    type    ATTRIBUTE.&id({IOSet}),
  19.  *    values  SET SIZE(1..MAX) OF ATTRIBUTE.&Type({IOSet}{@type})
  20.  *  }
  21.  * </pre>
  22.  */
  23. public class CertificationRequestInfo
  24.     implements DEREncodable
  25. {
  26.     DERInteger              version = new DERInteger(0);
  27.     X509Name                subject;
  28.     SubjectPublicKeyInfo    subjectPKInfo;
  29.     ASN1Set                 attributes = null;
  30.     public static CertificationRequestInfo getInstance(
  31.         Object  obj)
  32.     {
  33.         if (obj instanceof CertificationRequestInfo)
  34.         {
  35.             return (CertificationRequestInfo)obj;
  36.         }
  37.         else if (obj instanceof ASN1Sequence)
  38.         {
  39.             return new CertificationRequestInfo((ASN1Sequence)obj);
  40.         }
  41.         throw new IllegalArgumentException("unknown object in factory");
  42.     }
  43.     public CertificationRequestInfo(
  44.         X509Name                subject,
  45.         SubjectPublicKeyInfo    pkInfo,
  46.         ASN1Set                 attributes)
  47.     {
  48.         this.subject = subject;
  49.         this.subjectPKInfo = pkInfo;
  50.         this.attributes = attributes;
  51.         if ((subject == null) || (version == null) || (subjectPKInfo == null))
  52.         {
  53.             throw new IllegalArgumentException("Not all mandatory fields set in CertificationRequestInfo generator.");
  54.         }
  55.     }
  56.     public CertificationRequestInfo(
  57.         ASN1Sequence  seq)
  58.     {
  59.         version = (DERInteger)seq.getObjectAt(0);
  60.         subject = X509Name.getInstance(seq.getObjectAt(1));
  61.         subjectPKInfo = SubjectPublicKeyInfo.getInstance(seq.getObjectAt(2));
  62.         //
  63.         // some CertificationRequestInfo objects seem to treat this field
  64.         // as optional.
  65.         //
  66.         if (seq.size() > 3)
  67.         {
  68.             DERTaggedObject tagobj = (DERTaggedObject)seq.getObjectAt(3);
  69.             attributes = ASN1Set.getInstance(tagobj, false);
  70.         }
  71.         if ((subject == null) || (version == null) || (subjectPKInfo == null))
  72.         {
  73.             throw new IllegalArgumentException("Not all mandatory fields set in CertificationRequestInfo generator.");
  74.         }
  75.     }
  76.     public DERInteger getVersion()
  77.     {
  78.         return version;
  79.     }
  80.     public X509Name getSubject()
  81.     {
  82.         return subject;
  83.     }
  84.     public SubjectPublicKeyInfo getSubjectPublicKeyInfo()
  85.     {
  86.         return subjectPKInfo;
  87.     }
  88.     public ASN1Set getAttributes()
  89.     {
  90.         return (ASN1Set)attributes;
  91.     }
  92.     public DERObject getDERObject()
  93.     {
  94.         ASN1EncodableVector  v = new ASN1EncodableVector();
  95.         v.add(version);
  96.         v.add(subject);
  97.         v.add(subjectPKInfo);
  98.         if (attributes != null)
  99.         {
  100.             v.add(new DERTaggedObject(false, 0, attributes));
  101.         }
  102.         return new DERSequence(v);
  103.     }
  104. }