ContentInfo.cs 1.9 KB

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