DerGeneralString.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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
  7. {
  8. public class DerGeneralString
  9. : DerStringBase
  10. {
  11. private readonly string str;
  12. public static DerGeneralString GetInstance(
  13. object obj)
  14. {
  15. if (obj == null || obj is DerGeneralString)
  16. {
  17. return (DerGeneralString) obj;
  18. }
  19. throw new ArgumentException("illegal object in GetInstance: "
  20. + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj));
  21. }
  22. public static DerGeneralString GetInstance(
  23. Asn1TaggedObject obj,
  24. bool isExplicit)
  25. {
  26. Asn1Object o = obj.GetObject();
  27. if (isExplicit || o is DerGeneralString)
  28. {
  29. return GetInstance(o);
  30. }
  31. return new DerGeneralString(((Asn1OctetString)o).GetOctets());
  32. }
  33. public DerGeneralString(
  34. byte[] str)
  35. : this(Strings.FromAsciiByteArray(str))
  36. {
  37. }
  38. public DerGeneralString(
  39. string str)
  40. {
  41. if (str == null)
  42. throw new ArgumentNullException("str");
  43. this.str = str;
  44. }
  45. public override string GetString()
  46. {
  47. return str;
  48. }
  49. public byte[] GetOctets()
  50. {
  51. return Strings.ToAsciiByteArray(str);
  52. }
  53. internal override void Encode(
  54. DerOutputStream derOut)
  55. {
  56. derOut.WriteEncoded(Asn1Tags.GeneralString, GetOctets());
  57. }
  58. protected override bool Asn1Equals(
  59. Asn1Object asn1Object)
  60. {
  61. DerGeneralString other = asn1Object as DerGeneralString;
  62. if (other == null)
  63. return false;
  64. return this.str.Equals(other.str);
  65. }
  66. }
  67. }
  68. #pragma warning restore
  69. #endif