PbmParameter.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
  5. namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cmp
  6. {
  7. /**
  8. * PBMParameter ::= SEQUENCE {
  9. * salt OCTET STRING,
  10. * -- note: implementations MAY wish to limit acceptable sizes
  11. * -- of this string to values appropriate for their environment
  12. * -- in order to reduce the risk of denial-of-service attacks
  13. * owf AlgorithmIdentifier,
  14. * -- AlgId for a One-Way Function (SHA-1 recommended)
  15. * iterationCount INTEGER,
  16. * -- number of times the OWF is applied
  17. * -- note: implementations MAY wish to limit acceptable sizes
  18. * -- of this integer to values appropriate for their environment
  19. * -- in order to reduce the risk of denial-of-service attacks
  20. * mac AlgorithmIdentifier
  21. * -- the MAC AlgId (e.g., DES-MAC, Triple-DES-MAC [PKCS11],
  22. * } -- or HMAC [RFC2104, RFC2202])
  23. */
  24. public class PbmParameter
  25. : Asn1Encodable
  26. {
  27. public static PbmParameter GetInstance(object obj)
  28. {
  29. if (obj is PbmParameter pbmParameter)
  30. return pbmParameter;
  31. if (obj != null)
  32. return new PbmParameter(Asn1Sequence.GetInstance(obj));
  33. return null;
  34. }
  35. private readonly Asn1OctetString m_salt;
  36. private readonly AlgorithmIdentifier m_owf;
  37. private readonly DerInteger m_iterationCount;
  38. private readonly AlgorithmIdentifier m_mac;
  39. private PbmParameter(Asn1Sequence seq)
  40. {
  41. m_salt = Asn1OctetString.GetInstance(seq[0]);
  42. m_owf = AlgorithmIdentifier.GetInstance(seq[1]);
  43. m_iterationCount = DerInteger.GetInstance(seq[2]);
  44. m_mac = AlgorithmIdentifier.GetInstance(seq[3]);
  45. }
  46. public PbmParameter(byte[] salt, AlgorithmIdentifier owf, int iterationCount, AlgorithmIdentifier mac)
  47. : this(new DerOctetString(salt), owf, new DerInteger(iterationCount), mac)
  48. {
  49. }
  50. public PbmParameter(Asn1OctetString salt, AlgorithmIdentifier owf, DerInteger iterationCount,
  51. AlgorithmIdentifier mac)
  52. {
  53. m_salt = salt;
  54. m_owf = owf;
  55. m_iterationCount = iterationCount;
  56. m_mac = mac;
  57. }
  58. public virtual DerInteger IterationCount => m_iterationCount;
  59. public virtual AlgorithmIdentifier Mac => m_mac;
  60. public virtual AlgorithmIdentifier Owf => m_owf;
  61. public virtual Asn1OctetString Salt => m_salt;
  62. /**
  63. * <pre>
  64. * PbmParameter ::= SEQUENCE {
  65. * salt OCTET STRING,
  66. * -- note: implementations MAY wish to limit acceptable sizes
  67. * -- of this string to values appropriate for their environment
  68. * -- in order to reduce the risk of denial-of-service attacks
  69. * owf AlgorithmIdentifier,
  70. * -- AlgId for a One-Way Function (SHA-1 recommended)
  71. * iterationCount INTEGER,
  72. * -- number of times the OWF is applied
  73. * -- note: implementations MAY wish to limit acceptable sizes
  74. * -- of this integer to values appropriate for their environment
  75. * -- in order to reduce the risk of denial-of-service attacks
  76. * mac AlgorithmIdentifier
  77. * -- the MAC AlgId (e.g., DES-MAC, Triple-DES-MAC [PKCS11],
  78. * } -- or HMAC [RFC2104, RFC2202])
  79. * </pre>
  80. * @return a basic ASN.1 object representation.
  81. */
  82. public override Asn1Object ToAsn1Object()
  83. {
  84. return new DerSequence(m_salt, m_owf, m_iterationCount, m_mac);
  85. }
  86. }
  87. }
  88. #pragma warning restore
  89. #endif