GeneralNames.cs 2.0 KB

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