GeneralNames.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using System.Text;
  5. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  6. namespace Best.HTTP.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. buf.AppendLine("GeneralNames:");
  71. foreach (GeneralName name in names)
  72. {
  73. buf.Append(" ")
  74. .Append(name)
  75. .AppendLine();
  76. }
  77. return buf.ToString();
  78. }
  79. }
  80. }
  81. #pragma warning restore
  82. #endif