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