DerVideotexString.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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
  6. {
  7. public class DerVideotexString
  8. : DerStringBase
  9. {
  10. private readonly byte[] mString;
  11. /**
  12. * return a Videotex String from the passed in object
  13. *
  14. * @param obj a DERVideotexString or an object that can be converted into one.
  15. * @exception IllegalArgumentException if the object cannot be converted.
  16. * @return a DERVideotexString instance, or null.
  17. */
  18. public static DerVideotexString GetInstance(object obj)
  19. {
  20. if (obj == null || obj is DerVideotexString)
  21. {
  22. return (DerVideotexString)obj;
  23. }
  24. if (obj is byte[])
  25. {
  26. try
  27. {
  28. return (DerVideotexString)FromByteArray((byte[])obj);
  29. }
  30. catch (Exception e)
  31. {
  32. throw new ArgumentException("encoding error in GetInstance: " + e.ToString(), "obj");
  33. }
  34. }
  35. throw new ArgumentException("illegal object in GetInstance: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
  36. }
  37. /**
  38. * return a Videotex String from a tagged object.
  39. *
  40. * @param obj the tagged object holding the object we want
  41. * @param explicit true if the object is meant to be explicitly
  42. * tagged false otherwise.
  43. * @exception IllegalArgumentException if the tagged object cannot
  44. * be converted.
  45. * @return a DERVideotexString instance, or null.
  46. */
  47. public static DerVideotexString GetInstance(Asn1TaggedObject obj, bool isExplicit)
  48. {
  49. Asn1Object o = obj.GetObject();
  50. if (isExplicit || o is DerVideotexString)
  51. {
  52. return GetInstance(o);
  53. }
  54. return new DerVideotexString(((Asn1OctetString)o).GetOctets());
  55. }
  56. /**
  57. * basic constructor - with bytes.
  58. * @param string the byte encoding of the characters making up the string.
  59. */
  60. public DerVideotexString(byte[] encoding)
  61. {
  62. this.mString = Arrays.Clone(encoding);
  63. }
  64. public override string GetString()
  65. {
  66. return Strings.FromByteArray(mString);
  67. }
  68. public byte[] GetOctets()
  69. {
  70. return Arrays.Clone(mString);
  71. }
  72. internal override void Encode(DerOutputStream derOut)
  73. {
  74. derOut.WriteEncoded(Asn1Tags.VideotexString, mString);
  75. }
  76. protected override int Asn1GetHashCode()
  77. {
  78. return Arrays.GetHashCode(mString);
  79. }
  80. protected override bool Asn1Equals(
  81. Asn1Object asn1Object)
  82. {
  83. DerVideotexString other = asn1Object as DerVideotexString;
  84. if (other == null)
  85. return false;
  86. return Arrays.AreEqual(mString, other.mString);
  87. }
  88. }
  89. }
  90. #pragma warning restore
  91. #endif