GOST3410PublicKeyAlgParameters.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. using System;
  3. using Org.BouncyCastle.Utilities;
  4. namespace Org.BouncyCastle.Asn1.CryptoPro
  5. {
  6. public class Gost3410PublicKeyAlgParameters
  7. : Asn1Encodable
  8. {
  9. private DerObjectIdentifier publicKeyParamSet;
  10. private DerObjectIdentifier digestParamSet;
  11. private DerObjectIdentifier encryptionParamSet;
  12. public static Gost3410PublicKeyAlgParameters GetInstance(
  13. Asn1TaggedObject obj,
  14. bool explicitly)
  15. {
  16. return GetInstance(Asn1Sequence.GetInstance(obj, explicitly));
  17. }
  18. public static Gost3410PublicKeyAlgParameters GetInstance(
  19. object obj)
  20. {
  21. if (obj == null || obj is Gost3410PublicKeyAlgParameters)
  22. {
  23. return (Gost3410PublicKeyAlgParameters) obj;
  24. }
  25. if (obj is Asn1Sequence)
  26. {
  27. return new Gost3410PublicKeyAlgParameters((Asn1Sequence) obj);
  28. }
  29. throw new ArgumentException("Invalid GOST3410Parameter: " + Org.BouncyCastle.Utilities.Platform.GetTypeName(obj));
  30. }
  31. public Gost3410PublicKeyAlgParameters(
  32. DerObjectIdentifier publicKeyParamSet,
  33. DerObjectIdentifier digestParamSet)
  34. : this (publicKeyParamSet, digestParamSet, null)
  35. {
  36. }
  37. public Gost3410PublicKeyAlgParameters(
  38. DerObjectIdentifier publicKeyParamSet,
  39. DerObjectIdentifier digestParamSet,
  40. DerObjectIdentifier encryptionParamSet)
  41. {
  42. if (publicKeyParamSet == null)
  43. throw new ArgumentNullException("publicKeyParamSet");
  44. if (digestParamSet == null)
  45. throw new ArgumentNullException("digestParamSet");
  46. this.publicKeyParamSet = publicKeyParamSet;
  47. this.digestParamSet = digestParamSet;
  48. this.encryptionParamSet = encryptionParamSet;
  49. }
  50. public Gost3410PublicKeyAlgParameters(
  51. Asn1Sequence seq)
  52. {
  53. this.publicKeyParamSet = (DerObjectIdentifier) seq[0];
  54. this.digestParamSet = (DerObjectIdentifier) seq[1];
  55. if (seq.Count > 2)
  56. {
  57. this.encryptionParamSet = (DerObjectIdentifier) seq[2];
  58. }
  59. }
  60. public DerObjectIdentifier PublicKeyParamSet
  61. {
  62. get { return publicKeyParamSet; }
  63. }
  64. public DerObjectIdentifier DigestParamSet
  65. {
  66. get { return digestParamSet; }
  67. }
  68. public DerObjectIdentifier EncryptionParamSet
  69. {
  70. get { return encryptionParamSet; }
  71. }
  72. public override Asn1Object ToAsn1Object()
  73. {
  74. Asn1EncodableVector v = new Asn1EncodableVector(
  75. publicKeyParamSet, digestParamSet);
  76. if (encryptionParamSet != null)
  77. {
  78. v.Add(encryptionParamSet);
  79. }
  80. return new DerSequence(v);
  81. }
  82. }
  83. }
  84. #endif