CompressedData.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
  5. using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  6. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cms
  7. {
  8. /**
  9. * RFC 3274 - CMS Compressed Data.
  10. * <pre>
  11. * CompressedData ::= Sequence {
  12. * version CMSVersion,
  13. * compressionAlgorithm CompressionAlgorithmIdentifier,
  14. * encapContentInfo EncapsulatedContentInfo
  15. * }
  16. * </pre>
  17. */
  18. public class CompressedData
  19. : Asn1Encodable
  20. {
  21. private DerInteger version;
  22. private AlgorithmIdentifier compressionAlgorithm;
  23. private ContentInfo encapContentInfo;
  24. public CompressedData(
  25. AlgorithmIdentifier compressionAlgorithm,
  26. ContentInfo encapContentInfo)
  27. {
  28. this.version = new DerInteger(0);
  29. this.compressionAlgorithm = compressionAlgorithm;
  30. this.encapContentInfo = encapContentInfo;
  31. }
  32. public CompressedData(
  33. Asn1Sequence seq)
  34. {
  35. this.version = (DerInteger) seq[0];
  36. this.compressionAlgorithm = AlgorithmIdentifier.GetInstance(seq[1]);
  37. this.encapContentInfo = ContentInfo.GetInstance(seq[2]);
  38. }
  39. /**
  40. * return a CompressedData object from a tagged object.
  41. *
  42. * @param ato the tagged object holding the object we want.
  43. * @param explicitly true if the object is meant to be explicitly
  44. * tagged false otherwise.
  45. * @exception ArgumentException if the object held by the
  46. * tagged object cannot be converted.
  47. */
  48. public static CompressedData GetInstance(
  49. Asn1TaggedObject ato,
  50. bool explicitly)
  51. {
  52. return GetInstance(Asn1Sequence.GetInstance(ato, explicitly));
  53. }
  54. /**
  55. * return a CompressedData object from the given object.
  56. *
  57. * @param _obj the object we want converted.
  58. * @exception ArgumentException if the object cannot be converted.
  59. */
  60. public static CompressedData GetInstance(
  61. object obj)
  62. {
  63. if (obj == null || obj is CompressedData)
  64. return (CompressedData)obj;
  65. if (obj is Asn1Sequence)
  66. return new CompressedData((Asn1Sequence) obj);
  67. throw new ArgumentException("Invalid CompressedData: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj));
  68. }
  69. public DerInteger Version
  70. {
  71. get { return version; }
  72. }
  73. public AlgorithmIdentifier CompressionAlgorithmIdentifier
  74. {
  75. get { return compressionAlgorithm; }
  76. }
  77. public ContentInfo EncapContentInfo
  78. {
  79. get { return encapContentInfo; }
  80. }
  81. public override Asn1Object ToAsn1Object()
  82. {
  83. return new BerSequence(version, compressionAlgorithm, encapContentInfo);
  84. }
  85. }
  86. }
  87. #pragma warning restore
  88. #endif