PKIFreeText.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using System.Collections;
  5. using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  6. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cmp
  7. {
  8. public class PkiFreeText
  9. : Asn1Encodable
  10. {
  11. internal Asn1Sequence strings;
  12. public static PkiFreeText GetInstance(
  13. Asn1TaggedObject obj,
  14. bool isExplicit)
  15. {
  16. return GetInstance(Asn1Sequence.GetInstance(obj, isExplicit));
  17. }
  18. public static PkiFreeText GetInstance(
  19. object obj)
  20. {
  21. if (obj is PkiFreeText)
  22. {
  23. return (PkiFreeText)obj;
  24. }
  25. else if (obj is Asn1Sequence)
  26. {
  27. return new PkiFreeText((Asn1Sequence)obj);
  28. }
  29. throw new ArgumentException("Unknown object in factory: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
  30. }
  31. public PkiFreeText(
  32. Asn1Sequence seq)
  33. {
  34. foreach (object o in seq)
  35. {
  36. if (!(o is DerUtf8String))
  37. {
  38. throw new ArgumentException("attempt to insert non UTF8 STRING into PkiFreeText");
  39. }
  40. }
  41. this.strings = seq;
  42. }
  43. public PkiFreeText(
  44. DerUtf8String p)
  45. {
  46. strings = new DerSequence(p);
  47. }
  48. /**
  49. * Return the number of string elements present.
  50. *
  51. * @return number of elements present.
  52. */
  53. [Obsolete("Use 'Count' property instead")]
  54. public int Size
  55. {
  56. get { return strings.Count; }
  57. }
  58. public int Count
  59. {
  60. get { return strings.Count; }
  61. }
  62. /**
  63. * Return the UTF8STRING at index.
  64. *
  65. * @param index index of the string of interest
  66. * @return the string at index.
  67. */
  68. public DerUtf8String this[int index]
  69. {
  70. get { return (DerUtf8String) strings[index]; }
  71. }
  72. [Obsolete("Use 'object[index]' syntax instead")]
  73. public DerUtf8String GetStringAt(
  74. int index)
  75. {
  76. return this[index];
  77. }
  78. /**
  79. * <pre>
  80. * PkiFreeText ::= SEQUENCE SIZE (1..MAX) OF UTF8String
  81. * </pre>
  82. */
  83. public override Asn1Object ToAsn1Object()
  84. {
  85. return strings;
  86. }
  87. }
  88. }
  89. #pragma warning restore
  90. #endif