DirectoryString.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  5. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X500
  6. {
  7. public class DirectoryString
  8. : Asn1Encodable, IAsn1Choice, IAsn1String
  9. {
  10. private readonly DerStringBase str;
  11. public static DirectoryString GetInstance(object obj)
  12. {
  13. if (obj == null || obj is DirectoryString)
  14. return (DirectoryString) obj;
  15. if (obj is DerStringBase)
  16. {
  17. if (obj is DerT61String
  18. || obj is DerPrintableString
  19. || obj is DerUniversalString
  20. || obj is DerUtf8String
  21. || obj is DerBmpString)
  22. {
  23. return new DirectoryString((DerStringBase) obj);
  24. }
  25. }
  26. throw new ArgumentException("unknown object in factory: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
  27. }
  28. public static DirectoryString GetInstance(
  29. Asn1TaggedObject obj,
  30. bool isExplicit)
  31. {
  32. if (!isExplicit)
  33. throw new ArgumentException("choice item must be explicitly tagged");
  34. return GetInstance(obj.GetObject());
  35. }
  36. private DirectoryString(
  37. DerStringBase str)
  38. {
  39. this.str = str;
  40. }
  41. public DirectoryString(
  42. string str)
  43. {
  44. this.str = new DerUtf8String(str);
  45. }
  46. public string GetString()
  47. {
  48. return str.GetString();
  49. }
  50. /**
  51. * <pre>
  52. * DirectoryString ::= CHOICE {
  53. * teletexString TeletexString (SIZE (1..MAX)),
  54. * printableString PrintableString (SIZE (1..MAX)),
  55. * universalString UniversalString (SIZE (1..MAX)),
  56. * utf8String UTF8String (SIZE (1..MAX)),
  57. * bmpString BMPString (SIZE (1..MAX)) }
  58. * </pre>
  59. */
  60. public override Asn1Object ToAsn1Object()
  61. {
  62. return str.ToAsn1Object();
  63. }
  64. }
  65. }
  66. #pragma warning restore
  67. #endif