X509Extension.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509
  5. {
  6. /**
  7. * an object for the elements in the X.509 V3 extension block.
  8. */
  9. public class X509Extension
  10. {
  11. internal bool critical;
  12. internal Asn1OctetString value;
  13. public X509Extension(
  14. DerBoolean critical,
  15. Asn1OctetString value)
  16. {
  17. if (critical == null)
  18. {
  19. throw new ArgumentNullException("critical");
  20. }
  21. this.critical = critical.IsTrue;
  22. this.value = value;
  23. }
  24. public X509Extension(
  25. bool critical,
  26. Asn1OctetString value)
  27. {
  28. this.critical = critical;
  29. this.value = value;
  30. }
  31. public bool IsCritical { get { return critical; } }
  32. public Asn1OctetString Value { get { return value; } }
  33. public Asn1Encodable GetParsedValue()
  34. {
  35. return ConvertValueToObject(this);
  36. }
  37. public override int GetHashCode()
  38. {
  39. int vh = this.Value.GetHashCode();
  40. return IsCritical ? vh : ~vh;
  41. }
  42. public override bool Equals(
  43. object obj)
  44. {
  45. X509Extension other = obj as X509Extension;
  46. if (other == null)
  47. {
  48. return false;
  49. }
  50. return Value.Equals(other.Value) && IsCritical == other.IsCritical;
  51. }
  52. /// <sumary>Convert the value of the passed in extension to an object.</sumary>
  53. /// <param name="ext">The extension to parse.</param>
  54. /// <returns>The object the value string contains.</returns>
  55. /// <exception cref="ArgumentException">If conversion is not possible.</exception>
  56. public static Asn1Object ConvertValueToObject(
  57. X509Extension ext)
  58. {
  59. try
  60. {
  61. return Asn1Object.FromByteArray(ext.Value.GetOctets());
  62. }
  63. catch (Exception e)
  64. {
  65. throw new ArgumentException("can't convert extension", e);
  66. }
  67. }
  68. }
  69. }
  70. #pragma warning restore
  71. #endif