X509ExtensionBase.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. using System;
  3. using Org.BouncyCastle.Asn1;
  4. using Org.BouncyCastle.Asn1.X509;
  5. using Org.BouncyCastle.Utilities.Collections;
  6. namespace Org.BouncyCastle.X509
  7. {
  8. public abstract class X509ExtensionBase
  9. : IX509Extension
  10. {
  11. protected abstract X509Extensions GetX509Extensions();
  12. protected virtual ISet GetExtensionOids(
  13. bool critical)
  14. {
  15. X509Extensions extensions = GetX509Extensions();
  16. if (extensions != null)
  17. {
  18. HashSet set = new HashSet();
  19. foreach (DerObjectIdentifier oid in extensions.ExtensionOids)
  20. {
  21. X509Extension ext = extensions.GetExtension(oid);
  22. if (ext.IsCritical == critical)
  23. {
  24. set.Add(oid.Id);
  25. }
  26. }
  27. return set;
  28. }
  29. return null;
  30. }
  31. /// <summary>
  32. /// Get non critical extensions.
  33. /// </summary>
  34. /// <returns>A set of non critical extension oids.</returns>
  35. public virtual ISet GetNonCriticalExtensionOids()
  36. {
  37. return GetExtensionOids(false);
  38. }
  39. /// <summary>
  40. /// Get any critical extensions.
  41. /// </summary>
  42. /// <returns>A sorted list of critical entension.</returns>
  43. public virtual ISet GetCriticalExtensionOids()
  44. {
  45. return GetExtensionOids(true);
  46. }
  47. /// <summary>
  48. /// Get the value of a given extension.
  49. /// </summary>
  50. /// <param name="oid">The object ID of the extension. </param>
  51. /// <returns>An Asn1OctetString object if that extension is found or null if not.</returns>
  52. [Obsolete("Use version taking a DerObjectIdentifier instead")]
  53. public Asn1OctetString GetExtensionValue(
  54. string oid)
  55. {
  56. return GetExtensionValue(new DerObjectIdentifier(oid));
  57. }
  58. public virtual Asn1OctetString GetExtensionValue(
  59. DerObjectIdentifier oid)
  60. {
  61. X509Extensions exts = GetX509Extensions();
  62. if (exts != null)
  63. {
  64. X509Extension ext = exts.GetExtension(oid);
  65. if (ext != null)
  66. {
  67. return ext.Value;
  68. }
  69. }
  70. return null;
  71. }
  72. }
  73. }
  74. #endif