PopoSigningKeyInput.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
  5. using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  6. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Crmf
  7. {
  8. public class PopoSigningKeyInput
  9. : Asn1Encodable
  10. {
  11. private readonly GeneralName sender;
  12. private readonly PKMacValue publicKeyMac;
  13. private readonly SubjectPublicKeyInfo publicKey;
  14. private PopoSigningKeyInput(Asn1Sequence seq)
  15. {
  16. Asn1Encodable authInfo = (Asn1Encodable)seq[0];
  17. if (authInfo is Asn1TaggedObject)
  18. {
  19. Asn1TaggedObject tagObj = (Asn1TaggedObject)authInfo;
  20. if (tagObj.TagNo != 0)
  21. {
  22. throw new ArgumentException("Unknown authInfo tag: " + tagObj.TagNo, "seq");
  23. }
  24. sender = GeneralName.GetInstance(tagObj.GetObject());
  25. }
  26. else
  27. {
  28. publicKeyMac = PKMacValue.GetInstance(authInfo);
  29. }
  30. publicKey = SubjectPublicKeyInfo.GetInstance(seq[1]);
  31. }
  32. public static PopoSigningKeyInput GetInstance(object obj)
  33. {
  34. if (obj is PopoSigningKeyInput)
  35. return (PopoSigningKeyInput)obj;
  36. if (obj is Asn1Sequence)
  37. return new PopoSigningKeyInput((Asn1Sequence)obj);
  38. throw new ArgumentException("Invalid object: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
  39. }
  40. /** Creates a new PopoSigningKeyInput with sender name as authInfo. */
  41. public PopoSigningKeyInput(
  42. GeneralName sender,
  43. SubjectPublicKeyInfo spki)
  44. {
  45. this.sender = sender;
  46. this.publicKey = spki;
  47. }
  48. /** Creates a new PopoSigningKeyInput using password-based MAC. */
  49. public PopoSigningKeyInput(
  50. PKMacValue pkmac,
  51. SubjectPublicKeyInfo spki)
  52. {
  53. this.publicKeyMac = pkmac;
  54. this.publicKey = spki;
  55. }
  56. /** Returns the sender field, or null if authInfo is publicKeyMac */
  57. public virtual GeneralName Sender
  58. {
  59. get { return sender; }
  60. }
  61. /** Returns the publicKeyMac field, or null if authInfo is sender */
  62. public virtual PKMacValue PublicKeyMac
  63. {
  64. get { return publicKeyMac; }
  65. }
  66. public virtual SubjectPublicKeyInfo PublicKey
  67. {
  68. get { return publicKey; }
  69. }
  70. /**
  71. * <pre>
  72. * PopoSigningKeyInput ::= SEQUENCE {
  73. * authInfo CHOICE {
  74. * sender [0] GeneralName,
  75. * -- used only if an authenticated identity has been
  76. * -- established for the sender (e.g., a DN from a
  77. * -- previously-issued and currently-valid certificate
  78. * publicKeyMac PKMacValue },
  79. * -- used if no authenticated GeneralName currently exists for
  80. * -- the sender; publicKeyMac contains a password-based MAC
  81. * -- on the DER-encoded value of publicKey
  82. * publicKey SubjectPublicKeyInfo } -- from CertTemplate
  83. * </pre>
  84. * @return a basic ASN.1 object representation.
  85. */
  86. public override Asn1Object ToAsn1Object()
  87. {
  88. Asn1EncodableVector v = new Asn1EncodableVector();
  89. if (sender != null)
  90. {
  91. v.Add(new DerTaggedObject(false, 0, sender));
  92. }
  93. else
  94. {
  95. v.Add(publicKeyMac);
  96. }
  97. v.Add(publicKey);
  98. return new DerSequence(v);
  99. }
  100. }
  101. }
  102. #pragma warning restore
  103. #endif