PKIArchiveOptions.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  5. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Crmf
  6. {
  7. public class PkiArchiveOptions
  8. : Asn1Encodable, IAsn1Choice
  9. {
  10. public const int encryptedPrivKey = 0;
  11. public const int keyGenParameters = 1;
  12. public const int archiveRemGenPrivKey = 2;
  13. private readonly Asn1Encodable value;
  14. public static PkiArchiveOptions GetInstance(object obj)
  15. {
  16. if (obj is PkiArchiveOptions)
  17. return (PkiArchiveOptions)obj;
  18. if (obj is Asn1TaggedObject)
  19. return new PkiArchiveOptions((Asn1TaggedObject)obj);
  20. throw new ArgumentException("Invalid object: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
  21. }
  22. private PkiArchiveOptions(Asn1TaggedObject tagged)
  23. {
  24. switch (tagged.TagNo)
  25. {
  26. case encryptedPrivKey:
  27. value = EncryptedKey.GetInstance(tagged.GetObject());
  28. break;
  29. case keyGenParameters:
  30. value = Asn1OctetString.GetInstance(tagged, false);
  31. break;
  32. case archiveRemGenPrivKey:
  33. value = DerBoolean.GetInstance(tagged, false);
  34. break;
  35. default:
  36. throw new ArgumentException("unknown tag number: " + tagged.TagNo, "tagged");
  37. }
  38. }
  39. public PkiArchiveOptions(EncryptedKey encKey)
  40. {
  41. this.value = encKey;
  42. }
  43. public PkiArchiveOptions(Asn1OctetString keyGenParameters)
  44. {
  45. this.value = keyGenParameters;
  46. }
  47. public PkiArchiveOptions(bool archiveRemGenPrivKey)
  48. {
  49. this.value = DerBoolean.GetInstance(archiveRemGenPrivKey);
  50. }
  51. public virtual int Type
  52. {
  53. get
  54. {
  55. if (value is EncryptedKey)
  56. return encryptedPrivKey;
  57. if (value is Asn1OctetString)
  58. return keyGenParameters;
  59. return archiveRemGenPrivKey;
  60. }
  61. }
  62. public virtual Asn1Encodable Value
  63. {
  64. get { return value; }
  65. }
  66. /**
  67. * <pre>
  68. * PkiArchiveOptions ::= CHOICE {
  69. * encryptedPrivKey [0] EncryptedKey,
  70. * -- the actual value of the private key
  71. * keyGenParameters [1] KeyGenParameters,
  72. * -- parameters which allow the private key to be re-generated
  73. * archiveRemGenPrivKey [2] BOOLEAN }
  74. * -- set to TRUE if sender wishes receiver to archive the private
  75. * -- key of a key pair that the receiver generates in response to
  76. * -- this request; set to FALSE if no archival is desired.
  77. * </pre>
  78. */
  79. public override Asn1Object ToAsn1Object()
  80. {
  81. if (value is EncryptedKey)
  82. {
  83. return new DerTaggedObject(true, encryptedPrivKey, value); // choice
  84. }
  85. if (value is Asn1OctetString)
  86. {
  87. return new DerTaggedObject(false, keyGenParameters, value);
  88. }
  89. return new DerTaggedObject(false, archiveRemGenPrivKey, value);
  90. }
  91. }
  92. }
  93. #pragma warning restore
  94. #endif