ContentInfo.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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.Asn1;
  6. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Pkcs
  7. {
  8. public class ContentInfo
  9. : Asn1Encodable
  10. {
  11. private readonly DerObjectIdentifier contentType;
  12. private readonly Asn1Encodable content;
  13. public static ContentInfo GetInstance(object obj)
  14. {
  15. if (obj == null)
  16. return null;
  17. ContentInfo existing = obj as ContentInfo;
  18. if (existing != null)
  19. return existing;
  20. return new ContentInfo(Asn1Sequence.GetInstance(obj));
  21. }
  22. private ContentInfo(
  23. Asn1Sequence seq)
  24. {
  25. contentType = (DerObjectIdentifier) seq[0];
  26. if (seq.Count > 1)
  27. {
  28. content = ((Asn1TaggedObject) seq[1]).GetObject();
  29. }
  30. }
  31. public ContentInfo(
  32. DerObjectIdentifier contentType,
  33. Asn1Encodable content)
  34. {
  35. this.contentType = contentType;
  36. this.content = content;
  37. }
  38. public DerObjectIdentifier ContentType
  39. {
  40. get { return contentType; }
  41. }
  42. public Asn1Encodable Content
  43. {
  44. get { return content; }
  45. }
  46. /**
  47. * Produce an object suitable for an Asn1OutputStream.
  48. * <pre>
  49. * ContentInfo ::= Sequence {
  50. * contentType ContentType,
  51. * content
  52. * [0] EXPLICIT ANY DEFINED BY contentType OPTIONAL }
  53. * </pre>
  54. */
  55. public override Asn1Object ToAsn1Object()
  56. {
  57. Asn1EncodableVector v = new Asn1EncodableVector(contentType);
  58. if (content != null)
  59. {
  60. v.Add(new BerTaggedObject(0, content));
  61. }
  62. return new BerSequence(v);
  63. }
  64. }
  65. }
  66. #pragma warning restore
  67. #endif