ContentInfo.cs 1.9 KB

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