ContentInfo.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using System.Collections;
  5. using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  6. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cms
  7. {
  8. public class ContentInfo
  9. : Asn1Encodable
  10. {
  11. private readonly DerObjectIdentifier contentType;
  12. private readonly Asn1Encodable content;
  13. public static ContentInfo GetInstance(
  14. object obj)
  15. {
  16. if (obj == null || obj is ContentInfo)
  17. return (ContentInfo) obj;
  18. if (obj is Asn1Sequence)
  19. return new ContentInfo((Asn1Sequence) obj);
  20. throw new ArgumentException("unknown object in factory: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj));
  21. }
  22. public static ContentInfo GetInstance(Asn1TaggedObject obj, bool isExplicit)
  23. {
  24. return GetInstance(Asn1Sequence.GetInstance(obj, isExplicit));
  25. }
  26. private ContentInfo(
  27. Asn1Sequence seq)
  28. {
  29. if (seq.Count < 1 || seq.Count > 2)
  30. throw new ArgumentException("Bad sequence size: " + seq.Count, "seq");
  31. contentType = (DerObjectIdentifier) seq[0];
  32. if (seq.Count > 1)
  33. {
  34. Asn1TaggedObject tagged = (Asn1TaggedObject) seq[1];
  35. if (!tagged.IsExplicit() || tagged.TagNo != 0)
  36. throw new ArgumentException("Bad tag for 'content'", "seq");
  37. content = tagged.GetObject();
  38. }
  39. }
  40. public ContentInfo(
  41. DerObjectIdentifier contentType,
  42. Asn1Encodable content)
  43. {
  44. this.contentType = contentType;
  45. this.content = content;
  46. }
  47. public DerObjectIdentifier ContentType
  48. {
  49. get { return contentType; }
  50. }
  51. public Asn1Encodable Content
  52. {
  53. get { return content; }
  54. }
  55. /**
  56. * Produce an object suitable for an Asn1OutputStream.
  57. * <pre>
  58. * ContentInfo ::= Sequence {
  59. * contentType ContentType,
  60. * content
  61. * [0] EXPLICIT ANY DEFINED BY contentType OPTIONAL }
  62. * </pre>
  63. */
  64. public override Asn1Object ToAsn1Object()
  65. {
  66. Asn1EncodableVector v = new Asn1EncodableVector(contentType);
  67. if (content != null)
  68. {
  69. v.Add(new BerTaggedObject(0, content));
  70. }
  71. return new BerSequence(v);
  72. }
  73. }
  74. }
  75. #pragma warning restore
  76. #endif