KEKIdentifier.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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.Cms
  6. {
  7. public class KekIdentifier
  8. : Asn1Encodable
  9. {
  10. private Asn1OctetString keyIdentifier;
  11. private DerGeneralizedTime date;
  12. private OtherKeyAttribute other;
  13. public KekIdentifier(
  14. byte[] keyIdentifier,
  15. DerGeneralizedTime date,
  16. OtherKeyAttribute other)
  17. {
  18. this.keyIdentifier = new DerOctetString(keyIdentifier);
  19. this.date = date;
  20. this.other = other;
  21. }
  22. public KekIdentifier(
  23. Asn1Sequence seq)
  24. {
  25. keyIdentifier = (Asn1OctetString) seq[0];
  26. switch (seq.Count)
  27. {
  28. case 1:
  29. break;
  30. case 2:
  31. if (seq[1] is DerGeneralizedTime)
  32. {
  33. date = (DerGeneralizedTime) seq[1];
  34. }
  35. else
  36. {
  37. other = OtherKeyAttribute.GetInstance(seq[2]);
  38. }
  39. break;
  40. case 3:
  41. date = (DerGeneralizedTime) seq[1];
  42. other = OtherKeyAttribute.GetInstance(seq[2]);
  43. break;
  44. default:
  45. throw new ArgumentException("Invalid KekIdentifier");
  46. }
  47. }
  48. /**
  49. * return a KekIdentifier object from a tagged object.
  50. *
  51. * @param obj the tagged object holding the object we want.
  52. * @param explicitly true if the object is meant to be explicitly
  53. * tagged false otherwise.
  54. * @exception ArgumentException if the object held by the
  55. * tagged object cannot be converted.
  56. */
  57. public static KekIdentifier GetInstance(
  58. Asn1TaggedObject obj,
  59. bool explicitly)
  60. {
  61. return GetInstance(Asn1Sequence.GetInstance(obj, explicitly));
  62. }
  63. /**
  64. * return a KekIdentifier object from the given object.
  65. *
  66. * @param obj the object we want converted.
  67. * @exception ArgumentException if the object cannot be converted.
  68. */
  69. public static KekIdentifier GetInstance(
  70. object obj)
  71. {
  72. if (obj == null || obj is KekIdentifier)
  73. return (KekIdentifier)obj;
  74. if (obj is Asn1Sequence)
  75. return new KekIdentifier((Asn1Sequence)obj);
  76. throw new ArgumentException("Invalid KekIdentifier: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj));
  77. }
  78. public Asn1OctetString KeyIdentifier
  79. {
  80. get { return keyIdentifier; }
  81. }
  82. public DerGeneralizedTime Date
  83. {
  84. get { return date; }
  85. }
  86. public OtherKeyAttribute Other
  87. {
  88. get { return other; }
  89. }
  90. /**
  91. * Produce an object suitable for an Asn1OutputStream.
  92. * <pre>
  93. * KekIdentifier ::= Sequence {
  94. * keyIdentifier OCTET STRING,
  95. * date GeneralizedTime OPTIONAL,
  96. * other OtherKeyAttribute OPTIONAL
  97. * }
  98. * </pre>
  99. */
  100. public override Asn1Object ToAsn1Object()
  101. {
  102. Asn1EncodableVector v = new Asn1EncodableVector(keyIdentifier);
  103. v.AddOptional(date, other);
  104. return new DerSequence(v);
  105. }
  106. }
  107. }
  108. #pragma warning restore
  109. #endif