GeneralNames.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using System.Text;
  5. using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  6. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509
  7. {
  8. public class GeneralNames
  9. : Asn1Encodable
  10. {
  11. private readonly GeneralName[] names;
  12. public static GeneralNames GetInstance(
  13. object obj)
  14. {
  15. if (obj == null || obj is GeneralNames)
  16. {
  17. return (GeneralNames) obj;
  18. }
  19. if (obj is Asn1Sequence)
  20. {
  21. return new GeneralNames((Asn1Sequence) obj);
  22. }
  23. throw new ArgumentException("unknown object in factory: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
  24. }
  25. public static GeneralNames GetInstance(
  26. Asn1TaggedObject obj,
  27. bool explicitly)
  28. {
  29. return GetInstance(Asn1Sequence.GetInstance(obj, explicitly));
  30. }
  31. /// <summary>Construct a GeneralNames object containing one GeneralName.</summary>
  32. /// <param name="name">The name to be contained.</param>
  33. public GeneralNames(
  34. GeneralName name)
  35. {
  36. names = new GeneralName[]{ name };
  37. }
  38. public GeneralNames(
  39. GeneralName[] names)
  40. {
  41. this.names = (GeneralName[])names.Clone();
  42. }
  43. private GeneralNames(
  44. Asn1Sequence seq)
  45. {
  46. this.names = new GeneralName[seq.Count];
  47. for (int i = 0; i != seq.Count; i++)
  48. {
  49. names[i] = GeneralName.GetInstance(seq[i]);
  50. }
  51. }
  52. public GeneralName[] GetNames()
  53. {
  54. return (GeneralName[]) names.Clone();
  55. }
  56. /**
  57. * Produce an object suitable for an Asn1OutputStream.
  58. * <pre>
  59. * GeneralNames ::= Sequence SIZE {1..MAX} OF GeneralName
  60. * </pre>
  61. */
  62. public override Asn1Object ToAsn1Object()
  63. {
  64. return new DerSequence(names);
  65. }
  66. public override string ToString()
  67. {
  68. StringBuilder buf = new StringBuilder();
  69. string sep = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.NewLine;
  70. buf.Append("GeneralNames:");
  71. buf.Append(sep);
  72. foreach (GeneralName name in names)
  73. {
  74. buf.Append(" ");
  75. buf.Append(name);
  76. buf.Append(sep);
  77. }
  78. return buf.ToString();
  79. }
  80. }
  81. }
  82. #pragma warning restore
  83. #endif