OriginatorPublicKey.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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.Cms
  7. {
  8. public class OriginatorPublicKey
  9. : Asn1Encodable
  10. {
  11. private readonly AlgorithmIdentifier mAlgorithm;
  12. private readonly DerBitString mPublicKey;
  13. public OriginatorPublicKey(
  14. AlgorithmIdentifier algorithm,
  15. byte[] publicKey)
  16. {
  17. this.mAlgorithm = algorithm;
  18. this.mPublicKey = new DerBitString(publicKey);
  19. }
  20. [Obsolete("Use 'GetInstance' instead")]
  21. public OriginatorPublicKey(
  22. Asn1Sequence seq)
  23. {
  24. this.mAlgorithm = AlgorithmIdentifier.GetInstance(seq[0]);
  25. this.mPublicKey = DerBitString.GetInstance(seq[1]);
  26. }
  27. /**
  28. * return an OriginatorPublicKey object from a tagged object.
  29. *
  30. * @param obj the tagged object holding the object we want.
  31. * @param explicitly true if the object is meant to be explicitly
  32. * tagged false otherwise.
  33. * @exception ArgumentException if the object held by the
  34. * tagged object cannot be converted.
  35. */
  36. public static OriginatorPublicKey GetInstance(
  37. Asn1TaggedObject obj,
  38. bool explicitly)
  39. {
  40. return GetInstance(Asn1Sequence.GetInstance(obj, explicitly));
  41. }
  42. /**
  43. * return an OriginatorPublicKey object from the given object.
  44. *
  45. * @param obj the object we want converted.
  46. * @exception ArgumentException if the object cannot be converted.
  47. */
  48. public static OriginatorPublicKey GetInstance(
  49. object obj)
  50. {
  51. if (obj == null || obj is OriginatorPublicKey)
  52. return (OriginatorPublicKey)obj;
  53. if (obj is Asn1Sequence)
  54. return new OriginatorPublicKey(Asn1Sequence.GetInstance(obj));
  55. throw new ArgumentException("Invalid OriginatorPublicKey: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj));
  56. }
  57. public AlgorithmIdentifier Algorithm
  58. {
  59. get { return mAlgorithm; }
  60. }
  61. public DerBitString PublicKey
  62. {
  63. get { return mPublicKey; }
  64. }
  65. /**
  66. * Produce an object suitable for an Asn1OutputStream.
  67. * <pre>
  68. * OriginatorPublicKey ::= Sequence {
  69. * algorithm AlgorithmIdentifier,
  70. * publicKey BIT STRING
  71. * }
  72. * </pre>
  73. */
  74. public override Asn1Object ToAsn1Object()
  75. {
  76. return new DerSequence(mAlgorithm, mPublicKey);
  77. }
  78. }
  79. }
  80. #pragma warning restore
  81. #endif