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

CA认证

开发平台:

Java

  1. package org.bouncycastle.asn1.ocsp;
  2. import org.bouncycastle.asn1.ASN1Sequence;
  3. import org.bouncycastle.asn1.ASN1TaggedObject;
  4. import org.bouncycastle.asn1.DERSequence;
  5. import org.bouncycastle.asn1.DERTaggedObject;
  6. import org.bouncycastle.asn1.DERObject;
  7. import org.bouncycastle.asn1.DERInteger;
  8. import org.bouncycastle.asn1.DEREncodable;
  9. import org.bouncycastle.asn1.ASN1EncodableVector;
  10. import org.bouncycastle.asn1.x509.GeneralName;
  11. import org.bouncycastle.asn1.x509.X509Extensions;
  12. public class TBSRequest
  13.     implements DEREncodable
  14. {
  15. DERInteger version;
  16. GeneralName requestorName;
  17. ASN1Sequence requestList;
  18. X509Extensions requestExtensions;
  19. public TBSRequest(
  20. ASN1Sequence seq)
  21. {
  22. version = DERInteger.getInstance((ASN1TaggedObject)seq.getObjectAt(0), true);
  23. int index = 1;
  24. if (seq.getObjectAt(index) instanceof ASN1TaggedObject)
  25. {
  26. requestorName = GeneralName.getInstance((ASN1TaggedObject)seq.getObjectAt(index++), true);
  27. }
  28. requestList = (ASN1Sequence)seq.getObjectAt(index++);
  29. if (seq.size() == (index + 1))
  30. {
  31. requestExtensions = X509Extensions.getInstance((ASN1TaggedObject)seq.getObjectAt(index), true);
  32. }
  33. }
  34.     public static TBSRequest getInstance(
  35.         ASN1TaggedObject obj,
  36.         boolean          explicit)
  37.     {
  38.         return getInstance(ASN1Sequence.getInstance(obj, explicit));
  39.     }
  40.     public static TBSRequest getInstance(
  41.         Object  obj)
  42.     {
  43.         if (obj == null || obj instanceof TBSRequest)
  44.         {
  45.             return (TBSRequest)obj;
  46.         }
  47.         else if (obj instanceof ASN1Sequence)
  48.         {
  49.             return new TBSRequest((ASN1Sequence)obj);
  50.         }
  51.         throw new IllegalArgumentException("unknown object in factory");
  52.     }
  53. public DERInteger getVersion()
  54. {
  55. return version;
  56. }
  57. public GeneralName getRequestorName()
  58. {
  59. return requestorName;
  60. }
  61. public ASN1Sequence getRequestList()
  62. {
  63. return requestList;
  64. }
  65. public X509Extensions getRequestExtensions()
  66. {
  67. return requestExtensions;
  68. }
  69. /**
  70.  * <pre>
  71.  * TBSRequest      ::=     SEQUENCE {
  72.  *     version             [0]     EXPLICIT Version DEFAULT v1,
  73.  *     requestorName       [1]     EXPLICIT GeneralName OPTIONAL,
  74.  *     requestList                 SEQUENCE OF Request,
  75.  *     requestExtensions   [2]     EXPLICIT Extensions OPTIONAL }
  76.  * </pre>
  77.  */
  78. public DERObject getDERObject()
  79. {
  80. ASN1EncodableVector v = new ASN1EncodableVector();
  81. v.add(new DERTaggedObject(true, 0, version));
  82. v.add(new DERTaggedObject(true, 1, requestorName));
  83. v.add(requestList);
  84. v.add(new DERTaggedObject(true, 2, requestExtensions));
  85. return new DERSequence(v);
  86. }
  87. }