CompressedData.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.ASN1Set;
  4. import org.bouncycastle.asn1.ASN1TaggedObject;
  5. import org.bouncycastle.asn1.BERConstructedSequence;
  6. import org.bouncycastle.asn1.BERTaggedObject;
  7. import org.bouncycastle.asn1.DERInteger;
  8. import org.bouncycastle.asn1.DERObject;
  9. import org.bouncycastle.asn1.DERObjectIdentifier;
  10. import org.bouncycastle.asn1.DEREncodable;
  11. import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
  12. /** 
  13.  * <br>
  14.  * RFC 3274
  15.  * <pre>
  16.  * CompressedData ::= SEQUENCE {
  17.  *  version CMSVersion,
  18.  *  compressionAlgorithm CompressionAlgorithmIdentifier,
  19.  *  encapContentInfo EncapsulatedContentInfo
  20.  * }
  21.  * </pre>
  22.  */
  23. public class CompressedData
  24.     implements DEREncodable
  25. {
  26. private DERInteger                  version;
  27. private AlgorithmIdentifier          compressionAlgorithm;
  28. private ContentInfo                 encapContentInfo;
  29. public CompressedData(
  30.         AlgorithmIdentifier compressionAlgorithm,
  31.         ContentInfo         encapContentInfo)
  32.     {
  33.         this.version = new DERInteger(0);
  34.         this.compressionAlgorithm = compressionAlgorithm;
  35.         this.encapContentInfo = encapContentInfo;
  36. }
  37. public CompressedData(
  38.         ASN1Sequence seq)
  39.     {
  40.         this.version = (DERInteger)seq.getObjectAt(0);
  41. this.compressionAlgorithm = AlgorithmIdentifier.getInstance(seq.getObjectAt(1));
  42. this.encapContentInfo = ContentInfo.getInstance(seq.getObjectAt(2));
  43. }
  44.     /**
  45.      * return a CompressedData object from a tagged object.
  46.      *
  47.      * @param _ato the tagged object holding the object we want.
  48.      * @param _explicit true if the object is meant to be explicitly
  49.      *              tagged false otherwise.
  50.      * @exception IllegalArgumentException if the object held by the
  51.      *          tagged object cannot be converted.
  52.      */
  53. public static CompressedData getInstance(
  54.         ASN1TaggedObject _ato,
  55.         boolean _explicit)
  56.     {
  57. return getInstance(ASN1Sequence.getInstance(_ato, _explicit));
  58. }
  59.     /**
  60.      * return a CompressedData object from the given object.
  61.      *
  62.      * @param _obj the object we want converted.
  63.      * @exception IllegalArgumentException if the object cannot be converted.
  64.      */
  65. public static CompressedData getInstance(
  66.         Object _obj)
  67.     {
  68. if (_obj == null || _obj instanceof CompressedData)
  69.         {
  70. return (CompressedData)_obj;
  71. }
  72. if (_obj instanceof ASN1Sequence)
  73.         {
  74. return new CompressedData((ASN1Sequence)_obj);
  75. }
  76. throw new IllegalArgumentException("Invalid CompressedData: " + _obj.getClass().getName());
  77. }
  78. public DERInteger getVersion()
  79.     {
  80. return version;
  81. }
  82. public AlgorithmIdentifier getCompressionAlgorithmIdentifier()
  83.     {
  84. return compressionAlgorithm;
  85. }
  86. public ContentInfo getEncapContentInfo()
  87.     {
  88. return encapContentInfo;
  89. }
  90. public DERObject getDERObject()
  91.     {
  92. BERConstructedSequence _seq = new BERConstructedSequence();
  93. _seq.addObject(version);
  94. _seq.addObject(compressionAlgorithm);
  95. _seq.addObject(encapContentInfo);
  96. return _seq;
  97. }
  98. }