EncryptedContentInfo.cs 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 EncryptedContentInfo
  9. : Asn1Encodable
  10. {
  11. private DerObjectIdentifier contentType;
  12. private AlgorithmIdentifier contentEncryptionAlgorithm;
  13. private Asn1OctetString encryptedContent;
  14. public EncryptedContentInfo(
  15. DerObjectIdentifier contentType,
  16. AlgorithmIdentifier contentEncryptionAlgorithm,
  17. Asn1OctetString encryptedContent)
  18. {
  19. this.contentType = contentType;
  20. this.contentEncryptionAlgorithm = contentEncryptionAlgorithm;
  21. this.encryptedContent = encryptedContent;
  22. }
  23. public EncryptedContentInfo(
  24. Asn1Sequence seq)
  25. {
  26. contentType = (DerObjectIdentifier) seq[0];
  27. contentEncryptionAlgorithm = AlgorithmIdentifier.GetInstance(seq[1]);
  28. if (seq.Count > 2)
  29. {
  30. encryptedContent = Asn1OctetString.GetInstance(
  31. (Asn1TaggedObject) seq[2], false);
  32. }
  33. }
  34. /**
  35. * return an EncryptedContentInfo object from the given object.
  36. *
  37. * @param obj the object we want converted.
  38. * @exception ArgumentException if the object cannot be converted.
  39. */
  40. public static EncryptedContentInfo GetInstance(
  41. object obj)
  42. {
  43. if (obj == null || obj is EncryptedContentInfo)
  44. return (EncryptedContentInfo)obj;
  45. if (obj is Asn1Sequence)
  46. return new EncryptedContentInfo((Asn1Sequence)obj);
  47. throw new ArgumentException("Invalid EncryptedContentInfo: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj));
  48. }
  49. public DerObjectIdentifier ContentType
  50. {
  51. get { return contentType; }
  52. }
  53. public AlgorithmIdentifier ContentEncryptionAlgorithm
  54. {
  55. get { return contentEncryptionAlgorithm; }
  56. }
  57. public Asn1OctetString EncryptedContent
  58. {
  59. get { return encryptedContent; }
  60. }
  61. /**
  62. * Produce an object suitable for an Asn1OutputStream.
  63. * <pre>
  64. * EncryptedContentInfo ::= Sequence {
  65. * contentType ContentType,
  66. * contentEncryptionAlgorithm ContentEncryptionAlgorithmIdentifier,
  67. * encryptedContent [0] IMPLICIT EncryptedContent OPTIONAL
  68. * }
  69. * </pre>
  70. */
  71. public override Asn1Object ToAsn1Object()
  72. {
  73. Asn1EncodableVector v = new Asn1EncodableVector(
  74. contentType, contentEncryptionAlgorithm);
  75. if (encryptedContent != null)
  76. {
  77. v.Add(new BerTaggedObject(false, 0, encryptedContent));
  78. }
  79. return new BerSequence(v);
  80. }
  81. }
  82. }
  83. #pragma warning restore
  84. #endif