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

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.DERObject;
  6. import org.bouncycastle.asn1.DERBitString;
  7. import org.bouncycastle.asn1.DERTaggedObject;
  8. import org.bouncycastle.asn1.DEREncodable;
  9. import org.bouncycastle.asn1.ASN1EncodableVector;
  10. import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
  11. public class Signature
  12.     implements DEREncodable
  13. {
  14. AlgorithmIdentifier signatureAlgorithm;
  15. DERBitString signature;
  16. ASN1Sequence certs;
  17. public Signature(
  18. ASN1Sequence seq)
  19. {
  20. signatureAlgorithm  = AlgorithmIdentifier.getInstance(seq.getObjectAt(0));
  21. signature = (DERBitString)seq.getObjectAt(1);
  22. if (seq.size() == 3)
  23. {
  24. certs = ASN1Sequence.getInstance(
  25. (ASN1TaggedObject)seq.getObjectAt(2), true);
  26. }
  27. }
  28.     public static Signature getInstance(
  29.         ASN1TaggedObject obj,
  30.         boolean          explicit)
  31.     {
  32.         return getInstance(ASN1Sequence.getInstance(obj, explicit));
  33.     }
  34.     public static Signature getInstance(
  35.         Object  obj)
  36.     {
  37.         if (obj == null || obj instanceof Signature)
  38.         {
  39.             return (Signature)obj;
  40.         }
  41.         else if (obj instanceof ASN1Sequence)
  42.         {
  43.             return new Signature((ASN1Sequence)obj);
  44.         }
  45.         throw new IllegalArgumentException("unknown object in factory");
  46.     }
  47. public AlgorithmIdentifier getSignatureAlgorithm()
  48. {
  49. return signatureAlgorithm;
  50. }
  51. public DERBitString getSignature()
  52. {
  53. return signature;
  54. }
  55. public ASN1Sequence getCerts()
  56. {
  57. return certs;
  58. }
  59. /**
  60.  * <pre>
  61.  * Signature       ::=     SEQUENCE {
  62.  *     signatureAlgorithm      AlgorithmIdentifier,
  63.  *     signature               BIT STRING,
  64.  *     certs               [0] EXPLICIT SEQUENCE OF Certificate OPTIONAL}
  65.  * </pre>
  66.  */
  67. public DERObject getDERObject()
  68. {
  69. ASN1EncodableVector v = new ASN1EncodableVector();
  70. v.add(signatureAlgorithm);
  71. v.add(signature);
  72. if (certs != null)
  73. {
  74. v.add(new DERTaggedObject(true, 0, certs));
  75. }
  76. return new DERSequence(v);
  77. }
  78. }