ContentHints.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  5. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Ess
  6. {
  7. public class ContentHints
  8. : Asn1Encodable
  9. {
  10. private readonly DerUtf8String contentDescription;
  11. private readonly DerObjectIdentifier contentType;
  12. public static ContentHints GetInstance(
  13. object o)
  14. {
  15. if (o == null || o is ContentHints)
  16. {
  17. return (ContentHints)o;
  18. }
  19. if (o is Asn1Sequence)
  20. {
  21. return new ContentHints((Asn1Sequence)o);
  22. }
  23. throw new ArgumentException("unknown object in 'ContentHints' factory : "
  24. + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(o) + ".");
  25. }
  26. /**
  27. * constructor
  28. */
  29. private ContentHints(
  30. Asn1Sequence seq)
  31. {
  32. IAsn1Convertible field = seq[0];
  33. if (field.ToAsn1Object() is DerUtf8String)
  34. {
  35. contentDescription = DerUtf8String.GetInstance(field);
  36. contentType = DerObjectIdentifier.GetInstance(seq[1]);
  37. }
  38. else
  39. {
  40. contentType = DerObjectIdentifier.GetInstance(seq[0]);
  41. }
  42. }
  43. public ContentHints(
  44. DerObjectIdentifier contentType)
  45. {
  46. this.contentType = contentType;
  47. this.contentDescription = null;
  48. }
  49. public ContentHints(
  50. DerObjectIdentifier contentType,
  51. DerUtf8String contentDescription)
  52. {
  53. this.contentType = contentType;
  54. this.contentDescription = contentDescription;
  55. }
  56. public DerObjectIdentifier ContentType
  57. {
  58. get { return contentType; }
  59. }
  60. public DerUtf8String ContentDescription
  61. {
  62. get { return contentDescription; }
  63. }
  64. /**
  65. * <pre>
  66. * ContentHints ::= SEQUENCE {
  67. * contentDescription UTF8String (SIZE (1..MAX)) OPTIONAL,
  68. * contentType ContentType }
  69. * </pre>
  70. */
  71. public override Asn1Object ToAsn1Object()
  72. {
  73. Asn1EncodableVector v = new Asn1EncodableVector();
  74. v.AddOptional(contentDescription);
  75. v.Add(contentType);
  76. return new DerSequence(v);
  77. }
  78. }
  79. }
  80. #pragma warning restore
  81. #endif