Pfx.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
  6. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Pkcs
  7. {
  8. /**
  9. * the infamous Pfx from Pkcs12
  10. */
  11. public class Pfx
  12. : Asn1Encodable
  13. {
  14. private ContentInfo contentInfo;
  15. private MacData macData;
  16. public Pfx(
  17. Asn1Sequence seq)
  18. {
  19. BigInteger version = ((DerInteger) seq[0]).Value;
  20. if (version.IntValue != 3)
  21. {
  22. throw new ArgumentException("wrong version for PFX PDU");
  23. }
  24. contentInfo = ContentInfo.GetInstance(seq[1]);
  25. if (seq.Count == 3)
  26. {
  27. macData = MacData.GetInstance(seq[2]);
  28. }
  29. }
  30. public Pfx(
  31. ContentInfo contentInfo,
  32. MacData macData)
  33. {
  34. this.contentInfo = contentInfo;
  35. this.macData = macData;
  36. }
  37. public ContentInfo AuthSafe
  38. {
  39. get { return contentInfo; }
  40. }
  41. public MacData MacData
  42. {
  43. get { return macData; }
  44. }
  45. public override Asn1Object ToAsn1Object()
  46. {
  47. Asn1EncodableVector v = new Asn1EncodableVector(
  48. new DerInteger(3), contentInfo);
  49. if (macData != null)
  50. {
  51. v.Add(macData);
  52. }
  53. return new BerSequence(v);
  54. }
  55. }
  56. }
  57. #pragma warning restore
  58. #endif