OriginatorPublicKey.cs 2.7 KB

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