PKIFreeText.cs 1.9 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. public int Size
  54. {
  55. get { return strings.Count; }
  56. }
  57. public int Count
  58. {
  59. get { return strings.Count; }
  60. }
  61. /**
  62. * Return the UTF8STRING at index.
  63. *
  64. * @param index index of the string of interest
  65. * @return the string at index.
  66. */
  67. public DerUtf8String this[int index]
  68. {
  69. get { return (DerUtf8String) strings[index]; }
  70. }
  71. public DerUtf8String GetStringAt(
  72. int index)
  73. {
  74. return this[index];
  75. }
  76. /**
  77. * <pre>
  78. * PkiFreeText ::= SEQUENCE SIZE (1..MAX) OF UTF8String
  79. * </pre>
  80. */
  81. public override Asn1Object ToAsn1Object()
  82. {
  83. return strings;
  84. }
  85. }
  86. }
  87. #pragma warning restore
  88. #endif