OriginatorIdentifierOrKey.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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 OriginatorIdentifierOrKey
  9. : Asn1Encodable, IAsn1Choice
  10. {
  11. private Asn1Encodable id;
  12. public OriginatorIdentifierOrKey(
  13. IssuerAndSerialNumber id)
  14. {
  15. this.id = id;
  16. }
  17. [Obsolete("Use version taking a 'SubjectKeyIdentifier'")]
  18. public OriginatorIdentifierOrKey(
  19. Asn1OctetString id)
  20. : this(new SubjectKeyIdentifier(id))
  21. {
  22. }
  23. public OriginatorIdentifierOrKey(
  24. SubjectKeyIdentifier id)
  25. {
  26. this.id = new DerTaggedObject(false, 0, id);
  27. }
  28. public OriginatorIdentifierOrKey(
  29. OriginatorPublicKey id)
  30. {
  31. this.id = new DerTaggedObject(false, 1, id);
  32. }
  33. [Obsolete("Use more specific version")]
  34. public OriginatorIdentifierOrKey(
  35. Asn1Object id)
  36. {
  37. this.id = id;
  38. }
  39. private OriginatorIdentifierOrKey(
  40. Asn1TaggedObject id)
  41. {
  42. // TODO Add validation
  43. this.id = id;
  44. }
  45. /**
  46. * return an OriginatorIdentifierOrKey object from a tagged object.
  47. *
  48. * @param o the tagged object holding the object we want.
  49. * @param explicitly true if the object is meant to be explicitly
  50. * tagged false otherwise.
  51. * @exception ArgumentException if the object held by the
  52. * tagged object cannot be converted.
  53. */
  54. public static OriginatorIdentifierOrKey GetInstance(
  55. Asn1TaggedObject o,
  56. bool explicitly)
  57. {
  58. if (!explicitly)
  59. {
  60. throw new ArgumentException(
  61. "Can't implicitly tag OriginatorIdentifierOrKey");
  62. }
  63. return GetInstance(o.GetObject());
  64. }
  65. /**
  66. * return an OriginatorIdentifierOrKey object from the given object.
  67. *
  68. * @param o the object we want converted.
  69. * @exception ArgumentException if the object cannot be converted.
  70. */
  71. public static OriginatorIdentifierOrKey GetInstance(
  72. object o)
  73. {
  74. if (o == null || o is OriginatorIdentifierOrKey)
  75. return (OriginatorIdentifierOrKey)o;
  76. if (o is IssuerAndSerialNumber)
  77. return new OriginatorIdentifierOrKey((IssuerAndSerialNumber)o);
  78. if (o is SubjectKeyIdentifier)
  79. return new OriginatorIdentifierOrKey((SubjectKeyIdentifier)o);
  80. if (o is OriginatorPublicKey)
  81. return new OriginatorIdentifierOrKey((OriginatorPublicKey)o);
  82. if (o is Asn1TaggedObject)
  83. return new OriginatorIdentifierOrKey((Asn1TaggedObject)o);
  84. throw new ArgumentException("Invalid OriginatorIdentifierOrKey: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(o));
  85. }
  86. public Asn1Encodable ID
  87. {
  88. get { return id; }
  89. }
  90. public IssuerAndSerialNumber IssuerAndSerialNumber
  91. {
  92. get
  93. {
  94. if (id is IssuerAndSerialNumber)
  95. {
  96. return (IssuerAndSerialNumber)id;
  97. }
  98. return null;
  99. }
  100. }
  101. public SubjectKeyIdentifier SubjectKeyIdentifier
  102. {
  103. get
  104. {
  105. if (id is Asn1TaggedObject && ((Asn1TaggedObject)id).TagNo == 0)
  106. {
  107. return SubjectKeyIdentifier.GetInstance((Asn1TaggedObject)id, false);
  108. }
  109. return null;
  110. }
  111. }
  112. [Obsolete("Use 'OriginatorPublicKey' property")]
  113. public OriginatorPublicKey OriginatorKey
  114. {
  115. get { return OriginatorPublicKey; }
  116. }
  117. public OriginatorPublicKey OriginatorPublicKey
  118. {
  119. get
  120. {
  121. if (id is Asn1TaggedObject && ((Asn1TaggedObject)id).TagNo == 1)
  122. {
  123. return OriginatorPublicKey.GetInstance((Asn1TaggedObject)id, false);
  124. }
  125. return null;
  126. }
  127. }
  128. /**
  129. * Produce an object suitable for an Asn1OutputStream.
  130. * <pre>
  131. * OriginatorIdentifierOrKey ::= CHOICE {
  132. * issuerAndSerialNumber IssuerAndSerialNumber,
  133. * subjectKeyIdentifier [0] SubjectKeyIdentifier,
  134. * originatorKey [1] OriginatorPublicKey
  135. * }
  136. *
  137. * SubjectKeyIdentifier ::= OCTET STRING
  138. * </pre>
  139. */
  140. public override Asn1Object ToAsn1Object()
  141. {
  142. return id.ToAsn1Object();
  143. }
  144. }
  145. }
  146. #pragma warning restore
  147. #endif