SafeBag.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
  5. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Pkcs
  6. {
  7. public class SafeBag
  8. : Asn1Encodable
  9. {
  10. public static SafeBag GetInstance(object obj)
  11. {
  12. if (obj is SafeBag)
  13. return (SafeBag)obj;
  14. if (obj == null)
  15. return null;
  16. return new SafeBag(Asn1Sequence.GetInstance(obj));
  17. }
  18. private readonly DerObjectIdentifier bagID;
  19. private readonly Asn1Object bagValue;
  20. private readonly Asn1Set bagAttributes;
  21. public SafeBag(
  22. DerObjectIdentifier oid,
  23. Asn1Object obj)
  24. {
  25. this.bagID = oid;
  26. this.bagValue = obj;
  27. this.bagAttributes = null;
  28. }
  29. public SafeBag(
  30. DerObjectIdentifier oid,
  31. Asn1Object obj,
  32. Asn1Set bagAttributes)
  33. {
  34. this.bagID = oid;
  35. this.bagValue = obj;
  36. this.bagAttributes = bagAttributes;
  37. }
  38. private SafeBag(Asn1Sequence seq)
  39. {
  40. this.bagID = (DerObjectIdentifier)seq[0];
  41. this.bagValue = ((DerTaggedObject)seq[1]).GetObject();
  42. if (seq.Count == 3)
  43. {
  44. this.bagAttributes = (Asn1Set)seq[2];
  45. }
  46. }
  47. public DerObjectIdentifier BagID
  48. {
  49. get { return bagID; }
  50. }
  51. public Asn1Object BagValue
  52. {
  53. get { return bagValue; }
  54. }
  55. public Asn1Set BagAttributes
  56. {
  57. get { return bagAttributes; }
  58. }
  59. public override Asn1Object ToAsn1Object()
  60. {
  61. Asn1EncodableVector v = new Asn1EncodableVector(bagID, new DerTaggedObject(0, bagValue));
  62. v.AddOptional(bagAttributes);
  63. return new DerSequence(v);
  64. }
  65. }
  66. }
  67. #pragma warning restore
  68. #endif