ContentInfo.cs 2.6 KB

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