PKIFreeText.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cmp
  5. {
  6. public class PkiFreeText
  7. : Asn1Encodable
  8. {
  9. public static PkiFreeText GetInstance(object obj)
  10. {
  11. if (obj is PkiFreeText pkiFreeText)
  12. return pkiFreeText;
  13. if (obj != null)
  14. return new PkiFreeText(Asn1Sequence.GetInstance(obj));
  15. return null;
  16. }
  17. public static PkiFreeText GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
  18. {
  19. return GetInstance(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
  20. }
  21. internal Asn1Sequence m_strings;
  22. internal PkiFreeText(Asn1Sequence seq)
  23. {
  24. foreach (var element in seq)
  25. {
  26. if (!(element is DerUtf8String))
  27. throw new ArgumentException("attempt to insert non UTF8 STRING into PkiFreeText");
  28. }
  29. m_strings = seq;
  30. }
  31. public PkiFreeText(DerUtf8String p)
  32. {
  33. m_strings = new DerSequence(p);
  34. }
  35. public PkiFreeText(string p)
  36. : this(new DerUtf8String(p))
  37. {
  38. }
  39. public PkiFreeText(DerUtf8String[] strs)
  40. {
  41. m_strings = new DerSequence(strs);
  42. }
  43. public PkiFreeText(string[] strs)
  44. {
  45. Asn1EncodableVector v = new Asn1EncodableVector(strs.Length);
  46. for (int i = 0; i < strs.Length; i++)
  47. {
  48. v.Add(new DerUtf8String(strs[i]));
  49. }
  50. m_strings = new DerSequence(v);
  51. }
  52. public virtual int Count => m_strings.Count;
  53. /**
  54. * Return the UTF8STRING at index.
  55. *
  56. * @param index index of the string of interest
  57. * @return the string at index.
  58. */
  59. public DerUtf8String this[int index]
  60. {
  61. get { return (DerUtf8String)m_strings[index]; }
  62. }
  63. /**
  64. * <pre>
  65. * PkiFreeText ::= SEQUENCE SIZE (1..MAX) OF UTF8String
  66. * </pre>
  67. */
  68. public override Asn1Object ToAsn1Object()
  69. {
  70. return m_strings;
  71. }
  72. }
  73. }
  74. #pragma warning restore
  75. #endif