OriginatorInfo.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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.Cms
  6. {
  7. public class OriginatorInfo
  8. : Asn1Encodable
  9. {
  10. private Asn1Set certs;
  11. private Asn1Set crls;
  12. public OriginatorInfo(
  13. Asn1Set certs,
  14. Asn1Set crls)
  15. {
  16. this.certs = certs;
  17. this.crls = crls;
  18. }
  19. public OriginatorInfo(
  20. Asn1Sequence seq)
  21. {
  22. switch (seq.Count)
  23. {
  24. case 0: // empty
  25. break;
  26. case 1:
  27. Asn1TaggedObject o = (Asn1TaggedObject) seq[0];
  28. switch (o.TagNo)
  29. {
  30. case 0 :
  31. certs = Asn1Set.GetInstance(o, false);
  32. break;
  33. case 1 :
  34. crls = Asn1Set.GetInstance(o, false);
  35. break;
  36. default:
  37. throw new ArgumentException("Bad tag in OriginatorInfo: " + o.TagNo);
  38. }
  39. break;
  40. case 2:
  41. certs = Asn1Set.GetInstance((Asn1TaggedObject) seq[0], false);
  42. crls = Asn1Set.GetInstance((Asn1TaggedObject) seq[1], false);
  43. break;
  44. default:
  45. throw new ArgumentException("OriginatorInfo too big");
  46. }
  47. }
  48. /**
  49. * return an OriginatorInfo object from a tagged object.
  50. *
  51. * @param obj the tagged object holding the object we want.
  52. * @param explicitly true if the object is meant to be explicitly
  53. * tagged false otherwise.
  54. * @exception ArgumentException if the object held by the
  55. * tagged object cannot be converted.
  56. */
  57. public static OriginatorInfo GetInstance(
  58. Asn1TaggedObject obj,
  59. bool explicitly)
  60. {
  61. return GetInstance(Asn1Sequence.GetInstance(obj, explicitly));
  62. }
  63. /**
  64. * return an OriginatorInfo object from the given object.
  65. *
  66. * @param obj the object we want converted.
  67. * @exception ArgumentException if the object cannot be converted.
  68. */
  69. public static OriginatorInfo GetInstance(
  70. object obj)
  71. {
  72. if (obj == null || obj is OriginatorInfo)
  73. return (OriginatorInfo)obj;
  74. if (obj is Asn1Sequence)
  75. return new OriginatorInfo((Asn1Sequence)obj);
  76. throw new ArgumentException("Invalid OriginatorInfo: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj));
  77. }
  78. public Asn1Set Certificates
  79. {
  80. get { return certs; }
  81. }
  82. public Asn1Set Crls
  83. {
  84. get { return crls; }
  85. }
  86. /**
  87. * Produce an object suitable for an Asn1OutputStream.
  88. * <pre>
  89. * OriginatorInfo ::= Sequence {
  90. * certs [0] IMPLICIT CertificateSet OPTIONAL,
  91. * crls [1] IMPLICIT CertificateRevocationLists OPTIONAL
  92. * }
  93. * </pre>
  94. */
  95. public override Asn1Object ToAsn1Object()
  96. {
  97. Asn1EncodableVector v = new Asn1EncodableVector();
  98. v.AddOptionalTagged(false, 0, certs);
  99. v.AddOptionalTagged(false, 1, crls);
  100. return new DerSequence(v);
  101. }
  102. }
  103. }
  104. #pragma warning restore
  105. #endif