DerVideotexString.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 int EncodedLength(bool withID)
  73. {
  74. return Asn1OutputStream.GetLengthOfEncodingDL(withID, mString.Length);
  75. }
  76. internal override void Encode(Asn1OutputStream asn1Out, bool withID)
  77. {
  78. asn1Out.WriteEncodingDL(withID, Asn1Tags.VideotexString, mString);
  79. }
  80. protected override int Asn1GetHashCode()
  81. {
  82. return Arrays.GetHashCode(mString);
  83. }
  84. protected override bool Asn1Equals(
  85. Asn1Object asn1Object)
  86. {
  87. DerVideotexString other = asn1Object as DerVideotexString;
  88. if (other == null)
  89. return false;
  90. return Arrays.AreEqual(mString, other.mString);
  91. }
  92. }
  93. }
  94. #pragma warning restore
  95. #endif