GeneralNames.cs 2.3 KB

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