SMIMECapabilities.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using System.Collections.Generic;
  5. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.Nist;
  6. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.Pkcs;
  7. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
  8. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  9. namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.Smime
  10. {
  11. /**
  12. * Handler class for dealing with S/MIME Capabilities
  13. */
  14. public class SmimeCapabilities
  15. : Asn1Encodable
  16. {
  17. /**
  18. * general preferences
  19. */
  20. public static readonly DerObjectIdentifier PreferSignedData = PkcsObjectIdentifiers.PreferSignedData;
  21. public static readonly DerObjectIdentifier CannotDecryptAny = PkcsObjectIdentifiers.CannotDecryptAny;
  22. public static readonly DerObjectIdentifier SmimeCapabilitesVersions = PkcsObjectIdentifiers.SmimeCapabilitiesVersions;
  23. /**
  24. * encryption algorithms preferences
  25. */
  26. public static readonly DerObjectIdentifier Aes256Cbc = NistObjectIdentifiers.IdAes256Cbc;
  27. public static readonly DerObjectIdentifier Aes192Cbc = NistObjectIdentifiers.IdAes192Cbc;
  28. public static readonly DerObjectIdentifier Aes128Cbc = NistObjectIdentifiers.IdAes128Cbc;
  29. public static readonly DerObjectIdentifier IdeaCbc = new DerObjectIdentifier("1.3.6.1.4.1.188.7.1.1.2");
  30. public static readonly DerObjectIdentifier Cast5Cbc = new DerObjectIdentifier("1.2.840.113533.7.66.10");
  31. public static readonly DerObjectIdentifier DesCbc = new DerObjectIdentifier("1.3.14.3.2.7");
  32. public static readonly DerObjectIdentifier DesEde3Cbc = PkcsObjectIdentifiers.DesEde3Cbc;
  33. public static readonly DerObjectIdentifier RC2Cbc = PkcsObjectIdentifiers.RC2Cbc;
  34. private Asn1Sequence capabilities;
  35. /**
  36. * return an Attr object from the given object.
  37. *
  38. * @param o the object we want converted.
  39. * @exception ArgumentException if the object cannot be converted.
  40. */
  41. public static SmimeCapabilities GetInstance(
  42. object obj)
  43. {
  44. if (obj == null || obj is SmimeCapabilities)
  45. {
  46. return (SmimeCapabilities) obj;
  47. }
  48. if (obj is Asn1Sequence)
  49. {
  50. return new SmimeCapabilities((Asn1Sequence) obj);
  51. }
  52. if (obj is AttributeX509)
  53. {
  54. return new SmimeCapabilities(
  55. (Asn1Sequence)(((AttributeX509) obj).AttrValues[0]));
  56. }
  57. throw new ArgumentException("unknown object in factory: " + Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
  58. }
  59. public SmimeCapabilities(
  60. Asn1Sequence seq)
  61. {
  62. capabilities = seq;
  63. }
  64. /**
  65. * returns an ArrayList with 0 or more objects of all the capabilities
  66. * matching the passed in capability Oid. If the Oid passed is null the
  67. * entire set is returned.
  68. */
  69. public IList<SmimeCapability> GetCapabilitiesForOid(DerObjectIdentifier capability)
  70. {
  71. var list = new List<SmimeCapability>();
  72. DoGetCapabilitiesForOid(capability, list);
  73. return list;
  74. }
  75. private void DoGetCapabilitiesForOid(DerObjectIdentifier capability, IList<SmimeCapability> list)
  76. {
  77. foreach (object o in capabilities)
  78. {
  79. SmimeCapability cap = SmimeCapability.GetInstance(o);
  80. if (capability == null || capability.Equals(cap.CapabilityID))
  81. {
  82. list.Add(cap);
  83. }
  84. }
  85. }
  86. /**
  87. * Produce an object suitable for an Asn1OutputStream.
  88. * <pre>
  89. * SMIMECapabilities ::= Sequence OF SMIMECapability
  90. * </pre>
  91. */
  92. public override Asn1Object ToAsn1Object()
  93. {
  94. return capabilities;
  95. }
  96. }
  97. }
  98. #pragma warning restore
  99. #endif