AlgorithmIdentifier.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. namespace Best.HTTP.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. public AlgorithmIdentifier(
  32. DerObjectIdentifier algorithm,
  33. Asn1Encodable parameters)
  34. {
  35. this.algorithm = algorithm;
  36. this.parameters = parameters;
  37. }
  38. internal AlgorithmIdentifier(
  39. Asn1Sequence seq)
  40. {
  41. if (seq.Count < 1 || seq.Count > 2)
  42. throw new ArgumentException("Bad sequence size: " + seq.Count);
  43. this.algorithm = DerObjectIdentifier.GetInstance(seq[0]);
  44. this.parameters = seq.Count < 2 ? null : seq[1];
  45. }
  46. /// <summary>
  47. /// Return the OID in the Algorithm entry of this identifier.
  48. /// </summary>
  49. public virtual DerObjectIdentifier Algorithm
  50. {
  51. get { return algorithm; }
  52. }
  53. /// <summary>
  54. /// Return the parameters structure in the Parameters entry of this identifier.
  55. /// </summary>
  56. public virtual Asn1Encodable Parameters
  57. {
  58. get { return parameters; }
  59. }
  60. /**
  61. * Produce an object suitable for an Asn1OutputStream.
  62. * <pre>
  63. * AlgorithmIdentifier ::= Sequence {
  64. * algorithm OBJECT IDENTIFIER,
  65. * parameters ANY DEFINED BY algorithm OPTIONAL }
  66. * </pre>
  67. */
  68. public override Asn1Object ToAsn1Object()
  69. {
  70. Asn1EncodableVector v = new Asn1EncodableVector(algorithm);
  71. v.AddOptional(parameters);
  72. return new DerSequence(v);
  73. }
  74. }
  75. }
  76. #pragma warning restore
  77. #endif