MetaData.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cms
  5. {
  6. public class MetaData
  7. : Asn1Encodable
  8. {
  9. private DerBoolean hashProtected;
  10. private DerUtf8String fileName;
  11. private DerIA5String mediaType;
  12. private Attributes otherMetaData;
  13. public MetaData(
  14. DerBoolean hashProtected,
  15. DerUtf8String fileName,
  16. DerIA5String mediaType,
  17. Attributes otherMetaData)
  18. {
  19. this.hashProtected = hashProtected;
  20. this.fileName = fileName;
  21. this.mediaType = mediaType;
  22. this.otherMetaData = otherMetaData;
  23. }
  24. private MetaData(Asn1Sequence seq)
  25. {
  26. this.hashProtected = DerBoolean.GetInstance(seq[0]);
  27. int index = 1;
  28. if (index < seq.Count && seq[index] is DerUtf8String)
  29. {
  30. this.fileName = DerUtf8String.GetInstance(seq[index++]);
  31. }
  32. if (index < seq.Count && seq[index] is DerIA5String)
  33. {
  34. this.mediaType = DerIA5String.GetInstance(seq[index++]);
  35. }
  36. if (index < seq.Count)
  37. {
  38. this.otherMetaData = Attributes.GetInstance(seq[index++]);
  39. }
  40. }
  41. public static MetaData GetInstance(object obj)
  42. {
  43. if (obj is MetaData)
  44. return (MetaData)obj;
  45. if (obj != null)
  46. return new MetaData(Asn1Sequence.GetInstance(obj));
  47. return null;
  48. }
  49. /**
  50. * <pre>
  51. * MetaData ::= SEQUENCE {
  52. * hashProtected BOOLEAN,
  53. * fileName UTF8String OPTIONAL,
  54. * mediaType IA5String OPTIONAL,
  55. * otherMetaData Attributes OPTIONAL
  56. * }
  57. * </pre>
  58. * @return
  59. */
  60. public override Asn1Object ToAsn1Object()
  61. {
  62. Asn1EncodableVector v = new Asn1EncodableVector(hashProtected);
  63. v.AddOptional(fileName, mediaType, otherMetaData);
  64. return new DerSequence(v);
  65. }
  66. public virtual bool IsHashProtected
  67. {
  68. get { return hashProtected.IsTrue; }
  69. }
  70. public virtual DerUtf8String FileName
  71. {
  72. get { return fileName; }
  73. }
  74. public virtual DerIA5String MediaType
  75. {
  76. get { return mediaType; }
  77. }
  78. public virtual Attributes OtherMetaData
  79. {
  80. get { return otherMetaData; }
  81. }
  82. }
  83. }
  84. #pragma warning restore
  85. #endif