PKMacValue.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cmp;
  5. using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
  6. using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  7. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Crmf
  8. {
  9. /**
  10. * Password-based MAC value for use with POPOSigningKeyInput.
  11. */
  12. public class PKMacValue
  13. : Asn1Encodable
  14. {
  15. private readonly AlgorithmIdentifier algID;
  16. private readonly DerBitString macValue;
  17. private PKMacValue(Asn1Sequence seq)
  18. {
  19. this.algID = AlgorithmIdentifier.GetInstance(seq[0]);
  20. this.macValue = DerBitString.GetInstance(seq[1]);
  21. }
  22. public static PKMacValue GetInstance(object obj)
  23. {
  24. if (obj is PKMacValue)
  25. return (PKMacValue)obj;
  26. if (obj is Asn1Sequence)
  27. return new PKMacValue((Asn1Sequence)obj);
  28. throw new ArgumentException("Invalid object: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
  29. }
  30. public static PKMacValue GetInstance(Asn1TaggedObject obj, bool isExplicit)
  31. {
  32. return GetInstance(Asn1Sequence.GetInstance(obj, isExplicit));
  33. }
  34. /**
  35. * Creates a new PKMACValue.
  36. * @param params parameters for password-based MAC
  37. * @param value MAC of the DER-encoded SubjectPublicKeyInfo
  38. */
  39. public PKMacValue(
  40. PbmParameter pbmParams,
  41. DerBitString macValue)
  42. : this(new AlgorithmIdentifier(CmpObjectIdentifiers.passwordBasedMac, pbmParams), macValue)
  43. {
  44. }
  45. /**
  46. * Creates a new PKMACValue.
  47. * @param aid CMPObjectIdentifiers.passwordBasedMAC, with PBMParameter
  48. * @param value MAC of the DER-encoded SubjectPublicKeyInfo
  49. */
  50. public PKMacValue(
  51. AlgorithmIdentifier algID,
  52. DerBitString macValue)
  53. {
  54. this.algID = algID;
  55. this.macValue = macValue;
  56. }
  57. public virtual AlgorithmIdentifier AlgID
  58. {
  59. get { return algID; }
  60. }
  61. public virtual DerBitString MacValue
  62. {
  63. get { return macValue; }
  64. }
  65. /**
  66. * <pre>
  67. * PKMACValue ::= SEQUENCE {
  68. * algId AlgorithmIdentifier,
  69. * -- algorithm value shall be PasswordBasedMac 1.2.840.113533.7.66.13
  70. * -- parameter value is PBMParameter
  71. * value BIT STRING }
  72. * </pre>
  73. * @return a basic ASN.1 object representation.
  74. */
  75. public override Asn1Object ToAsn1Object()
  76. {
  77. return new DerSequence(algID, macValue);
  78. }
  79. }
  80. }
  81. #pragma warning restore
  82. #endif