AlgorithmIdentifier.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. public class AlgorithmIdentifier
  7. : Asn1Encodable
  8. {
  9. private readonly DerObjectIdentifier algorithm;
  10. private readonly Asn1Encodable parameters;
  11. public static AlgorithmIdentifier GetInstance(
  12. Asn1TaggedObject obj,
  13. bool explicitly)
  14. {
  15. return GetInstance(Asn1Sequence.GetInstance(obj, explicitly));
  16. }
  17. public static AlgorithmIdentifier GetInstance(
  18. object obj)
  19. {
  20. if (obj == null)
  21. return null;
  22. if (obj is AlgorithmIdentifier)
  23. return (AlgorithmIdentifier)obj;
  24. return new AlgorithmIdentifier(Asn1Sequence.GetInstance(obj));
  25. }
  26. public AlgorithmIdentifier(
  27. DerObjectIdentifier algorithm)
  28. {
  29. this.algorithm = algorithm;
  30. }
  31. [Obsolete("Use version taking a DerObjectIdentifier")]
  32. public AlgorithmIdentifier(
  33. string algorithm)
  34. {
  35. this.algorithm = new DerObjectIdentifier(algorithm);
  36. }
  37. public AlgorithmIdentifier(
  38. DerObjectIdentifier algorithm,
  39. Asn1Encodable parameters)
  40. {
  41. this.algorithm = algorithm;
  42. this.parameters = parameters;
  43. }
  44. internal AlgorithmIdentifier(
  45. Asn1Sequence seq)
  46. {
  47. if (seq.Count < 1 || seq.Count > 2)
  48. throw new ArgumentException("Bad sequence size: " + seq.Count);
  49. this.algorithm = DerObjectIdentifier.GetInstance(seq[0]);
  50. this.parameters = seq.Count < 2 ? null : seq[1];
  51. }
  52. /// <summary>
  53. /// Return the OID in the Algorithm entry of this identifier.
  54. /// </summary>
  55. public virtual DerObjectIdentifier Algorithm
  56. {
  57. get { return algorithm; }
  58. }
  59. [Obsolete("Use 'Algorithm' property instead")]
  60. public virtual DerObjectIdentifier ObjectID
  61. {
  62. get { return algorithm; }
  63. }
  64. /// <summary>
  65. /// Return the parameters structure in the Parameters entry of this identifier.
  66. /// </summary>
  67. public virtual Asn1Encodable Parameters
  68. {
  69. get { return parameters; }
  70. }
  71. /**
  72. * Produce an object suitable for an Asn1OutputStream.
  73. * <pre>
  74. * AlgorithmIdentifier ::= Sequence {
  75. * algorithm OBJECT IDENTIFIER,
  76. * parameters ANY DEFINED BY algorithm OPTIONAL }
  77. * </pre>
  78. */
  79. public override Asn1Object ToAsn1Object()
  80. {
  81. Asn1EncodableVector v = new Asn1EncodableVector(algorithm);
  82. v.AddOptional(parameters);
  83. return new DerSequence(v);
  84. }
  85. }
  86. }
  87. #pragma warning restore
  88. #endif